* device/lib/pic16/Makefile.common.in: added $(MM) to fix `make clean`
[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
6 \usepackage[
7   pdftitle={SDCC Compiler User Guide},
8   pdfauthor={SDCC development team},
9   pdfsubject={installation, user manual},
10   pdfkeywords={8032, 8051, ansi, c, compiler, CPU, DS390, 
11                embedded, GPL, HC08, manual, mcs51, PIC, Z80},
12   colorlinks=true,
13   linkcolor=blue] {hyperref}
14 %
15 \sloppy
16 \tolerance=500          
17 \emergencystretch=30pt 
18 %
19 \date{}
20 \end_preamble
21 \language english
22 \inputencoding default
23 \fontscheme pslatex
24 \graphics default
25 \paperfontsize default
26 \spacing single 
27 \papersize letterpaper
28 \paperpackage a4
29 \use_geometry 1
30 \use_amsmath 0
31 \use_natbib 0
32 \use_numerical_citations 0
33 \paperorientation portrait
34 \leftmargin 30mm
35 \topmargin 20mm
36 \rightmargin 25mm
37 \bottommargin 20mm
38 \secnumdepth 3
39 \tocdepth 3
40 \paragraph_separation indent
41 \defskip medskip
42 \quotes_language swedish
43 \quotes_times 2
44 \papercolumns 1
45 \papersides 1
46 \paperpagestyle fancy
47
48 \layout Comment
49
50 Please note: double dashed longoptions (e.g.
51  --version) are written this way: -
52 \begin_inset ERT
53 status Collapsed
54
55 \layout Standard
56
57 \backslash 
58 /
59 \end_inset 
60
61 -
62 \layout Comment
63
64 Two resp.
65  three consecutive dashes simply result in a long resp.
66  extra long dash.
67 \layout Comment
68
69 Architecture specific stuff (like memory models, code examples) should maybe
70  later go
71 \layout Comment
72
73 into seperate sections/chapters/appendices (it is hard to document PIC or
74  Z80 in 
75 \layout Comment
76
77 a 8051 centered document) - for now simply add.
78 \layout Title
79
80 SDCC Compiler User Guide
81 \layout Date
82
83
84 \size normal 
85 SDCC 2.4.3
86 \size footnotesize 
87
88 \newline 
89 $Date$ 
90 \newline 
91 $Revision$
92 \layout Comment
93
94 The above strings enclosed in $ are automatically updated by cvs
95 \layout Standard
96
97
98 \begin_inset LatexCommand \tableofcontents{}
99
100 \end_inset 
101
102
103 \layout Chapter
104
105 Introduction
106 \layout Section
107
108 About SDCC
109 \layout Standard
110
111
112 \series bold 
113 SDCC
114 \series default 
115  (
116 \emph on 
117 S
118 \emph default 
119 mall 
120 \emph on 
121 D
122 \emph default 
123 evice 
124 \emph on 
125 C
126 \emph default 
127  
128 \emph on 
129 C
130 \emph default 
131 ompiler) is a Freeware, retargettable, optimizing ANSI-C compiler by 
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, Motorola HC08 and Zilog Z80 based MCUs.
143  It can be retargetted for other microprocessors, support for Microchip
144  PIC, Atmel AVR is under development.
145  The entire source code for the compiler is distributed under GPL.
146  SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
147  SDCC has extensive language extensions suitable for utilizing various microcont
148 rollers and underlying hardware effectively.
149  
150 \newline 
151
152 \newline 
153 In addition to the MCU specific optimizations SDCC also does a host of standard
154  optimizations like:
155 \layout Itemize
156
157 global sub expression elimination, 
158 \layout Itemize
159
160 loop optimizations (loop invariant, strength reduction of induction variables
161  and loop reversing), 
162 \layout Itemize
163
164 constant folding & propagation, 
165 \layout Itemize
166
167 copy propagation, 
168 \layout Itemize
169
170 dead code elimination 
171 \layout Itemize
172
173 jump tables for 
174 \emph on 
175 switch
176 \emph default 
177  statements.
178 \layout Standard
179
180 For the back-end SDCC uses a global register allocation scheme which should
181  be well suited for other 8 bit MCUs.
182  
183 \newline 
184
185 \newline 
186 The peep hole optimizer uses a rule based substitution mechanism which is
187  MCU independent.
188  
189 \newline 
190
191 \newline 
192 Supported data-types are:
193 \layout Itemize
194
195 char (8 bits, 1 byte), 
196 \layout Itemize
197
198 short and int (16 bits, 2 bytes), 
199 \layout Itemize
200
201 long (32 bit, 4 bytes)
202 \layout Itemize
203
204 float (4 byte IEEE).
205  
206 \layout Standard
207
208 The compiler also allows 
209 \emph on 
210 inline assembler code
211 \emph default 
212  to be embedded anywhere in a function.
213  In addition, routines developed in assembly can also be called.
214 \newline 
215
216 \newline 
217 SDCC also provides an option (-
218 \begin_inset ERT
219 status Collapsed
220
221 \layout Standard
222
223 \backslash 
224 /
225 \end_inset 
226
227 -cyclomatic) to report the relative complexity of a function.
228  These functions can then be further optimized, or hand coded in assembly
229  if needed.
230  
231 \newline 
232
233 \newline 
234 SDCC also comes with a companion source level debugger SDCDB, the debugger
235  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
236  
237 \newline 
238
239 \newline 
240 The latest version can be downloaded from 
241 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
242
243 \end_inset 
244
245 .
246
247 \series bold 
248  
249 \series default 
250 \emph on 
251 Please note: the compiler will probably always be some steps ahead of this
252  documentation
253 \series bold 
254 \emph default 
255
256 \begin_inset LatexCommand \index{Status of documentation}
257
258 \end_inset 
259
260
261 \begin_inset Foot
262 collapsed false
263
264 \layout Standard
265
266 Obviously this has pros and cons
267 \end_inset 
268
269 .
270 \layout Section
271
272 Open Source
273 \layout Standard
274
275 All packages used in this compiler system are 
276 \emph on 
277 opensource
278 \emph default 
279  and 
280 \emph on 
281 freeware
282 \emph default 
283 ; source code for all the sub-packages (pre-processor, assemblers, linkers
284  etc) is distributed with the package.
285  This documentation is maintained using a freeware word processor (LyX).
286 \newline 
287 This program is free software; you can redistribute it and/or modify it
288  under the terms of the GNU General Public License
289 \begin_inset LatexCommand \index{GNU General Public License, GPL}
290
291 \end_inset 
292
293  as published by the Free Software Foundation; either version 2, or (at
294  your option) any later version.
295  This program is distributed in the hope that it will be useful, but WITHOUT
296  ANY WARRANTY; without even the implied warranty
297 \begin_inset LatexCommand \index{warranty}
298
299 \end_inset 
300
301  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
302  See the GNU General Public License for more details.
303  You should have received a copy of the GNU General Public License along
304  with this program; if not, write to the Free Software Foundation, 59 Temple
305  Place - Suite 330, Boston, MA 02111-1307, USA.
306  In other words, you are welcome to use, share and improve this program.
307  You are forbidden to forbid anyone else to use, share and improve what
308  you give them.
309  Help stamp out software-hoarding! 
310 \layout Section
311
312 Typographic conventions
313 \begin_inset LatexCommand \index{Typographic conventions}
314
315 \end_inset 
316
317
318 \layout Standard
319
320 Throughout this manual, we will use the following convention.
321  Commands you have to type in are printed in 
322 \family sans 
323 \series bold 
324 "sans serif"
325 \series default 
326 .
327
328 \family default 
329  Code samples are printed in 
330 \family typewriter 
331 typewriter font.
332
333 \family default 
334  Interesting items and new terms are printed in 
335 \emph on 
336 italic.
337 \layout Section
338
339 Compatibility with previous versions
340 \layout Standard
341
342 This version has numerous bug fixes compared with the previous version.
343  But we also introduced some incompatibilities with older versions.
344  Not just for the fun of it, but to make the compiler more stable, efficient
345  and ANSI compliant
346 \begin_inset LatexCommand \index{ANSI-compliance}
347
348 \end_inset 
349
350  (see section 
351 \begin_inset LatexCommand \ref{sub:ANSI-Compliance}
352
353 \end_inset 
354
355  for ANSI-Compliance).
356  
357 \newline 
358
359 \layout Itemize
360
361 short is now equivalent to int (16 bits), it used to be equivalent to char
362  (8 bits) which is not ANSI compliant
363 \layout Itemize
364
365 the default directory for gcc-builds where include, library and documentation
366  files are stored is now in /usr/local/share
367 \layout Itemize
368
369 char type parameters to vararg functions are casted to int unless explicitly
370  casted, e.g.: 
371 \newline 
372
373 \family typewriter 
374 \SpecialChar ~
375 \SpecialChar ~
376 char a=3;
377 \newline 
378 \SpecialChar ~
379 \SpecialChar ~
380 printf ("%d %c
381 \backslash 
382 n", a, (char)a);
383 \family default 
384
385 \newline 
386  will push a as an int and as a char resp.
387 \layout Itemize
388
389 option -
390 \begin_inset ERT
391 status Collapsed
392
393 \layout Standard
394
395 \backslash 
396 /
397 \end_inset 
398
399 -regextend has been removed
400 \layout Itemize
401
402 option -
403 \begin_inset ERT
404 status Collapsed
405
406 \layout Standard
407
408 \backslash 
409 /
410 \end_inset 
411
412 -noregparms has been removed
413 \layout Itemize
414
415 option -
416 \begin_inset ERT
417 status Collapsed
418
419 \layout Standard
420
421 \backslash 
422 /
423 \end_inset 
424
425 -stack-after-data has been removed
426 \layout Standard
427
428
429 \emph on 
430 <pending: more incompatibilities?>
431 \layout Section
432
433 System Requirements
434 \layout Standard
435
436 What do you need before you start installation of SDCC? A computer, and
437  a desire to compute.
438  The preferred method of installation is to compile SDCC from source using
439  GNU gcc and make.
440  For Windows some pre-compiled binary distributions are available for your
441  convenience.
442  You should have some experience with command line tools and compiler use.
443 \layout Section
444
445 Other Resources
446 \layout Standard
447
448 The SDCC home page at 
449 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/}
450
451 \end_inset 
452
453  is a great place to find distribution sets.
454  You can also find links to the user mailing lists that offer help or discuss
455  SDCC with other SDCC users.
456  Web links to other SDCC related sites can also be found here.
457  This document can be found in the DOC directory of the source package as
458  a text or HTML file.
459  A pdf version of this document is available at 
460 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
461
462 \end_inset 
463
464 .
465  Some of the other tools (simulator and assembler) included with SDCC contain
466  their own documentation and can be found in the source distribution.
467  If you want the latest unreleased software, the complete source package
468  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
469 \layout Section
470
471 Wishes for the future
472 \layout Standard
473
474 There are (and always will be) some things that could be done.
475  Here are some I can think of:
476 \newline 
477
478 \layout Standard
479
480
481 \family typewriter 
482 char KernelFunction3(char p) at 0x340;
483 \newline 
484
485 \layout Standard
486
487
488 \family typewriter 
489 code banking
490 \begin_inset LatexCommand \index{code banking (not supported)}
491
492 \end_inset 
493
494  support for mcs51
495 \newline 
496
497 \newline 
498
499 \family default 
500 If you can think of some more, please see the section 
501 \begin_inset LatexCommand \ref{sub:Requesting-Features}
502
503 \end_inset 
504
505  about filing feature requests
506 \begin_inset LatexCommand \index{Requesting features}
507
508 \end_inset 
509
510
511 \begin_inset LatexCommand \index{Feature request}
512
513 \end_inset 
514
515 .
516 \newline 
517
518 \layout Chapter
519
520 Installing SDCC
521 \begin_inset LatexCommand \index{Installation}
522
523 \end_inset 
524
525
526 \layout Standard
527
528 For most users it is sufficient to skip to either section 
529 \begin_inset LatexCommand \ref{sub:Building-SDCC-on-Linux}
530
531 \end_inset 
532
533  or section 
534 \begin_inset LatexCommand \ref{sub:Windows-Install}
535
536 \end_inset 
537
538 .
539  More detailled instructions follow below.
540 \layout Section
541
542 Configure Options
543 \begin_inset LatexCommand \index{Options SDCC configuration}
544
545 \end_inset 
546
547
548 \layout Standard
549
550 The install paths, search paths and other options are defined when running
551  'configure'.
552  The defaults can be overridden by:
553 \layout List
554 \labelwidthstring 00.00.0000
555
556 -
557 \begin_inset ERT
558 status Collapsed
559
560 \layout Standard
561
562 \backslash 
563 /
564 \end_inset 
565
566 -prefix see table below
567 \layout List
568 \labelwidthstring 00.00.0000
569
570 -
571 \begin_inset ERT
572 status Collapsed
573
574 \layout Standard
575
576 \backslash 
577 /
578 \end_inset 
579
580 -exec_prefix see table below
581 \layout List
582 \labelwidthstring 00.00.0000
583
584 -
585 \begin_inset ERT
586 status Collapsed
587
588 \layout Standard
589
590 \backslash 
591 /
592 \end_inset 
593
594 -bindir see table below
595 \layout List
596 \labelwidthstring 00.00.0000
597
598 -
599 \begin_inset ERT
600 status Collapsed
601
602 \layout Standard
603
604 \backslash 
605 /
606 \end_inset 
607
608 -datadir see table below
609 \layout List
610 \labelwidthstring 00.00.0000
611
612 docdir environment variable, see table below
613 \layout List
614 \labelwidthstring 00.00.0000
615
616 include_dir_suffix environment variable, see table below
617 \layout List
618 \labelwidthstring 00.00.0000
619
620 lib_dir_suffix environment variable, see table below
621 \layout List
622 \labelwidthstring 00.00.0000
623
624 sdccconf_h_dir_separator environment variable, either / or 
625 \backslash 
626
627 \backslash 
628  makes sense here.
629  This character will only be used in sdccconf.h; don't forget it's a C-header,
630  therefore a double-backslash is needed there.
631 \layout List
632 \labelwidthstring 00.00.0000
633
634 -
635 \begin_inset ERT
636 status Collapsed
637
638 \layout Standard
639
640 \backslash 
641 /
642 \end_inset 
643
644 -disable-mcs51-port Excludes the Intel mcs51 port
645 \layout List
646 \labelwidthstring 00.00.0000
647
648 -
649 \begin_inset ERT
650 status Collapsed
651
652 \layout Standard
653
654 \backslash 
655 /
656 \end_inset 
657
658 -disable-gbz80-port Excludes the Gameboy gbz80 port
659 \layout List
660 \labelwidthstring 00.00.0000
661
662 -
663 \begin_inset ERT
664 status Collapsed
665
666 \layout Standard
667
668 \backslash 
669 /
670 \end_inset 
671
672 -disable-z80-port Excludes the z80 port
673 \layout List
674 \labelwidthstring 00.00.0000
675
676 -
677 \begin_inset ERT
678 status Collapsed
679
680 \layout Standard
681
682 \backslash 
683 /
684 \end_inset 
685
686 -disable-avr-port Excludes the AVR port
687 \layout List
688 \labelwidthstring 00.00.0000
689
690 -
691 \begin_inset ERT
692 status Collapsed
693
694 \layout Standard
695
696 \backslash 
697 /
698 \end_inset 
699
700 -disable-ds390-port Excludes the DS390 port
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-hc08-port Excludes the HC08 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-pic-port Excludes the PIC 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-xa51-port Excludes the XA51 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-ucsim Disables configuring and building of ucsim
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-device-lib-build Disables automatically building device libraries
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-packihx Disables building packihx
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 -enable-libgc Use the Bohem memory allocator.
799  Lower runtime footprint.
800 \layout Standard
801
802 Furthermore the environment variables CC, CFLAGS, ...
803  the tools and their arguments can be influenced.
804  Please see `configure -
805 \begin_inset ERT
806 status Collapsed
807
808 \layout Standard
809
810 \backslash 
811 /
812 \end_inset 
813
814 -help` and the man/info pages of `configure` for details.
815 \newline 
816
817 \newline 
818 The names of the standard libraries STD_LIB, STD_INT_LIB, STD_LONG_LIB,
819  STD_FP_LIB, STD_DS390_LIB, STD_XA51_LIB and the environment variables SDCC_DIR_
820 NAME, SDCC_INCLUDE_NAME, SDCC_LIB_NAME are defined by `configure` too.
821  At the moment it's not possible to change the default settings (it was
822  simply never required).
823 \newline 
824
825 \newline 
826 These configure options are compiled into the binaries, and can only be
827  changed by rerunning 'configure' and recompiling SDCC.
828  The configure options are written in 
829 \emph on 
830 italics
831 \emph default 
832  to distinguish them from run time environment variables (see section search
833  paths).
834 \newline 
835
836 \newline 
837 The settings for 
838 \begin_inset Quotes sld
839 \end_inset 
840
841 Win32 builds
842 \begin_inset Quotes srd
843 \end_inset 
844
845  are used by the SDCC team to build the official Win32 binaries.
846  The SDCC team uses Mingw32 to build the official Windows binaries, because
847  it's
848 \layout Enumerate
849
850 open source, 
851 \layout Enumerate
852
853 a gcc compiler and last but not least
854 \layout Enumerate
855
856 the binaries can be built by cross compiling on Sourceforge's compile farm.
857 \layout Standard
858
859 See the examples, how to pass the Win32 settings to 'configure'.
860  The other Win32 builds using Borland, VC or whatever don't use 'configure',
861  but a header file sdcc_vc_in.h is the same as sdccconf.h built by 'configure'
862  for Win32.
863 \newline 
864
865 \newline 
866 These defaults are:
867 \newline 
868
869 \layout Standard
870 \align center 
871
872 \begin_inset  Tabular
873 <lyxtabular version="3" rows="8" columns="3">
874 <features>
875 <column alignment="block" valignment="top" leftline="true" width="0in">
876 <column alignment="block" valignment="top" leftline="true" width="0in">
877 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
878 <row topline="true" bottomline="true">
879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
880 \begin_inset Text
881
882 \layout Standard
883
884 Variable
885 \end_inset 
886 </cell>
887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
888 \begin_inset Text
889
890 \layout Standard
891
892 default
893 \end_inset 
894 </cell>
895 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
896 \begin_inset Text
897
898 \layout Standard
899
900 Win32 builds
901 \end_inset 
902 </cell>
903 </row>
904 <row topline="true">
905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
906 \begin_inset Text
907
908 \layout Standard
909
910
911 \emph on 
912 PREFIX
913 \end_inset 
914 </cell>
915 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
916 \begin_inset Text
917
918 \layout Standard
919
920 /usr/local
921 \end_inset 
922 </cell>
923 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
924 \begin_inset Text
925
926 \layout Standard
927
928
929 \backslash 
930 sdcc
931 \end_inset 
932 </cell>
933 </row>
934 <row topline="true">
935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
936 \begin_inset Text
937
938 \layout Standard
939
940
941 \emph on 
942 EXEC_PREFIX
943 \end_inset 
944 </cell>
945 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
946 \begin_inset Text
947
948 \layout Standard
949
950
951 \emph on 
952 $PREFIX
953 \end_inset 
954 </cell>
955 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
956 \begin_inset Text
957
958 \layout Standard
959
960
961 \emph on 
962 $PREFIX
963 \end_inset 
964 </cell>
965 </row>
966 <row topline="true">
967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
968 \begin_inset Text
969
970 \layout Standard
971
972
973 \emph on 
974 BINDIR
975 \end_inset 
976 </cell>
977 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
978 \begin_inset Text
979
980 \layout Standard
981
982
983 \emph on 
984 $EXECPREFIX
985 \emph default 
986 /bin
987 \end_inset 
988 </cell>
989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
990 \begin_inset Text
991
992 \layout Standard
993
994
995 \emph on 
996 $EXECPREFIX
997 \emph default 
998
999 \backslash 
1000 bin
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 DATADIR
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 \emph default 
1024 /share
1025 \end_inset 
1026 </cell>
1027 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1028 \begin_inset Text
1029
1030 \layout Standard
1031
1032
1033 \emph on 
1034 $PREFIX
1035 \end_inset 
1036 </cell>
1037 </row>
1038 <row topline="true">
1039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1040 \begin_inset Text
1041
1042 \layout Standard
1043
1044
1045 \emph on 
1046 DOCDIR
1047 \end_inset 
1048 </cell>
1049 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1050 \begin_inset Text
1051
1052 \layout Standard
1053
1054
1055 \emph on 
1056 $DATADIR
1057 \emph default 
1058 /sdcc/doc
1059 \end_inset 
1060 </cell>
1061 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1062 \begin_inset Text
1063
1064 \layout Standard
1065
1066
1067 \emph on 
1068 $DATADIR
1069 \emph default 
1070
1071 \backslash 
1072 doc
1073 \end_inset 
1074 </cell>
1075 </row>
1076 <row topline="true">
1077 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1078 \begin_inset Text
1079
1080 \layout Standard
1081
1082
1083 \emph on 
1084 INCLUDE_DIR_SUFFIX
1085 \end_inset 
1086 </cell>
1087 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1088 \begin_inset Text
1089
1090 \layout Standard
1091
1092 sdcc/include
1093 \end_inset 
1094 </cell>
1095 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1096 \begin_inset Text
1097
1098 \layout Standard
1099
1100 include
1101 \end_inset 
1102 </cell>
1103 </row>
1104 <row topline="true" bottomline="true">
1105 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1106 \begin_inset Text
1107
1108 \layout Standard
1109
1110
1111 \emph on 
1112 LIB_DIR_SUFFIX
1113 \end_inset 
1114 </cell>
1115 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1116 \begin_inset Text
1117
1118 \layout Standard
1119
1120 sdcc/lib
1121 \end_inset 
1122 </cell>
1123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1124 \begin_inset Text
1125
1126 \layout Standard
1127
1128 lib
1129 \end_inset 
1130 </cell>
1131 </row>
1132 </lyxtabular>
1133
1134 \end_inset 
1135
1136
1137 \newline 
1138
1139 \layout Standard
1140 \noindent 
1141 'configure' also computes relative paths.
1142  This is needed for full relocatability of a binary package and to complete
1143  search paths (see section search paths below):
1144 \newline 
1145  
1146 \layout Standard
1147 \align center 
1148
1149 \begin_inset  Tabular
1150 <lyxtabular version="3" rows="4" columns="3">
1151 <features>
1152 <column alignment="block" valignment="top" leftline="true" width="0in">
1153 <column alignment="block" valignment="top" leftline="true" width="0in">
1154 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
1155 <row topline="true" bottomline="true">
1156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1157 \begin_inset Text
1158
1159 \layout Standard
1160
1161 Variable (computed)
1162 \end_inset 
1163 </cell>
1164 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1165 \begin_inset Text
1166
1167 \layout Standard
1168
1169 default
1170 \end_inset 
1171 </cell>
1172 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1173 \begin_inset Text
1174
1175 \layout Standard
1176
1177 Win32 builds
1178 \end_inset 
1179 </cell>
1180 </row>
1181 <row topline="true" bottomline="true">
1182 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1183 \begin_inset Text
1184
1185 \layout Standard
1186
1187
1188 \emph on 
1189 BIN2DATA_DIR
1190 \end_inset 
1191 </cell>
1192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1193 \begin_inset Text
1194
1195 \layout Standard
1196
1197 ../share
1198 \end_inset 
1199 </cell>
1200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1201 \begin_inset Text
1202
1203 \layout Standard
1204
1205 ..
1206 \end_inset 
1207 </cell>
1208 </row>
1209 <row bottomline="true">
1210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1211 \begin_inset Text
1212
1213 \layout Standard
1214
1215
1216 \emph on 
1217 PREFIX2BIN_DIR
1218 \end_inset 
1219 </cell>
1220 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1221 \begin_inset Text
1222
1223 \layout Standard
1224
1225 bin
1226 \end_inset 
1227 </cell>
1228 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1229 \begin_inset Text
1230
1231 \layout Standard
1232
1233 bin
1234 \end_inset 
1235 </cell>
1236 </row>
1237 <row bottomline="true">
1238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1239 \begin_inset Text
1240
1241 \layout Standard
1242
1243
1244 \emph on 
1245 PREFIX2DATA_DIR
1246 \end_inset 
1247 </cell>
1248 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1249 \begin_inset Text
1250
1251 \layout Standard
1252
1253 share/sdcc
1254 \end_inset 
1255 </cell>
1256 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1257 \begin_inset Text
1258
1259 \layout Standard
1260
1261 \end_inset 
1262 </cell>
1263 </row>
1264 </lyxtabular>
1265
1266 \end_inset 
1267
1268
1269 \newline 
1270
1271 \layout Standard
1272 \noindent 
1273 Examples:
1274 \layout LyX-Code
1275
1276 ./configure
1277 \newline 
1278 ./configure -
1279 \begin_inset ERT
1280 status Collapsed
1281
1282 \layout Standard
1283
1284 \backslash 
1285 /
1286 \end_inset 
1287
1288 -prefix=
1289 \begin_inset Quotes srd
1290 \end_inset 
1291
1292 /usr/bin
1293 \begin_inset Quotes srd
1294 \end_inset 
1295
1296  -
1297 \begin_inset ERT
1298 status Collapsed
1299
1300 \layout Standard
1301
1302 \backslash 
1303 /
1304 \end_inset 
1305
1306 -datadir=
1307 \begin_inset Quotes srd
1308 \end_inset 
1309
1310 /usr/share
1311 \begin_inset Quotes srd
1312 \end_inset 
1313
1314
1315 \newline 
1316 ./configure -
1317 \begin_inset ERT
1318 status Collapsed
1319
1320 \layout Standard
1321
1322 \backslash 
1323 /
1324 \end_inset 
1325
1326 -disable-avr-port -
1327 \begin_inset ERT
1328 status Collapsed
1329
1330 \layout Standard
1331
1332 \backslash 
1333 /
1334 \end_inset 
1335
1336 -disable-xa51-port
1337 \layout Standard
1338
1339 To cross compile on linux for Mingw32 (see also 'sdcc/support/scripts/sdcc_mingw
1340 32'):
1341 \layout LyX-Code
1342
1343 ./configure 
1344 \backslash 
1345
1346 \newline 
1347 CC=
1348 \begin_inset Quotes srd
1349 \end_inset 
1350
1351 i586-mingw32msvc-gcc
1352 \begin_inset Quotes srd
1353 \end_inset 
1354
1355  CXX=
1356 \begin_inset Quotes srd
1357 \end_inset 
1358
1359 i586-mingw32msvc-g++
1360 \begin_inset Quotes srd
1361 \end_inset 
1362
1363  
1364 \backslash 
1365  
1366 \newline 
1367 RANLIB=
1368 \begin_inset Quotes srd
1369 \end_inset 
1370
1371 i586-mingw32msvc-ranlib
1372 \begin_inset Quotes srd
1373 \end_inset 
1374
1375  
1376 \backslash 
1377
1378 \newline 
1379 STRIP=
1380 \begin_inset Quotes srd
1381 \end_inset 
1382
1383 i586-mingw32msvc-strip
1384 \begin_inset Quotes srd
1385 \end_inset 
1386
1387  
1388 \backslash 
1389
1390 \newline 
1391 -
1392 \begin_inset ERT
1393 status Collapsed
1394
1395 \layout Standard
1396
1397 \backslash 
1398 /
1399 \end_inset 
1400
1401 -prefix=
1402 \begin_inset Quotes srd
1403 \end_inset 
1404
1405 /sdcc
1406 \begin_inset Quotes srd
1407 \end_inset 
1408
1409  
1410 \backslash 
1411
1412 \newline 
1413 -
1414 \begin_inset ERT
1415 status Collapsed
1416
1417 \layout Standard
1418
1419 \backslash 
1420 /
1421 \end_inset 
1422
1423 -datadir=
1424 \begin_inset Quotes srd
1425 \end_inset 
1426
1427 /sdcc
1428 \begin_inset Quotes srd
1429 \end_inset 
1430
1431  
1432 \backslash 
1433
1434 \newline 
1435 docdir=
1436 \begin_inset Quotes srd
1437 \end_inset 
1438
1439 /sdcc/doc
1440 \begin_inset Quotes srd
1441 \end_inset 
1442
1443  
1444 \backslash 
1445
1446 \newline 
1447 include_dir_suffix=
1448 \begin_inset Quotes srd
1449 \end_inset 
1450
1451 include
1452 \begin_inset Quotes srd
1453 \end_inset 
1454
1455  
1456 \backslash 
1457
1458 \newline 
1459 lib_dir_suffix=
1460 \begin_inset Quotes srd
1461 \end_inset 
1462
1463 lib
1464 \begin_inset Quotes srd
1465 \end_inset 
1466
1467  
1468 \backslash 
1469
1470 \newline 
1471 sdccconf_h_dir_separator=
1472 \begin_inset Quotes srd
1473 \end_inset 
1474
1475
1476 \backslash 
1477
1478 \backslash 
1479
1480 \backslash 
1481
1482 \backslash 
1483
1484 \begin_inset Quotes srd
1485 \end_inset 
1486
1487  
1488 \backslash 
1489
1490 \newline 
1491 -
1492 \begin_inset ERT
1493 status Collapsed
1494
1495 \layout Standard
1496
1497 \backslash 
1498 /
1499 \end_inset 
1500
1501 -disable-device-lib-build
1502 \backslash 
1503
1504 \newline 
1505 -
1506 \begin_inset ERT
1507 status Collapsed
1508
1509 \layout Standard
1510
1511 \backslash 
1512 /
1513 \end_inset 
1514
1515 -disable-ucsim
1516 \backslash 
1517
1518 \newline 
1519 -
1520 \begin_inset ERT
1521 status Collapsed
1522
1523 \layout Standard
1524
1525 \backslash 
1526 /
1527 \end_inset 
1528
1529 -host=i586-mingw32msvc -
1530 \begin_inset ERT
1531 status Collapsed
1532
1533 \layout Standard
1534
1535 \backslash 
1536 /
1537 \end_inset 
1538
1539 -build=unknown-unknown-linux-gnu
1540 \layout Standard
1541
1542 To 
1543 \begin_inset Quotes sld
1544 \end_inset 
1545
1546 cross
1547 \begin_inset Quotes srd
1548 \end_inset 
1549
1550 compile on Cygwin for Mingw32 (see also sdcc/support/scripts/sdcc_cygwin_mingw32
1551 ):
1552 \layout LyX-Code
1553
1554 ./configure -C 
1555 \backslash 
1556
1557 \newline 
1558 CFLAGS=
1559 \begin_inset Quotes srd
1560 \end_inset 
1561
1562 -mno-cygwin -O2
1563 \begin_inset Quotes srd
1564 \end_inset 
1565
1566  
1567 \backslash 
1568
1569 \newline 
1570 LDFLAGS=
1571 \begin_inset Quotes srd
1572 \end_inset 
1573
1574 -mno-cygwin
1575 \begin_inset Quotes srd
1576 \end_inset 
1577
1578  
1579 \backslash 
1580
1581 \newline 
1582 -
1583 \begin_inset ERT
1584 status Collapsed
1585
1586 \layout Standard
1587
1588 \backslash 
1589 /
1590 \end_inset 
1591
1592 -prefix=
1593 \begin_inset Quotes srd
1594 \end_inset 
1595
1596 /sdcc
1597 \begin_inset Quotes srd
1598 \end_inset 
1599
1600  
1601 \backslash 
1602
1603 \newline 
1604 -
1605 \begin_inset ERT
1606 status Collapsed
1607
1608 \layout Standard
1609
1610 \backslash 
1611 /
1612 \end_inset 
1613
1614 -datadir=
1615 \begin_inset Quotes srd
1616 \end_inset 
1617
1618 /sdcc
1619 \begin_inset Quotes srd
1620 \end_inset 
1621
1622  
1623 \backslash 
1624
1625 \newline 
1626 docdir=
1627 \begin_inset Quotes srd
1628 \end_inset 
1629
1630 /sdcc/doc
1631 \begin_inset Quotes srd
1632 \end_inset 
1633
1634  
1635 \backslash 
1636  
1637 \newline 
1638 include_dir_suffix=
1639 \begin_inset Quotes srd
1640 \end_inset 
1641
1642 include
1643 \begin_inset Quotes srd
1644 \end_inset 
1645
1646  
1647 \backslash 
1648
1649 \newline 
1650 lib_dir_suffix=
1651 \begin_inset Quotes srd
1652 \end_inset 
1653
1654 lib
1655 \begin_inset Quotes srd
1656 \end_inset 
1657
1658  
1659 \backslash 
1660
1661 \newline 
1662 sdccconf_h_dir_separator=
1663 \begin_inset Quotes srd
1664 \end_inset 
1665
1666
1667 \backslash 
1668
1669 \backslash 
1670
1671 \backslash 
1672
1673 \backslash 
1674
1675 \begin_inset Quotes srd
1676 \end_inset 
1677
1678  
1679 \backslash 
1680
1681 \newline 
1682 -
1683 \begin_inset ERT
1684 status Collapsed
1685
1686 \layout Standard
1687
1688 \backslash 
1689 /
1690 \end_inset 
1691
1692 -disable-ucsim
1693 \layout Standard
1694
1695 'configure' is quite slow on Cygwin (at least on windows before Win2000/XP).
1696  The option '-
1697 \begin_inset ERT
1698 status Collapsed
1699
1700 \layout Standard
1701
1702 \backslash 
1703 /
1704 \end_inset 
1705
1706 -C' turns on caching, which gives a little bit extra speed.
1707  However if options are changed, it can be necessary to delete the config.cache
1708  file.
1709 \layout Section
1710
1711 Install paths
1712 \begin_inset LatexCommand \label{sub:Install-paths}
1713
1714 \end_inset 
1715
1716
1717 \begin_inset LatexCommand \index{Install paths}
1718
1719 \end_inset 
1720
1721
1722 \layout Standard
1723 \added_space_top medskip \align center 
1724
1725 \begin_inset  Tabular
1726 <lyxtabular version="3" rows="5" columns="4">
1727 <features>
1728 <column alignment="center" valignment="top" leftline="true" width="0">
1729 <column alignment="center" valignment="top" leftline="true" width="0">
1730 <column alignment="center" valignment="top" leftline="true" width="0">
1731 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
1732 <row topline="true" bottomline="true">
1733 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1734 \begin_inset Text
1735
1736 \layout Standard
1737
1738
1739 \series bold 
1740 Description
1741 \end_inset 
1742 </cell>
1743 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1744 \begin_inset Text
1745
1746 \layout Standard
1747
1748
1749 \series bold 
1750 Path
1751 \end_inset 
1752 </cell>
1753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1754 \begin_inset Text
1755
1756 \layout Standard
1757
1758
1759 \series bold 
1760 Default
1761 \end_inset 
1762 </cell>
1763 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1764 \begin_inset Text
1765
1766 \layout Standard
1767
1768
1769 \series bold 
1770 Win32 builds
1771 \end_inset 
1772 </cell>
1773 </row>
1774 <row topline="true">
1775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1776 \begin_inset Text
1777
1778 \layout Standard
1779
1780 Binary files*
1781 \end_inset 
1782 </cell>
1783 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1784 \begin_inset Text
1785
1786 \layout Standard
1787
1788
1789 \emph on 
1790 $EXEC_PREFIX
1791 \end_inset 
1792 </cell>
1793 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1794 \begin_inset Text
1795
1796 \layout Standard
1797
1798 /usr/local/bin
1799 \end_inset 
1800 </cell>
1801 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1802 \begin_inset Text
1803
1804 \layout Standard
1805
1806
1807 \backslash 
1808 sdcc
1809 \backslash 
1810 bin
1811 \end_inset 
1812 </cell>
1813 </row>
1814 <row topline="true">
1815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1816 \begin_inset Text
1817
1818 \layout Standard
1819
1820 Include files
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 \emph on 
1830 $DATADIR/ $INCLUDE_DIR_SUFFIX
1831 \end_inset 
1832 </cell>
1833 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1834 \begin_inset Text
1835
1836 \layout Standard
1837
1838 /usr/local/share/sdcc/include
1839 \end_inset 
1840 </cell>
1841 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1842 \begin_inset Text
1843
1844 \layout Standard
1845
1846
1847 \backslash 
1848 sdcc
1849 \backslash 
1850 include
1851 \end_inset 
1852 </cell>
1853 </row>
1854 <row topline="true">
1855 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1856 \begin_inset Text
1857
1858 \layout Standard
1859
1860 Library file**
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
1869 \emph on 
1870 $DATADIR/$LIB_DIR_SUFFIX
1871 \end_inset 
1872 </cell>
1873 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1874 \begin_inset Text
1875
1876 \layout Standard
1877
1878 /usr/local/share/sdcc/lib
1879 \end_inset 
1880 </cell>
1881 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1882 \begin_inset Text
1883
1884 \layout Standard
1885
1886
1887 \backslash 
1888 sdcc
1889 \backslash 
1890 lib
1891 \end_inset 
1892 </cell>
1893 </row>
1894 <row topline="true" bottomline="true">
1895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1896 \begin_inset Text
1897
1898 \layout Standard
1899
1900 Documentation
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
1909 \emph on 
1910 $DOCDIR
1911 \end_inset 
1912 </cell>
1913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
1914 \begin_inset Text
1915
1916 \layout Standard
1917
1918 /usr/local/share/sdcc/doc
1919 \end_inset 
1920 </cell>
1921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
1922 \begin_inset Text
1923
1924 \layout Standard
1925
1926
1927 \backslash 
1928 sdcc
1929 \backslash 
1930 doc
1931 \end_inset 
1932 </cell>
1933 </row>
1934 </lyxtabular>
1935
1936 \end_inset 
1937
1938
1939 \layout Verse
1940
1941
1942 \size footnotesize 
1943 *compiler, preprocessor, assembler, and linker
1944 \newline 
1945 **the 
1946 \shape italic 
1947 model
1948 \shape default 
1949  is auto-appended by the compiler, e.g.
1950  small, large, z80, ds390 etc
1951 \layout Standard
1952 \noindent 
1953 The install paths can still be changed during `make install` with e.g.:
1954 \layout LyX-Code
1955
1956 make install prefix=$(HOME)/local/sdcc
1957 \layout Standard
1958
1959 Of course this doesn't change the search paths compiled into the binaries.
1960 \newline 
1961
1962 \newline 
1963 Moreover the install path can be changed by defining DESTDIR
1964 \begin_inset LatexCommand \index{DESTDIR}
1965
1966 \end_inset 
1967
1968 :
1969 \layout LyX-Code
1970
1971 make install DESTDIR=$(HOME)/sdcc.rpm/
1972 \layout Standard
1973
1974 Please note that DESTDIR must have a trailing slash!
1975 \layout Section
1976
1977 Search Paths
1978 \begin_inset LatexCommand \label{sub:Search-Paths}
1979
1980 \end_inset 
1981
1982
1983 \begin_inset LatexCommand \index{Search path}
1984
1985 \end_inset 
1986
1987
1988 \layout Standard
1989
1990 Some search paths or parts of them are determined by configure variables
1991  (in 
1992 \emph on 
1993 italics
1994 \emph default 
1995 , see section above).
1996  Further search paths are determined by environment variables during runtime.
1997  
1998 \newline 
1999 The paths searched when running the compiler are as follows (the first catch
2000  wins):
2001 \newline 
2002
2003 \newline 
2004 1.
2005  Binary files (preprocessor, assembler and linker)
2006 \newline 
2007
2008 \layout Standard
2009 \align center 
2010
2011 \begin_inset  Tabular
2012 <lyxtabular version="3" rows="4" columns="3">
2013 <features>
2014 <column alignment="block" valignment="top" leftline="true" width="0in">
2015 <column alignment="block" valignment="top" leftline="true" width="0in">
2016 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2017 <row topline="true" bottomline="true">
2018 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2019 \begin_inset Text
2020
2021 \layout Standard
2022
2023 Search path
2024 \end_inset 
2025 </cell>
2026 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2027 \begin_inset Text
2028
2029 \layout Standard
2030
2031 default
2032 \end_inset 
2033 </cell>
2034 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2035 \begin_inset Text
2036
2037 \layout Standard
2038
2039 Win32 builds
2040 \end_inset 
2041 </cell>
2042 </row>
2043 <row topline="true">
2044 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2045 \begin_inset Text
2046
2047 \layout Standard
2048
2049 $SDCC_HOME/
2050 \emph on 
2051 $PPREFIX2BIN_DIR
2052 \end_inset 
2053 </cell>
2054 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2055 \begin_inset Text
2056
2057 \layout Standard
2058
2059 $SDCC_HOME/bin
2060 \end_inset 
2061 </cell>
2062 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2063 \begin_inset Text
2064
2065 \layout Standard
2066
2067 $SDCC_HOME
2068 \backslash 
2069 bin
2070 \end_inset 
2071 </cell>
2072 </row>
2073 <row topline="true">
2074 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2075 \begin_inset Text
2076
2077 \layout Standard
2078
2079 Path of argv[0] (if available)
2080 \end_inset 
2081 </cell>
2082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2083 \begin_inset Text
2084
2085 \layout Standard
2086
2087 Path of argv[0]
2088 \end_inset 
2089 </cell>
2090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2091 \begin_inset Text
2092
2093 \layout Standard
2094
2095 Path of argv[0]
2096 \end_inset 
2097 </cell>
2098 </row>
2099 <row topline="true" bottomline="true">
2100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2101 \begin_inset Text
2102
2103 \layout Standard
2104
2105 $PATH
2106 \end_inset 
2107 </cell>
2108 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2109 \begin_inset Text
2110
2111 \layout Standard
2112
2113 $PATH
2114 \end_inset 
2115 </cell>
2116 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2117 \begin_inset Text
2118
2119 \layout Standard
2120
2121 $PATH
2122 \end_inset 
2123 </cell>
2124 </row>
2125 </lyxtabular>
2126
2127 \end_inset 
2128
2129  
2130 \newline 
2131
2132 \layout Standard
2133 \noindent 
2134 2.
2135  Include files
2136 \newline 
2137
2138 \layout Standard
2139 \align center 
2140
2141 \begin_inset  Tabular
2142 <lyxtabular version="3" rows="6" columns="3">
2143 <features>
2144 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2145 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2146 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2147 <row topline="true" bottomline="true">
2148 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2149 \begin_inset Text
2150
2151 \layout Standard
2152
2153 Search path
2154 \end_inset 
2155 </cell>
2156 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2157 \begin_inset Text
2158
2159 \layout Standard
2160
2161 default
2162 \end_inset 
2163 </cell>
2164 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2165 \begin_inset Text
2166
2167 \layout Standard
2168
2169 Win32 builds
2170 \end_inset 
2171 </cell>
2172 </row>
2173 <row topline="true">
2174 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2175 \begin_inset Text
2176
2177 \layout Standard
2178
2179 -
2180 \begin_inset ERT
2181 status Collapsed
2182
2183 \layout Standard
2184
2185 \backslash 
2186 /
2187 \end_inset 
2188
2189 -I dir
2190 \end_inset 
2191 </cell>
2192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2193 \begin_inset Text
2194
2195 \layout Standard
2196
2197 -
2198 \begin_inset ERT
2199 status Collapsed
2200
2201 \layout Standard
2202
2203 \backslash 
2204 /
2205 \end_inset 
2206
2207 -I dir
2208 \end_inset 
2209 </cell>
2210 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2211 \begin_inset Text
2212
2213 \layout Standard
2214
2215 -
2216 \begin_inset ERT
2217 status Collapsed
2218
2219 \layout Standard
2220
2221 \backslash 
2222 /
2223 \end_inset 
2224
2225 -I dir
2226 \end_inset 
2227 </cell>
2228 </row>
2229 <row topline="true">
2230 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2231 \begin_inset Text
2232
2233 \layout Standard
2234
2235 $SDCC_INCLUDE
2236 \end_inset 
2237 </cell>
2238 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2239 \begin_inset Text
2240
2241 \layout Standard
2242
2243 $SDCC_INCLUDE
2244 \end_inset 
2245 </cell>
2246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2247 \begin_inset Text
2248
2249 \layout Standard
2250
2251 $SDCC_INCLUDE
2252 \end_inset 
2253 </cell>
2254 </row>
2255 <row topline="true">
2256 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2257 \begin_inset Text
2258
2259 \layout Standard
2260
2261 $SDCC_HOME/
2262 \newline 
2263
2264 \emph on 
2265 $PREFIX2DATA_DIR/
2266 \newline 
2267 $INCLUDE_DIR_SUFFIX
2268 \end_inset 
2269 </cell>
2270 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2271 \begin_inset Text
2272
2273 \layout Standard
2274
2275 $SDCC_ HOME/
2276 \newline 
2277 share/sdcc/
2278 \newline 
2279 include
2280 \end_inset 
2281 </cell>
2282 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2283 \begin_inset Text
2284
2285 \layout Standard
2286
2287 $SDCC_HOME
2288 \backslash 
2289 include
2290 \end_inset 
2291 </cell>
2292 </row>
2293 <row topline="true">
2294 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2295 \begin_inset Text
2296
2297 \layout Standard
2298
2299 path(argv[0])/
2300 \newline 
2301
2302 \emph on 
2303 $BIN2DATADIR/
2304 \emph default 
2305
2306 \newline 
2307
2308 \emph on 
2309 $INCLUDE_DIR_SUFFIX
2310 \end_inset 
2311 </cell>
2312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2313 \begin_inset Text
2314
2315 \layout Standard
2316
2317 path(argv[0])/
2318 \newline 
2319 ../sdcc/include
2320 \newline 
2321 \SpecialChar ~
2322 \SpecialChar ~
2323 \SpecialChar ~
2324 \SpecialChar ~
2325 \SpecialChar ~
2326 \SpecialChar ~
2327 \SpecialChar ~
2328 \SpecialChar ~
2329 \SpecialChar ~
2330 \SpecialChar ~
2331 \SpecialChar ~
2332 \SpecialChar ~
2333 \SpecialChar ~
2334 \SpecialChar ~
2335 \SpecialChar ~
2336 \SpecialChar ~
2337 \SpecialChar ~
2338 \SpecialChar ~
2339 \SpecialChar ~
2340 \SpecialChar ~
2341 \SpecialChar ~
2342 \SpecialChar ~
2343 \SpecialChar ~
2344 \SpecialChar ~
2345 \SpecialChar ~
2346 \SpecialChar ~
2347 \SpecialChar ~
2348 \SpecialChar ~
2349 \SpecialChar ~
2350 \SpecialChar ~
2351 \SpecialChar ~
2352 \SpecialChar ~
2353 \SpecialChar ~
2354 \SpecialChar ~
2355 \SpecialChar ~
2356 \SpecialChar ~
2357 \SpecialChar ~
2358 \SpecialChar ~
2359
2360 \end_inset 
2361 </cell>
2362 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2363 \begin_inset Text
2364
2365 \layout Standard
2366
2367 path(argv[0])
2368 \backslash 
2369 ..
2370 \backslash 
2371 include
2372 \end_inset 
2373 </cell>
2374 </row>
2375 <row topline="true" bottomline="true">
2376 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2377 \begin_inset Text
2378
2379 \layout Standard
2380
2381
2382 \emph on 
2383 $DATADIR/
2384 \emph default 
2385
2386 \newline 
2387
2388 \emph on 
2389 $INCLUDE_DIR_SUFFIX
2390 \end_inset 
2391 </cell>
2392 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2393 \begin_inset Text
2394
2395 \layout Standard
2396
2397 /usr/local/share/sdcc/
2398 \newline 
2399 include
2400 \end_inset 
2401 </cell>
2402 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2403 \begin_inset Text
2404
2405 \layout Standard
2406
2407 (not on Win32)
2408 \end_inset 
2409 </cell>
2410 </row>
2411 </lyxtabular>
2412
2413 \end_inset 
2414
2415  
2416 \newline 
2417
2418 \layout Standard
2419 \noindent 
2420 The option -
2421 \begin_inset ERT
2422 status Collapsed
2423
2424 \layout Standard
2425
2426 \backslash 
2427 /
2428 \end_inset 
2429
2430 -nostdinc disables the last two search paths.
2431 \newline 
2432
2433 \newline 
2434 3.
2435  Library files 
2436 \newline 
2437
2438 \layout Standard
2439
2440 With the exception of 
2441 \begin_inset Quotes sld
2442 \end_inset 
2443
2444 -
2445 \begin_inset ERT
2446 status Collapsed
2447
2448 \layout Standard
2449
2450 \backslash 
2451 /
2452 \end_inset 
2453
2454 -L dir
2455 \begin_inset Quotes srd
2456 \end_inset 
2457
2458  the 
2459 \shape italic 
2460 model
2461 \shape default 
2462  is auto-appended by the compiler (e.g.
2463  small, large, z80, ds390 etc.).
2464  
2465 \newline 
2466
2467 \layout Standard
2468 \align center 
2469
2470 \begin_inset  Tabular
2471 <lyxtabular version="3" rows="6" columns="3">
2472 <features>
2473 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2474 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2475 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2476 <row topline="true" bottomline="true">
2477 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2478 \begin_inset Text
2479
2480 \layout Standard
2481
2482 Search path
2483 \end_inset 
2484 </cell>
2485 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2486 \begin_inset Text
2487
2488 \layout Standard
2489
2490 default
2491 \end_inset 
2492 </cell>
2493 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2494 \begin_inset Text
2495
2496 \layout Standard
2497
2498 Win32 builds
2499 \end_inset 
2500 </cell>
2501 </row>
2502 <row topline="true">
2503 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2504 \begin_inset Text
2505
2506 \layout Standard
2507
2508 -
2509 \begin_inset ERT
2510 status Collapsed
2511
2512 \layout Standard
2513
2514 \backslash 
2515 /
2516 \end_inset 
2517
2518 -L dir
2519 \end_inset 
2520 </cell>
2521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2522 \begin_inset Text
2523
2524 \layout Standard
2525
2526 -
2527 \begin_inset ERT
2528 status Collapsed
2529
2530 \layout Standard
2531
2532 \backslash 
2533 /
2534 \end_inset 
2535
2536 -L dir
2537 \end_inset 
2538 </cell>
2539 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2540 \begin_inset Text
2541
2542 \layout Standard
2543
2544 -
2545 \begin_inset ERT
2546 status Collapsed
2547
2548 \layout Standard
2549
2550 \backslash 
2551 /
2552 \end_inset 
2553
2554 -L dir
2555 \end_inset 
2556 </cell>
2557 </row>
2558 <row topline="true">
2559 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2560 \begin_inset Text
2561
2562 \layout Standard
2563
2564 $SDCC_LIB/
2565 \newline 
2566
2567 \emph on 
2568 <model>
2569 \end_inset 
2570 </cell>
2571 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2572 \begin_inset Text
2573
2574 \layout Standard
2575
2576 $SDCC_LIB/
2577 \newline 
2578
2579 \emph on 
2580 <model>
2581 \end_inset 
2582 </cell>
2583 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2584 \begin_inset Text
2585
2586 \layout Standard
2587
2588 $SDCC_LIB
2589 \backslash 
2590
2591 \newline 
2592
2593 \emph on 
2594 <model>
2595 \end_inset 
2596 </cell>
2597 </row>
2598 <row topline="true">
2599 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2600 \begin_inset Text
2601
2602 \layout Standard
2603
2604 $SDCC_HOME/
2605 \newline 
2606
2607 \emph on 
2608 $PREFIX2DATA_DIR/
2609 \newline 
2610 $LIB_DIR_SUFFIX/<model>
2611 \end_inset 
2612 </cell>
2613 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2614 \begin_inset Text
2615
2616 \layout Standard
2617
2618 $SDCC_HOME/
2619 \newline 
2620 share/sdcc/
2621 \newline 
2622 lib/
2623 \emph on 
2624 <model>
2625 \end_inset 
2626 </cell>
2627 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2628 \begin_inset Text
2629
2630 \layout Standard
2631
2632 $SDCC_HOME
2633 \backslash 
2634 lib
2635 \backslash 
2636
2637 \emph on 
2638
2639 \newline 
2640 <model>
2641 \end_inset 
2642 </cell>
2643 </row>
2644 <row topline="true">
2645 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2646 \begin_inset Text
2647
2648 \layout Standard
2649
2650 path(argv[0])/
2651 \newline 
2652
2653 \emph on 
2654 $BIN2DATADIR/
2655 \emph default 
2656
2657 \newline 
2658
2659 \emph on 
2660 $LIB_DIR_SUFFIX/<model>
2661 \end_inset 
2662 </cell>
2663 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2664 \begin_inset Text
2665
2666 \layout Standard
2667
2668 path(argv[0])/
2669 \newline 
2670 ../sdcc/lib/
2671 \emph on 
2672 <model>
2673 \newline 
2674 \SpecialChar ~
2675 \SpecialChar ~
2676 \SpecialChar ~
2677 \SpecialChar ~
2678 \SpecialChar ~
2679 \SpecialChar ~
2680 \SpecialChar ~
2681 \SpecialChar ~
2682 \SpecialChar ~
2683 \SpecialChar ~
2684 \SpecialChar ~
2685 \SpecialChar ~
2686 \SpecialChar ~
2687 \SpecialChar ~
2688 \SpecialChar ~
2689 \SpecialChar ~
2690 \SpecialChar ~
2691 \SpecialChar ~
2692 \SpecialChar ~
2693 \SpecialChar ~
2694 \SpecialChar ~
2695 \SpecialChar ~
2696 \SpecialChar ~
2697 \SpecialChar ~
2698 \SpecialChar ~
2699 \SpecialChar ~
2700 \SpecialChar ~
2701 \SpecialChar ~
2702 \SpecialChar ~
2703 \SpecialChar ~
2704 \SpecialChar ~
2705 \SpecialChar ~
2706 \SpecialChar ~
2707 \SpecialChar ~
2708 \SpecialChar ~
2709 \SpecialChar ~
2710 \SpecialChar ~
2711 \SpecialChar ~
2712 \SpecialChar ~
2713
2714 \end_inset 
2715 </cell>
2716 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2717 \begin_inset Text
2718
2719 \layout Standard
2720
2721 path(argv[0])
2722 \backslash 
2723
2724 \newline 
2725 ..
2726 \backslash 
2727 lib
2728 \backslash 
2729
2730 \emph on 
2731 <model>
2732 \newline 
2733 \SpecialChar ~
2734 \SpecialChar ~
2735 \SpecialChar ~
2736 \SpecialChar ~
2737 \SpecialChar ~
2738 \SpecialChar ~
2739 \SpecialChar ~
2740 \SpecialChar ~
2741 \SpecialChar ~
2742 \SpecialChar ~
2743 \SpecialChar ~
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
2769 \end_inset 
2770 </cell>
2771 </row>
2772 <row topline="true" bottomline="true">
2773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2774 \begin_inset Text
2775
2776 \layout Standard
2777
2778
2779 \emph on 
2780 $DATADIR/
2781 \newline 
2782 $LIB_DIR_SUFFIX/<model>
2783 \end_inset 
2784 </cell>
2785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2786 \begin_inset Text
2787
2788 \layout Standard
2789
2790 /usr/local/share/sdcc/
2791 \newline 
2792 lib/
2793 \emph on 
2794 <model>
2795 \end_inset 
2796 </cell>
2797 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2798 \begin_inset Text
2799
2800 \layout Standard
2801
2802 (not on Win32)
2803 \end_inset 
2804 </cell>
2805 </row>
2806 </lyxtabular>
2807
2808 \end_inset 
2809
2810
2811 \newline 
2812
2813 \layout Comment
2814
2815 Don't delete any of the stray spaces in the table above without checking
2816  the HTML output (last line)!
2817 \layout Standard
2818
2819 \SpecialChar ~
2820
2821 \newline 
2822 The option -
2823 \begin_inset ERT
2824 status Collapsed
2825
2826 \layout Standard
2827
2828 \backslash 
2829 /
2830 \end_inset 
2831
2832 -nostdlib disables the last two search paths.
2833 \layout Section
2834
2835 Building SDCC
2836 \begin_inset LatexCommand \index{Building SDCC}
2837
2838 \end_inset 
2839
2840
2841 \layout Subsection
2842
2843 Building SDCC on Linux
2844 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2845
2846 \end_inset 
2847
2848
2849 \layout Enumerate
2850
2851
2852 \series medium 
2853 Download the source package
2854 \series default 
2855  either from the SDCC CVS repository or from the nightly snapshots
2856 \series medium 
2857 , it will be named something like sdcc
2858 \series default 
2859 .src
2860 \series medium 
2861 .t
2862 \series default 
2863 ar.
2864 \series medium 
2865 gz
2866 \series default 
2867  
2868 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2869
2870 \end_inset 
2871
2872 .
2873 \layout Enumerate
2874
2875
2876 \series medium 
2877 Bring up a command line terminal, such as xterm.
2878 \layout Enumerate
2879
2880
2881 \series medium 
2882 Unpack the file using a command like: 
2883 \family sans 
2884 \series bold 
2885 "tar -xvzf sdcc.src.tar.gz
2886 \family default 
2887 \series default 
2888 "
2889 \series medium 
2890 , this will create a sub-directory called sdcc with all of the sources.
2891 \layout Enumerate
2892
2893 Change directory into the main SDCC directory, for example type: 
2894 \family sans 
2895 \series bold 
2896 "cd sdcc
2897 \series default 
2898 ".
2899 \layout Enumerate
2900
2901
2902 \series medium 
2903 Type 
2904 \family sans 
2905 \series bold 
2906 "./configure
2907 \family default 
2908 \series default 
2909 ".
2910  This configures the package for compilation on your system.
2911 \layout Enumerate
2912
2913
2914 \series medium 
2915 Type 
2916 \family sans 
2917 \series bold 
2918 "make
2919 \family default 
2920 \series default 
2921 "
2922 \series medium 
2923 .
2924
2925 \series default 
2926  All of the source packages will compile, this can take a while.
2927 \layout Enumerate
2928
2929
2930 \series medium 
2931 Type 
2932 \family sans 
2933 \series bold 
2934 "make install"
2935 \family default 
2936 \series default 
2937  as root
2938 \series medium 
2939 .
2940
2941 \series default 
2942  This copies the binary executables, the include files, the libraries and
2943  the documentation to the install directories.
2944  Proceed with section 
2945 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
2946
2947 \end_inset 
2948
2949 .
2950 \layout Subsection
2951
2952 Building SDCC on OSX 2.x
2953 \layout Standard
2954
2955 Follow the instruction for Linux.
2956 \newline 
2957
2958 \newline 
2959 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2960 )) fails to compile SDCC.
2961  Fortunately there's also gcc 2.9.x installed, which works fine.
2962  This compiler can be selected by running 'configure' with:
2963 \layout LyX-Code
2964
2965 ./configure CC=gcc2 CXX=g++2
2966 \layout Subsection
2967
2968 Cross compiling SDCC on Linux for Windows
2969 \layout Standard
2970
2971 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2972  See section 'Configure Options'.
2973 \layout Subsection
2974
2975 Building SDCC on Windows 
2976 \layout Standard
2977
2978 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2979  built on Windows.
2980  They use Unix-sockets, which are not available on Win32.
2981 \layout Subsection
2982
2983 Building SDCC using Cygwin and Mingw32
2984 \layout Standard
2985
2986 For building and installing a Cygwin executable follow the instructions
2987  for Linux.
2988 \newline 
2989
2990 \newline 
2991 On Cygwin a 
2992 \begin_inset Quotes sld
2993 \end_inset 
2994
2995 native
2996 \begin_inset Quotes srd
2997 \end_inset 
2998
2999  Win32-binary can be built, which will not need the Cygwin-DLL.
3000  For the necessary 'configure' options see section 'configure options' or
3001  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
3002 \newline 
3003
3004 \newline 
3005 In order to install Cygwin on Windows download setup.exe from 
3006 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
3007
3008 \end_inset 
3009
3010 .
3011  Run it, set the 
3012 \begin_inset Quotes sld
3013 \end_inset 
3014
3015 default text file type
3016 \begin_inset Quotes srd
3017 \end_inset 
3018
3019  to 
3020 \begin_inset Quotes sld
3021 \end_inset 
3022
3023 unix
3024 \begin_inset Quotes srd
3025 \end_inset 
3026
3027  and download/install at least the following packages.
3028  Some packages are selected by default, others will be automatically selected
3029  because of dependencies with the manually selected packages.
3030  Never deselect these packages!
3031 \layout Itemize
3032
3033 flex
3034 \layout Itemize
3035
3036 bison
3037 \layout Itemize
3038
3039 gcc ; version 3.x is fine, no need to use the old 2.9x
3040 \layout Itemize
3041
3042 binutils ; selected with gcc
3043 \layout Itemize
3044
3045 make
3046 \layout Itemize
3047
3048 rxvt ; a nice console, which makes life much easier under windoze (see below)
3049 \layout Itemize
3050
3051 man ; not really needed for building SDCC, but you'll miss it sooner or
3052  later
3053 \layout Itemize
3054
3055 less ; not really needed for building SDCC, but you'll miss it sooner or
3056  later
3057 \layout Itemize
3058
3059 cvs ; only if you use CVS access
3060 \layout Standard
3061
3062 If you want to develop something you'll need:
3063 \layout Itemize
3064
3065 python ; for the regression tests
3066 \layout Itemize
3067
3068 gdb ; the gnu debugger, together with the nice GUI 
3069 \begin_inset Quotes sld
3070 \end_inset 
3071
3072 insight
3073 \begin_inset Quotes srd
3074 \end_inset 
3075
3076
3077 \layout Itemize
3078
3079 openssh ; to access the CF or commit changes
3080 \layout Itemize
3081
3082 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3083  use autoconf-stable!
3084 \layout Standard
3085
3086 rxvt is a nice console with history.
3087  Replace in your cygwin.bat the line
3088 \layout LyX-Code
3089
3090 bash -
3091 \begin_inset ERT
3092 status Collapsed
3093
3094 \layout Standard
3095
3096 \backslash 
3097 /
3098 \end_inset 
3099
3100 -login -i 
3101 \layout Standard
3102
3103 with (one line):
3104 \layout LyX-Code
3105
3106 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3107 \layout LyX-Code
3108
3109      -bg black -fg white -geometry 100x65 -e bash -
3110 \begin_inset ERT
3111 status Collapsed
3112
3113 \layout Standard
3114
3115 \backslash 
3116 /
3117 \end_inset 
3118
3119 -login
3120 \layout Standard
3121
3122 Text selected with the mouse is automatically copied to the clipboard, pasting
3123  works with shift-insert.
3124 \newline 
3125
3126 \newline 
3127 The other good tip is to make sure you have no //c/-style paths anywhere,
3128  use /cygdrive/c/ instead.
3129  Using // invokes a network lookup which is very slow.
3130  If you think 
3131 \begin_inset Quotes sld
3132 \end_inset 
3133
3134 cygdrive
3135 \begin_inset Quotes srd
3136 \end_inset 
3137
3138  is too long, you can change it with e.g.
3139 \layout LyX-Code
3140
3141 mount -s -u -c /mnt
3142 \layout Standard
3143
3144 SDCC sources use the unix line ending LF.
3145  Life is much easier, if you store the source tree on a drive which is mounted
3146  in binary mode.
3147  And use an editor which can handle LF-only line endings.
3148  Make sure not to commit files with windows line endings.
3149  The tabulator spacing
3150 \begin_inset LatexCommand \index{tabulator spacing (8)}
3151
3152 \end_inset 
3153
3154  used in the project is 8.
3155 \layout Subsection
3156
3157 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3158 \layout Standard
3159
3160
3161 \series medium 
3162 Download the source package
3163 \series default 
3164  either from the SDCC CVS repository or from the 
3165 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3166
3167 \end_inset 
3168
3169
3170 \series medium 
3171 , it will be named something like sdcc
3172 \series default 
3173 .src
3174 \series medium 
3175 .tgz.
3176
3177 \series default 
3178  SDCC is distributed with all the projects, workspaces, and files you need
3179  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3180  doesn't build under MSVC).
3181  The workspace name is 'sdcc.dsw'.
3182  Please note that as it is now, all the executables are created in a folder
3183  called sdcc
3184 \backslash 
3185 bin_vc.
3186  Once built you need to copy the executables from sdcc
3187 \backslash 
3188 bin_vc to sdcc
3189 \backslash 
3190 bin before running SDCC.
3191  
3192 \newline 
3193
3194 \newline 
3195 WARNING: Visual studio is very picky with line terminations; it expects
3196  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3197  If you are getting a message such as "This makefile was not generated by
3198  Developer Studio etc.
3199  etc.
3200 \begin_inset Quotes srd
3201 \end_inset 
3202
3203  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3204  need to convert the Unix style line endings to DOS style line endings.
3205  To do so you can use the 
3206 \begin_inset Quotes sld
3207 \end_inset 
3208
3209 unix2dos
3210 \begin_inset Quotes srd
3211 \end_inset 
3212
3213  utility freely available on the internet.
3214  Doug Hawkins reported in the sdcc-user list that this works:
3215 \newline 
3216
3217 \newline 
3218 C:
3219 \backslash 
3220 Programming
3221 \backslash 
3222 SDCC> unix2dos sdcc.dsw
3223 \newline 
3224 C:
3225 \backslash 
3226 Programming
3227 \backslash 
3228 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3229 \newline 
3230
3231 \newline 
3232 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3233  flex.exe, and gawk.exe.
3234  One good place to get them is 
3235 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3236
3237 \end_inset 
3238
3239
3240 \newline 
3241
3242 \newline 
3243 Download the file UnxUtils
3244 \begin_inset LatexCommand \index{UnxUtils}
3245
3246 \end_inset 
3247
3248 .zip.
3249  Now you have to install the utilities and setup MSVC so it can locate the
3250  required programs.
3251  Here there are two alternatives (choose one!):
3252 \layout Enumerate
3253
3254 The easy way:
3255 \newline 
3256
3257 \newline 
3258 a) Extract UnxUtils.zip to your C:
3259 \backslash 
3260  hard disk PRESERVING the original paths, otherwise bison won't work.
3261  (If you are using WinZip make certain that 'Use folder names' is selected)
3262 \newline 
3263
3264 \newline 
3265 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3266  in 'Show directories for:' select 'Executable files', and in the directories
3267  window add a new path: 'C:
3268 \backslash 
3269 user
3270 \backslash 
3271 local
3272 \backslash 
3273 wbin', click ok.
3274 \newline 
3275
3276 \newline 
3277 (As a side effect, you get a bunch of Unix utilities that could be useful,
3278  such as diff and patch.)
3279 \layout Enumerate
3280
3281 A more compact way:
3282 \newline 
3283
3284 \newline 
3285 This one avoids extracting a bunch of files you may not use, but requires
3286  some extra work:
3287 \newline 
3288
3289 \newline 
3290 a) Create a directory were to put the tools needed, or use a directory already
3291  present.
3292  Say for example 'C:
3293 \backslash 
3294 util'.
3295 \newline 
3296
3297 \newline 
3298 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3299  to such directory WITHOUT preserving the original paths.
3300  (If you are using WinZip make certain that 'Use folder names' is not selected)
3301 \newline 
3302
3303 \newline 
3304 c) Rename bison.exe to '_bison.exe'.
3305 \newline 
3306
3307 \newline 
3308 d) Create a batch file 'bison.bat' in 'C:
3309 \backslash 
3310 util
3311 \backslash 
3312 ' and add these lines: 
3313 \newline 
3314 \SpecialChar ~
3315 \SpecialChar ~
3316 set BISON_SIMPLE=C:
3317 \backslash 
3318 util
3319 \backslash 
3320 bison.simple 
3321 \newline 
3322 \SpecialChar ~
3323 \SpecialChar ~
3324 set BISON_HAIRY=C:
3325 \backslash 
3326 util
3327 \backslash 
3328 bison.hairy
3329 \newline 
3330 \SpecialChar ~
3331 \SpecialChar ~
3332 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3333 \newline 
3334
3335 \newline 
3336 Steps 'c' and 'd' are needed because bison requires by default that the
3337  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3338  '/usr/local/share/' I think.
3339  So it is necessary to tell bison where those files are located if they
3340  are not in such directory.
3341  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3342 \newline 
3343
3344 \newline 
3345 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3346  in 'Show directories for:' select 'Executable files', and in the directories
3347  window add a new path: 'c:
3348 \backslash 
3349 util', click ok.
3350  Note that you can use any other path instead of 'c:
3351 \backslash 
3352 util', even the path where the Visual C++ tools are, probably: 'C:
3353 \backslash 
3354 Program Files
3355 \backslash 
3356 Microsoft Visual Studio
3357 \backslash 
3358 Common
3359 \backslash 
3360 Tools'.
3361  So you don't have to execute step 'e' :)
3362 \layout Standard
3363
3364 That is it.
3365  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3366  the executables from sdcc
3367 \backslash 
3368 bin_vc to sdcc
3369 \backslash 
3370 bin, and you can compile using SDCC.
3371 \layout Subsection
3372
3373 Building SDCC Using Borland
3374 \layout Enumerate
3375
3376 From the sdcc directory, run the command "make -f Makefile.bcc".
3377  This should regenerate all the .exe files in the bin directory except for
3378  sdcdb.exe (which currently doesn't build under Borland C++).
3379 \layout Enumerate
3380
3381 If you modify any source files and need to rebuild, be aware that the dependenci
3382 es may not be correctly calculated.
3383  The safest option is to delete all .obj files and run the build again.
3384  From a Cygwin BASH prompt, this can easily be done with the command (be
3385  sure you are in the sdcc directory):
3386 \newline 
3387
3388 \newline 
3389
3390 \family sans 
3391 \series bold 
3392 find .
3393  
3394 \backslash 
3395 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3396 \backslash 
3397 ) -print -exec rm {} 
3398 \backslash 
3399 ;
3400 \family default 
3401 \series default 
3402
3403 \newline 
3404
3405 \newline 
3406 or on Windows NT/2000/XP from the command prompt with the command:
3407 \newline 
3408
3409 \family sans 
3410 \series bold 
3411
3412 \newline 
3413 del /s *.obj *.lib *.rul
3414 \family default 
3415 \series default 
3416  from the sdcc directory.
3417 \layout Subsection
3418
3419 Windows Install Using a Binary Package
3420 \begin_inset LatexCommand \label{sub:Windows-Install}
3421
3422 \end_inset 
3423
3424
3425 \layout Enumerate
3426
3427 Download the binary package from 
3428 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3429
3430 \end_inset 
3431
3432  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3433  This should unpack to a group of sub-directories.
3434  An example directory structure after unpacking the mingw32 package is:
3435  c:
3436 \backslash 
3437 sdcc
3438 \backslash 
3439 bin for the executables, c:
3440 \backslash 
3441 sdcc
3442 \backslash 
3443 include and c:
3444 \backslash 
3445 sdcc
3446 \backslash 
3447 lib for the include and libraries.
3448 \layout Enumerate
3449
3450 Adjust your environment variable PATH to include the location of the bin
3451  directory or start sdcc using the full path.
3452 \layout Section
3453
3454 Building the Documentation
3455 \layout Standard
3456
3457 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3458  as changing into the doc directory and typing 
3459 \family sans 
3460 \series bold 
3461
3462 \begin_inset Quotes srd
3463 \end_inset 
3464
3465 make
3466 \begin_inset Quotes srd
3467 \end_inset 
3468
3469
3470 \family default 
3471 \series default 
3472  there.
3473  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3474 x).
3475  Using LyX 
3476 \begin_inset LatexCommand \url{www.lyx.org}
3477
3478 \end_inset 
3479
3480  as editor this is straightforward.
3481  Prebuilt documentation in html and pdf format is available from 
3482 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3483
3484 \end_inset 
3485
3486 .
3487 \layout Section
3488
3489 Reading the Documentation
3490 \layout Standard
3491
3492 Currently reading the document in pdf format is recommended, as for unknown
3493  reason the hyperlinks are working there whereas in the html version they
3494  are not
3495 \begin_inset Foot
3496 collapsed false
3497
3498 \layout Standard
3499
3500 If you should know why please drop us a note
3501 \end_inset 
3502
3503 .
3504  You'll find the pdf version at 
3505 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
3506
3507 \end_inset 
3508
3509 .
3510 \newline 
3511 This documentation is in some aspects different from a commercial documentation:
3512  
3513 \layout Itemize
3514
3515 It tries to document SDCC for several processor architectures in one document
3516  (commercially these probably would be separate documents/products).
3517  This document
3518 \begin_inset LatexCommand \index{Status of documentation}
3519
3520 \end_inset 
3521
3522  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3523 on about f.e.
3524  Z80, PIC14, PIC16 and HC08.
3525 \layout Itemize
3526
3527 There are many references pointing away from this documentation.
3528  Don't let this distract you.
3529  If there f.e.
3530  was a reference like 
3531 \begin_inset LatexCommand \url{www.opencores.org}
3532
3533 \end_inset 
3534
3535  together with a statement 
3536 \begin_inset Quotes sld
3537 \end_inset 
3538
3539 some processors which are targetted by SDCC can be implemented in a 
3540 \emph on 
3541 f
3542 \emph default 
3543 ield 
3544 \emph on 
3545 p
3546 \emph default 
3547 rogrammable 
3548 \emph on 
3549 g
3550 \emph default 
3551 ate 
3552 \emph on 
3553 a
3554 \emph default 
3555 rray
3556 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3557
3558 \end_inset 
3559
3560
3561 \begin_inset Quotes srd
3562 \end_inset 
3563
3564  we expect you to have a quick look there and come back.
3565  If you read this you are on the right track.
3566 \layout Itemize
3567
3568 Some sections attribute more space to problems, restrictions and warnings
3569  than to the solution.
3570 \layout Itemize
3571
3572 The installation section and the section about the debugger is intimidating.
3573 \layout Itemize
3574
3575 There are still lots of typos and there are more different writing styles
3576  than pictures.
3577 \layout Section
3578
3579 Testing the SDCC Compiler
3580 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3581
3582 \end_inset 
3583
3584
3585 \layout Standard
3586
3587 The first thing you should do after installing your SDCC compiler is to
3588  see if it runs.
3589  Type 
3590 \family sans 
3591 \series bold 
3592 "sdcc -
3593 \begin_inset ERT
3594 status Collapsed
3595
3596 \layout Standard
3597
3598 \backslash 
3599 /
3600 \end_inset 
3601
3602 -version"
3603 \begin_inset LatexCommand \index{version}
3604
3605 \end_inset 
3606
3607
3608 \family default 
3609 \series default 
3610  at the prompt, and the program should run and tell you the version.
3611  If it doesn't run, or gives a message about not finding sdcc program, then
3612  you need to check over your installation.
3613  Make sure that the sdcc bin directory is in your executable search path
3614  defined by the PATH environment setting (
3615 \series medium 
3616 see 
3617 \series default 
3618 section 
3619 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3620
3621 \end_inset 
3622
3623 \SpecialChar ~
3624
3625 \series medium 
3626 Install trouble-shooting for suggestions
3627 \series default 
3628 ).
3629  Make sure that the sdcc program is in the bin folder, if not perhaps something
3630  did not install correctly.
3631 \newline 
3632
3633 \newline 
3634
3635 \series medium 
3636 SDCC 
3637 \series default 
3638 is commonly installed as described in section 
3639 \begin_inset Quotes sld
3640 \end_inset 
3641
3642 Install and search paths
3643 \begin_inset Quotes srd
3644 \end_inset 
3645
3646 .
3647 \newline 
3648
3649 \newline 
3650
3651 \series medium 
3652 Make sure the compiler works on a very simple example.
3653  Type in the following test.c program using your favorite 
3654 \series default 
3655 ASCII 
3656 \series medium 
3657 editor:
3658 \layout Verse
3659
3660
3661 \family typewriter 
3662 char test;
3663 \newline 
3664
3665 \newline 
3666 void main(void) {
3667 \newline 
3668 \SpecialChar ~
3669 \SpecialChar ~
3670 \SpecialChar ~
3671 \SpecialChar ~
3672 test=0;
3673 \newline 
3674 }
3675 \layout Standard
3676
3677
3678 \series medium 
3679 Compile this using the following command: 
3680 \family sans 
3681 \series bold 
3682 "sdcc -c test.c".
3683
3684 \family default 
3685 \series default 
3686  
3687 \series medium 
3688 If all goes well, the compiler will generate a test.asm and test.rel file.
3689  Congratulations, you've just compiled your first program with SDCC.
3690  We used the -c option to tell SDCC not to link the generated code, just
3691  to keep things simple for this step.
3692 \series default 
3693
3694 \newline 
3695
3696 \newline 
3697
3698 \series medium 
3699 The next step is to try it with the linker.
3700  Type in 
3701 \family sans 
3702 \series bold 
3703 "sdcc test.c
3704 \family default 
3705 \series default 
3706 "
3707 \series medium 
3708 .
3709  If all goes well the compiler will link with the libraries and produce
3710  a test.ihx output file.
3711  If this step fails
3712 \series default 
3713  
3714 \series medium 
3715 (no test.ihx, and the linker generates warnings), then the problem is most
3716  likely that 
3717 \series default 
3718 SDCC
3719 \series medium 
3720  cannot find the 
3721 \series default 
3722 /
3723 \series medium 
3724 usr/local/share/sdcc/lib directory
3725 \series default 
3726  
3727 \series medium 
3728 (see 
3729 \series default 
3730 section 
3731 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3732
3733 \end_inset 
3734
3735 \SpecialChar ~
3736
3737 \series medium 
3738 Install trouble-shooting for suggestions).
3739 \series default 
3740
3741 \newline 
3742
3743 \newline 
3744
3745 \series medium 
3746 The final test is to ensure 
3747 \series default 
3748 SDCC
3749 \series medium 
3750  can use the 
3751 \series default 
3752 standard
3753 \series medium 
3754  header files and libraries.
3755  Edit test.c and change it to the following:
3756 \layout Verse
3757
3758
3759 \family typewriter 
3760 #include <string.h>
3761 \newline 
3762
3763 \newline 
3764 char str1[10];
3765 \newline 
3766
3767 \newline 
3768 void main(void) {
3769 \newline 
3770 \SpecialChar ~
3771 \SpecialChar ~
3772 strcpy(str1, "testing");
3773 \newline 
3774 }
3775 \layout Standard
3776
3777
3778 \series medium 
3779 Compile this by typing 
3780 \family sans 
3781 \series bold 
3782 "sdcc test.c"
3783 \family default 
3784 \series medium 
3785 .
3786  This should generate a test.ihx output file, and it should give no warnings
3787  such as not finding the string.h file.
3788  If it cannot find the string.h file, then the problem is that 
3789 \series default 
3790 SDCC
3791 \series medium 
3792  cannot find the /usr/local/share/sdcc/include directory
3793 \series default 
3794  
3795 \series medium 
3796 (see the 
3797 \series default 
3798 section 
3799 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3800
3801 \end_inset 
3802
3803 \SpecialChar ~
3804
3805 \series medium 
3806 Install trouble-shooting section for suggestions).
3807
3808 \series default 
3809  Use option 
3810 \series bold 
3811 -
3812 \begin_inset ERT
3813 status Collapsed
3814
3815 \layout Standard
3816
3817 \backslash 
3818 /
3819 \end_inset 
3820
3821 -print-search-dirs
3822 \series default 
3823
3824 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3825
3826 \end_inset 
3827
3828  to find exactly where SDCC is looking for the include and lib files.
3829 \layout Section
3830
3831 Install Trouble-shooting
3832 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3833
3834 \end_inset 
3835
3836
3837 \begin_inset LatexCommand \index{Install trouble-shooting}
3838
3839 \end_inset 
3840
3841
3842 \layout Subsection
3843
3844 If SDCC does not build correctly
3845 \layout Standard
3846
3847 A thing to try is starting from scratch by unpacking the .tgz source package
3848  again in an empty directory.
3849  Configure it like:
3850 \newline 
3851
3852 \newline 
3853
3854 \family sans 
3855 \series bold 
3856 ./configure 2>&1 | tee configure.log
3857 \family default 
3858 \series default 
3859
3860 \newline 
3861
3862 \newline 
3863 and build it like:
3864 \newline 
3865
3866 \newline 
3867
3868 \family sans 
3869 \series bold 
3870 make 2>&1 | tee make.log
3871 \family default 
3872 \series default 
3873
3874 \newline 
3875
3876 \newline 
3877 If anything goes wrong, you can review the log files to locate the problem.
3878  Or a relevant part of this can be attached to an email that could be helpful
3879  when requesting help from the mailing list.
3880 \layout Subsection
3881
3882 What the 
3883 \begin_inset Quotes sld
3884 \end_inset 
3885
3886 ./configure
3887 \begin_inset Quotes srd
3888 \end_inset 
3889
3890  does
3891 \layout Standard
3892
3893 The 
3894 \begin_inset Quotes sld
3895 \end_inset 
3896
3897 ./configure
3898 \begin_inset Quotes srd
3899 \end_inset 
3900
3901  command is a script that analyzes your system and performs some configuration
3902  to ensure the source package compiles on your system.
3903  It will take a few minutes to run, and will compile a few tests to determine
3904  what compiler features are installed.
3905 \layout Subsection
3906
3907 What the 
3908 \begin_inset Quotes sld
3909 \end_inset 
3910
3911 make
3912 \begin_inset Quotes srd
3913 \end_inset 
3914
3915  does
3916 \layout Standard
3917
3918 This runs the GNU make tool, which automatically compiles all the source
3919  packages into the final installed binary executables.
3920 \layout Subsection
3921
3922 What the 
3923 \begin_inset Quotes sld
3924 \end_inset 
3925
3926 make install
3927 \begin_inset Quotes erd
3928 \end_inset 
3929
3930  command does.
3931 \layout Standard
3932
3933 This will install the compiler, other executables libraries and include
3934  files into the appropriate directories.
3935  See sections 
3936 \begin_inset LatexCommand \ref{sub:Install-paths}
3937
3938 \end_inset 
3939
3940 ,\SpecialChar ~
3941
3942 \begin_inset LatexCommand \ref{sub:Search-Paths}
3943
3944 \end_inset 
3945
3946 \SpecialChar ~
3947 about install and search paths.
3948 \newline 
3949 On most systems you will need super-user privileges to do this.
3950 \layout Section
3951
3952 Components of SDCC
3953 \layout Standard
3954
3955 SDCC is not just a compiler, but a collection of tools by various developers.
3956  These include linkers, assemblers, simulators and other components.
3957  Here is a summary of some of the components.
3958  Note that the included simulator and assembler have separate documentation
3959  which you can find in the source package in their respective directories.
3960  As SDCC grows to include support for other processors, other packages from
3961  various developers are included and may have their own sets of documentation.
3962 \newline 
3963
3964 \newline 
3965 You might want to look at the files which are installed in <installdir>.
3966  At the time of this writing, we find the following programs for gcc-builds:
3967 \newline 
3968  
3969 \newline 
3970 In <installdir>/bin:
3971 \layout Itemize
3972
3973 sdcc - The compiler.
3974 \layout Itemize
3975
3976 sdcpp - The C preprocessor.
3977 \layout Itemize
3978
3979 asx8051 - The assembler for 8051 type processors.
3980 \layout Itemize
3981
3982 as-z80
3983 \series bold 
3984
3985 \series default 
3986 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3987 \layout Itemize
3988
3989 aslink -The linker for 8051 type processors.
3990 \layout Itemize
3991
3992 link-z80
3993 \series bold 
3994
3995 \series default 
3996 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3997 \layout Itemize
3998
3999 s51 - The ucSim 8051 simulator.
4000 \layout Itemize
4001
4002 sdcdb - The source debugger.
4003 \layout Itemize
4004
4005 packihx - A tool to pack (compress) Intel hex files.
4006 \layout Standard
4007
4008 In <installdir>/share/sdcc/include
4009 \layout Itemize
4010
4011 the include files
4012 \layout Standard
4013
4014 In <installdir>/share/sdcc/lib
4015 \layout Itemize
4016
4017 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4018  relocatables.
4019 \layout Standard
4020
4021 In <installdir>/share/sdcc/doc
4022 \layout Itemize
4023
4024 the documentation
4025 \layout Standard
4026
4027 As development for other processors proceeds, this list will expand to include
4028  executables to support processors like AVR, PIC, etc.
4029 \layout Subsection
4030
4031 sdcc - The Compiler
4032 \layout Standard
4033
4034 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4035  the assembler and linkage editor.
4036 \layout Subsection
4037
4038 sdcpp - The C-Preprocessor
4039 \layout Standard
4040
4041 The preprocessor
4042 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4043
4044 \end_inset 
4045
4046  is a modified version of the GNU preprocessor.
4047  The C preprocessor is used to pull in #include sources, process #ifdef
4048  statements, #defines and so on.
4049 \layout Subsection
4050
4051 as
4052 \emph on 
4053 xxxx
4054 \emph default 
4055 , aslink, link-
4056 \emph on 
4057 xxx
4058 \emph default 
4059  - The Assemblers and Linkage Editors
4060 \layout Standard
4061
4062 This is retargettable assembler & linkage editor, it was developed by Alan
4063  Baldwin.
4064  John Hartman created the version for 8051, and I (Sandeep) have made some
4065  enhancements and bug fixes for it to work properly with SDCC.
4066 \layout Subsection
4067
4068 s51 - The Simulator
4069 \layout Standard
4070
4071 S51
4072 \begin_inset LatexCommand \index{s51}
4073
4074 \end_inset 
4075
4076  is a freeware, opensource simulator developed by Daniel Drotos (
4077 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
4078
4079 \end_inset 
4080
4081 ).
4082  The simulator is built as part of the build process.
4083  For more information visit Daniel's web site at: 
4084 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4085
4086 \end_inset 
4087
4088 .
4089  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4090  XA51 family.
4091 \layout Subsection
4092
4093 sdcdb - Source Level Debugger
4094 \layout Standard
4095
4096 Sdcdb
4097 \begin_inset LatexCommand \index{sdcdb (debugger)}
4098
4099 \end_inset 
4100
4101  is the companion source level debugger.
4102  More about sdcdb in section 
4103 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4104
4105 \end_inset 
4106
4107 .
4108  The current version of the debugger uses Daniel's Simulator S51
4109 \begin_inset LatexCommand \index{s51}
4110
4111 \end_inset 
4112
4113 , but can be easily changed to use other simulators.
4114  
4115 \layout Chapter
4116
4117 Using SDCC
4118 \layout Section
4119
4120 Compiling
4121 \layout Subsection
4122
4123 Single Source File Projects
4124 \layout Standard
4125
4126 For single source file 8051 projects the process is very simple.
4127  Compile your programs with the following command 
4128 \family sans 
4129 \series bold 
4130 "sdcc sourcefile.c".
4131
4132 \family default 
4133 \series default 
4134  This will compile, assemble and link your source file.
4135  Output files are as follows:
4136 \layout Itemize
4137
4138 sourcefile.asm
4139 \begin_inset LatexCommand \index{<file>.asm}
4140
4141 \end_inset 
4142
4143  - Assembler source
4144 \begin_inset LatexCommand \index{Assembler source}
4145
4146 \end_inset 
4147
4148  file created by the compiler
4149 \layout Itemize
4150
4151 sourcefile.lst
4152 \begin_inset LatexCommand \index{<file>.lst}
4153
4154 \end_inset 
4155
4156  - Assembler listing
4157 \begin_inset LatexCommand \index{Assembler listing}
4158
4159 \end_inset 
4160
4161  file created by the Assembler
4162 \layout Itemize
4163
4164 sourcefile.rst
4165 \begin_inset LatexCommand \index{<file>.rst}
4166
4167 \end_inset 
4168
4169  - Assembler listing
4170 \begin_inset LatexCommand \index{Assembler listing}
4171
4172 \end_inset 
4173
4174  file updated with linkedit information, created by linkage editor
4175 \layout Itemize
4176
4177 sourcefile.sym
4178 \begin_inset LatexCommand \index{<file>.sym}
4179
4180 \end_inset 
4181
4182  - symbol listing
4183 \begin_inset LatexCommand \index{Symbol listing}
4184
4185 \end_inset 
4186
4187  for the sourcefile, created by the assembler
4188 \layout Itemize
4189
4190 sourcefile.rel
4191 \begin_inset LatexCommand \index{<file>.rel}
4192
4193 \end_inset 
4194
4195  or sourcefile.o
4196 \begin_inset LatexCommand \index{<file>.o}
4197
4198 \end_inset 
4199
4200  - Object file
4201 \begin_inset LatexCommand \index{Object file}
4202
4203 \end_inset 
4204
4205  created by the assembler, input to Linkage editor
4206 \layout Itemize
4207
4208 sourcefile.map
4209 \begin_inset LatexCommand \index{<file>.map}
4210
4211 \end_inset 
4212
4213  - The memory map
4214 \begin_inset LatexCommand \index{Memory map}
4215
4216 \end_inset 
4217
4218  for the load module, created by the Linker
4219 \layout Itemize
4220
4221 sourcefile.mem
4222 \begin_inset LatexCommand \index{<file>.mem}
4223
4224 \end_inset 
4225
4226  - A file with a summary of the memory usage
4227 \layout Itemize
4228
4229 sourcefile.ihx
4230 \begin_inset LatexCommand \index{<file>.ihx}
4231
4232 \end_inset 
4233
4234  - The load module in Intel hex format
4235 \begin_inset LatexCommand \index{Intel hex format}
4236
4237 \end_inset 
4238
4239  (you can select the Motorola S19 format
4240 \begin_inset LatexCommand \index{Motorola S19 format}
4241
4242 \end_inset 
4243
4244  with -
4245 \begin_inset ERT
4246 status Collapsed
4247
4248 \layout Standard
4249
4250 \backslash 
4251 /
4252 \end_inset 
4253
4254 -out-fmt-s19
4255 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4256
4257 \end_inset 
4258
4259 .
4260  If you need another format you might want to use 
4261 \family sans 
4262 \shape italic 
4263 objdump
4264 \family default 
4265 \shape default 
4266
4267 \begin_inset LatexCommand \index{objdump (tool)}
4268
4269 \end_inset 
4270
4271  or
4272 \family sans 
4273 \shape italic 
4274  srecord
4275 \family default 
4276 \shape default 
4277
4278 \begin_inset LatexCommand \index{srecord (tool)}
4279
4280 \end_inset 
4281
4282 ).
4283  Both formats are documented in the documentation of srecord
4284 \begin_inset LatexCommand \index{srecord (tool)}
4285
4286 \end_inset 
4287
4288
4289 \layout Itemize
4290
4291 sourcefile.adb
4292 \begin_inset LatexCommand \index{<file>.adb}
4293
4294 \end_inset 
4295
4296  - An intermediate file containing debug information needed to create the
4297  .cdb file (with -
4298 \begin_inset ERT
4299 status Open
4300
4301 \layout Standard
4302
4303 \backslash 
4304 /
4305 \end_inset 
4306
4307 -debug
4308 \begin_inset LatexCommand \index{-\/-debug}
4309
4310 \end_inset 
4311
4312
4313 \layout Itemize
4314
4315 sourcefile.cdb
4316 \begin_inset LatexCommand \index{<file>.cdb}
4317
4318 \end_inset 
4319
4320  - An optional file (with -
4321 \begin_inset ERT
4322 status Collapsed
4323
4324 \layout Standard
4325
4326 \backslash 
4327 /
4328 \end_inset 
4329
4330 -debug) containing debug information.
4331  The format is documented in cdbfileformat.pdf.
4332 \layout Itemize
4333
4334 sourcefile.
4335  - (no extension)
4336 \begin_inset LatexCommand \index{<file> (no extension)}
4337
4338 \end_inset 
4339
4340  An optional AOMF or AOMF51
4341 \begin_inset LatexCommand \index{AOMF, AOMF51}
4342
4343 \end_inset 
4344
4345  file containing debug information (generated with option -
4346 \begin_inset ERT
4347 status Collapsed
4348
4349 \layout Standard
4350
4351 \backslash 
4352 /
4353 \end_inset 
4354
4355 -debug).
4356  The (Intel)
4357 \emph on 
4358  a
4359 \emph default 
4360 bsolute 
4361 \emph on 
4362 o
4363 \emph default 
4364 bject 
4365 \emph on 
4366 m
4367 \emph default 
4368 odule 
4369 \emph on 
4370 f
4371 \emph default 
4372 ormat is commonly used by third party tools (debuggers
4373 \begin_inset LatexCommand \index{Debugger}
4374
4375 \end_inset 
4376
4377 , simulators, emulators)
4378 \layout Itemize
4379
4380 sourcefile.dump*
4381 \begin_inset LatexCommand \index{<file>.dump*}
4382
4383 \end_inset 
4384
4385  - Dump file to debug the compiler it self (generated with option -
4386 \begin_inset ERT
4387 status Collapsed
4388
4389 \layout Standard
4390
4391 \backslash 
4392 /
4393 \end_inset 
4394
4395 -dumpall) (see section 
4396 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4397
4398 \end_inset 
4399
4400 \SpecialChar ~
4401  and section 
4402 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4403
4404 \end_inset 
4405
4406 \SpecialChar ~
4407
4408 \begin_inset Quotes sld
4409 \end_inset 
4410
4411 Anatomy of the compiler
4412 \begin_inset Quotes srd
4413 \end_inset 
4414
4415 ).
4416 \layout Subsection
4417
4418 Projects with Multiple Source Files
4419 \layout Standard
4420
4421 SDCC can compile only ONE file at a time.
4422  Let us for example assume that you have a project containing the following
4423  files:
4424 \newline 
4425
4426 \newline 
4427 foo1.c (contains some functions)
4428 \newline 
4429 foo2.c (contains some more functions)
4430 \newline 
4431 foomain.c (contains more functions and the function main)
4432 \newline 
4433
4434 \size footnotesize 
4435
4436 \newline 
4437
4438 \size default 
4439 The first two files will need to be compiled separately with the commands:
4440 \size footnotesize 
4441  
4442 \size default 
4443
4444 \newline 
4445
4446 \newline 
4447
4448 \family sans 
4449 \series bold 
4450 sdcc\SpecialChar ~
4451 -c\SpecialChar ~
4452 foo1.c
4453 \family default 
4454 \series default 
4455 \size footnotesize 
4456
4457 \newline 
4458
4459 \family sans 
4460 \series bold 
4461 \size default 
4462 sdcc\SpecialChar ~
4463 -c\SpecialChar ~
4464 foo2.c
4465 \family default 
4466 \series default 
4467
4468 \newline 
4469
4470 \newline 
4471 Then compile the source file containing the 
4472 \emph on 
4473 main()
4474 \emph default 
4475  function and link
4476 \begin_inset LatexCommand \index{Linker}
4477
4478 \end_inset 
4479
4480  the files together with the following command: 
4481 \newline 
4482
4483 \newline 
4484
4485 \family sans 
4486 \series bold 
4487 sdcc\SpecialChar ~
4488 foomain.c\SpecialChar ~
4489 foo1.rel\SpecialChar ~
4490 foo2.rel
4491 \family default 
4492 \series default 
4493
4494 \begin_inset LatexCommand \index{<file>.rel}
4495
4496 \end_inset 
4497
4498
4499 \newline 
4500
4501 \newline 
4502 Alternatively, 
4503 \emph on 
4504 foomain.c 
4505 \emph default 
4506 can be separately compiled as well: 
4507 \family sans 
4508 \series bold 
4509
4510 \newline 
4511
4512 \newline 
4513 sdcc\SpecialChar ~
4514 -c\SpecialChar ~
4515 foomain.c
4516 \newline 
4517 sdcc foomain.rel foo1.rel foo2.rel
4518 \newline 
4519
4520 \newline 
4521
4522 \family default 
4523 \series default 
4524 The file containing the 
4525 \emph on 
4526 main()
4527 \emph default 
4528  function
4529 \emph on 
4530  
4531 \emph default 
4532 \noun on 
4533 must
4534 \noun default 
4535  be the 
4536 \noun on 
4537 first
4538 \noun default 
4539  file specified in the command line, since the linkage editor processes
4540  file in the order they are presented to it.
4541  The linker is invoked from SDCC using a script file with extension .lnk
4542 \begin_inset LatexCommand \index{<file>.lnk}
4543
4544 \end_inset 
4545
4546 .
4547  You can view this file to troubleshoot linking problems such as those arising
4548  from missing libraries.
4549 \layout Subsection
4550
4551 Projects with Additional Libraries
4552 \begin_inset LatexCommand \index{Libraries}
4553
4554 \end_inset 
4555
4556
4557 \layout Standard
4558
4559 Some reusable routines may be compiled into a library, see the documentation
4560  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4561  for how to create a 
4562 \emph on 
4563 .lib
4564 \begin_inset LatexCommand \index{<file>.lib}
4565
4566 \end_inset 
4567
4568
4569 \emph default 
4570  library file.
4571  Libraries created in this manner can be included in the command line.
4572  Make sure you include the -L <library-path> option to tell the linker where
4573  to look for these files if they are not in the current directory.
4574  Here is an example, assuming you have the source file 
4575 \emph on 
4576 foomain.c
4577 \emph default 
4578  and a library
4579 \emph on 
4580  foolib.lib
4581 \emph default 
4582  in the directory 
4583 \emph on 
4584 mylib
4585 \emph default 
4586  (if that is not the same as your current project):
4587 \newline 
4588
4589 \newline 
4590
4591 \family sans 
4592 \series bold 
4593 sdcc foomain.c foolib.lib -L mylib
4594 \newline 
4595
4596 \newline 
4597
4598 \family default 
4599 \series default 
4600 Note here that
4601 \emph on 
4602  mylib
4603 \emph default 
4604  must be an absolute path name.
4605 \newline 
4606
4607 \newline 
4608 The most efficient way to use libraries is to keep separate modules in separate
4609  source files.
4610  The lib file now should name all the modules.rel
4611 \begin_inset LatexCommand \index{<file>.rel}
4612
4613 \end_inset 
4614
4615  files.
4616  For an example see the standard library file 
4617 \emph on 
4618 libsdcc.lib
4619 \emph default 
4620  in the directory <installdir>/share/lib/small.
4621 \layout Subsection
4622
4623 Using sdcclib to Create and Manage Libraries
4624 \begin_inset LatexCommand \index{sdcclib}
4625
4626 \end_inset 
4627
4628
4629 \layout Standard
4630
4631 Alternatively, instead of having a .rel file for each entry on the library
4632  file as described in the preceding section, sdcclib can be used to embed
4633  all the modules belonging to such library in the library file itself.
4634  This results in a larger library file, but it greatly reduces the number
4635  of disk files accessed by the linker.
4636   Additionally, the packed library file contains an index of all include
4637  modules and symbols that significantly speeds up the linking process.
4638  To display a list of options supported by sdcclib type:
4639 \newline 
4640
4641 \layout Standard
4642
4643
4644 \family sans 
4645 \series bold 
4646 sdcclib -?
4647 \begin_inset LatexCommand \index{sdcclib}
4648
4649 \end_inset 
4650
4651
4652 \newline 
4653
4654 \newline 
4655
4656 \family default 
4657 \series default 
4658 To create a new library file, start by compiling all the required modules.
4659  For example:
4660 \newline 
4661
4662 \layout Standard
4663
4664
4665 \family sans 
4666 \series bold 
4667 sdcc -c _divsint.c
4668 \layout Standard
4669
4670
4671 \family sans 
4672 \series bold 
4673 sdcc -c _divuint.c
4674 \layout Standard
4675
4676
4677 \family sans 
4678 \series bold 
4679 sdcc -c _modsint.c
4680 \layout Standard
4681
4682
4683 \family sans 
4684 \series bold 
4685 sdcc -c _moduint.c
4686 \layout Standard
4687
4688
4689 \family sans 
4690 \series bold 
4691 sdcc -c _mulint.c
4692 \newline 
4693
4694 \layout Standard
4695
4696 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4697  and _mulint.rel.
4698  The next step is to add the .rel files to the library file:
4699 \newline 
4700
4701 \layout Standard
4702
4703
4704 \family sans 
4705 \series bold 
4706 sdcclib libint.lib _divsint.rel
4707 \family default 
4708
4709 \begin_inset LatexCommand \index{sdcclib}
4710
4711 \end_inset 
4712
4713
4714 \layout Standard
4715
4716
4717 \family sans 
4718 \series bold 
4719 sdcclib libint.lib _divuint.rel
4720 \layout Standard
4721
4722
4723 \family sans 
4724 \series bold 
4725 sdcclib libint.lib _modsint.rel
4726 \layout Standard
4727
4728
4729 \family sans 
4730 \series bold 
4731 sdcclib libint.lib _moduint.rel
4732 \layout Standard
4733
4734
4735 \family sans 
4736 \series bold 
4737 sdcclib libint.lib _mulint.rel
4738 \series default 
4739
4740 \newline 
4741
4742 \layout Standard
4743
4744 If the file already exists in the library, it will be replaced.
4745  To see what modules and symbols are included in the library, options -s
4746  and -m are available.
4747  For example:
4748 \newline 
4749
4750 \newline 
4751
4752 \family sans 
4753 \series bold 
4754 sdcclib -s libint.lib
4755 \family default 
4756
4757 \begin_inset LatexCommand \index{sdcclib}
4758
4759 \end_inset 
4760
4761
4762 \newline 
4763
4764 \family typewriter 
4765 \series default 
4766 _divsint.rel:
4767 \layout Standard
4768
4769
4770 \family typewriter 
4771 __divsint_a_1_1
4772 \layout Standard
4773
4774
4775 \family typewriter 
4776 __divsint_PARM_2
4777 \layout Standard
4778
4779
4780 \family typewriter 
4781 __divsint
4782 \newline 
4783 _divuint.rel:
4784 \layout Standard
4785
4786
4787 \family typewriter 
4788 __divuint_a_1_1
4789 \layout Standard
4790
4791
4792 \family typewriter 
4793 __divuint_PARM_2
4794 \layout Standard
4795
4796
4797 \family typewriter 
4798 __divuint_reste_1_1
4799 \layout Standard
4800
4801
4802 \family typewriter 
4803 __divuint_count_1_1
4804 \layout Standard
4805
4806
4807 \family typewriter 
4808 __divuint
4809 \newline 
4810 _modsint.rel:
4811 \layout Standard
4812
4813
4814 \family typewriter 
4815 __modsint_a_1_1
4816 \layout Standard
4817
4818
4819 \family typewriter 
4820 __modsint_PARM_2
4821 \layout Standard
4822
4823
4824 \family typewriter 
4825 __modsint
4826 \newline 
4827 _moduint.rel:
4828 \layout Standard
4829
4830
4831 \family typewriter 
4832 __moduint_a_1_1
4833 \layout Standard
4834
4835
4836 \family typewriter 
4837 __moduint_PARM_2
4838 \layout Standard
4839
4840
4841 \family typewriter 
4842 __moduint_count_1_1
4843 \layout Standard
4844
4845
4846 \family typewriter 
4847 __moduint
4848 \newline 
4849 _mulint.rel:
4850 \layout Standard
4851
4852
4853 \family typewriter 
4854 __mulint_PARM_2
4855 \layout Standard
4856
4857
4858 \family typewriter 
4859 __mulint
4860 \family default 
4861 \series bold 
4862
4863 \newline 
4864
4865 \layout Standard
4866
4867 If the source files are compiled using -
4868 \begin_inset ERT
4869 status Open
4870
4871 \layout Standard
4872
4873 \backslash 
4874 /
4875 \end_inset 
4876
4877 -debug
4878 \begin_inset LatexCommand \index{-\/-debug}
4879
4880 \end_inset 
4881
4882 , the corresponding debug information file .adb will be include in the library
4883  file as well.
4884  The library files created with sdcclib are plain text files, so they can
4885  be viewed with a text editor.
4886  It is not recomended to modify a library file created with sdcclib using
4887  a text editor, as there are file indexes numbers located accross the file
4888  used by the linker to quickly locate the required module to link.
4889  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
4890  it can be safely deleted, since all the information required for linking
4891  is embedded in the library file itself.
4892  Library files created using sdcclib are used as described in the preceding
4893  sections.
4894 \layout Section
4895
4896 Command Line Options
4897 \begin_inset LatexCommand \index{Command Line Options}
4898
4899 \end_inset 
4900
4901
4902 \layout Subsection
4903
4904 Processor Selection Options
4905 \begin_inset LatexCommand \index{Options processor selection}
4906
4907 \end_inset 
4908
4909
4910 \begin_inset LatexCommand \index{Processor selection options}
4911
4912 \end_inset 
4913
4914
4915 \layout List
4916 \labelwidthstring 00.00.0000
4917
4918
4919 \series bold 
4920 -mmcs51
4921 \begin_inset LatexCommand \index{-mmcs51}
4922
4923 \end_inset 
4924
4925
4926 \series default 
4927  Generate code for the Intel MCS51
4928 \begin_inset LatexCommand \index{MCS51}
4929
4930 \end_inset 
4931
4932  family of processors.
4933  This is the default processor target.
4934 \layout List
4935 \labelwidthstring 00.00.0000
4936
4937
4938 \series bold 
4939 -mds390
4940 \begin_inset LatexCommand \index{-mds390}
4941
4942 \end_inset 
4943
4944
4945 \series default 
4946  Generate code for the Dallas DS80C390
4947 \begin_inset LatexCommand \index{DS80C390}
4948
4949 \end_inset 
4950
4951  processor.
4952 \layout List
4953 \labelwidthstring 00.00.0000
4954
4955
4956 \series bold 
4957 -mds400
4958 \begin_inset LatexCommand \index{-mds400}
4959
4960 \end_inset 
4961
4962
4963 \series default 
4964  Generate code for the Dallas DS80C400
4965 \begin_inset LatexCommand \index{DS80C400}
4966
4967 \end_inset 
4968
4969  processor.
4970 \layout List
4971 \labelwidthstring 00.00.0000
4972
4973
4974 \series bold 
4975 -mhc08
4976 \begin_inset LatexCommand \index{-mhc08}
4977
4978 \end_inset 
4979
4980
4981 \series default 
4982  Generate code for the Motorola HC08
4983 \begin_inset LatexCommand \index{HC08}
4984
4985 \end_inset 
4986
4987  family of processors (added Oct 2003).
4988 \layout List
4989 \labelwidthstring 00.00.0000
4990
4991
4992 \series bold 
4993 -mz80
4994 \begin_inset LatexCommand \index{-mz80}
4995
4996 \end_inset 
4997
4998
4999 \series default 
5000  Generate code for the Zilog Z80
5001 \begin_inset LatexCommand \index{Z80}
5002
5003 \end_inset 
5004
5005  family of processors.
5006 \layout List
5007 \labelwidthstring 00.00.0000
5008
5009
5010 \series bold 
5011 -mgbz80
5012 \begin_inset LatexCommand \index{-mgbz80}
5013
5014 \end_inset 
5015
5016
5017 \series default 
5018  Generate code for the GameBoy Z80
5019 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5020
5021 \end_inset 
5022
5023  processor (Not actively maintained).
5024 \layout List
5025 \labelwidthstring 00.00.0000
5026
5027
5028 \series bold 
5029 -mavr
5030 \begin_inset LatexCommand \index{-mavr}
5031
5032 \end_inset 
5033
5034
5035 \series default 
5036  Generate code for the Atmel AVR
5037 \begin_inset LatexCommand \index{AVR}
5038
5039 \end_inset 
5040
5041  processor (In development, not complete).
5042  AVR users should probably have a look at avr-gcc 
5043 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
5044
5045 \end_inset 
5046
5047  or winavr 
5048 \begin_inset LatexCommand \url{http://winavr.sourceforge.net}
5049
5050 \end_inset 
5051
5052 .
5053 \layout Comment
5054
5055 I think it is fair to direct users there for now.
5056  Open source is also about avoiding unnecessary work .
5057  But I didn't find the 'official' link.
5058 \layout List
5059 \labelwidthstring 00.00.0000
5060
5061
5062 \series bold 
5063 -mpic14
5064 \begin_inset LatexCommand \index{-mpic14}
5065
5066 \end_inset 
5067
5068
5069 \series default 
5070  Generate code for the Microchip PIC 14
5071 \begin_inset LatexCommand \index{PIC14}
5072
5073 \end_inset 
5074
5075 -bit processors (p16f84 and variants.
5076  In development, not complete).
5077 \layout Comment
5078
5079 p16f627 p16f628 p16f84 p16f873 p16f877?
5080 \layout List
5081 \labelwidthstring 00.00.0000
5082
5083
5084 \series bold 
5085 -mpic16
5086 \begin_inset LatexCommand \index{-mpic16}
5087
5088 \end_inset 
5089
5090
5091 \series default 
5092  Generate code for the Microchip PIC 16
5093 \begin_inset LatexCommand \index{PIC16}
5094
5095 \end_inset 
5096
5097 -bit processors (p18f452 and variants.
5098  In development, not complete).
5099 \layout List
5100 \labelwidthstring 00.00.0000
5101
5102
5103 \series bold 
5104 -mtlcs900h
5105 \series default 
5106  Generate code for the Toshiba TLCS-900H
5107 \begin_inset LatexCommand \index{TLCS-900H}
5108
5109 \end_inset 
5110
5111  processor (Not maintained, not complete).
5112 \layout List
5113 \labelwidthstring 00.00.0000
5114
5115
5116 \series bold 
5117 -mxa51
5118 \begin_inset LatexCommand \index{-mxa51}
5119
5120 \end_inset 
5121
5122
5123 \series default 
5124  Generate code for the Phillips XA51
5125 \begin_inset LatexCommand \index{XA51}
5126
5127 \end_inset 
5128
5129  processor (Not maintained, not complete).
5130 \layout Subsection
5131
5132 Preprocessor Options
5133 \begin_inset LatexCommand \index{Options preprocessor}
5134
5135 \end_inset 
5136
5137
5138 \begin_inset LatexCommand \index{Preprocessor options}
5139
5140 \end_inset 
5141
5142
5143 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5144
5145 \end_inset 
5146
5147
5148 \layout List
5149 \labelwidthstring 00.00.0000
5150
5151
5152 \series bold 
5153 -I<path>
5154 \begin_inset LatexCommand \index{-I<path>}
5155
5156 \end_inset 
5157
5158
5159 \series default 
5160  The additional location where the pre processor will look for <..h> or 
5161 \begin_inset Quotes eld
5162 \end_inset 
5163
5164 ..h
5165 \begin_inset Quotes erd
5166 \end_inset 
5167
5168  files.
5169 \layout List
5170 \labelwidthstring 00.00.0000
5171
5172
5173 \series bold 
5174 -D<macro[=value]>
5175 \begin_inset LatexCommand \index{-D<macro[=value]>}
5176
5177 \end_inset 
5178
5179
5180 \series default 
5181  Command line definition of macros.
5182  Passed to the preprocessor.
5183 \layout List
5184 \labelwidthstring 00.00.0000
5185
5186
5187 \series bold 
5188 -M
5189 \begin_inset LatexCommand \index{-M}
5190
5191 \end_inset 
5192
5193
5194 \series default 
5195  Tell the preprocessor to output a rule suitable for make describing the
5196  dependencies of each object file.
5197  For each source file, the preprocessor outputs one make-rule whose target
5198  is the object file name for that source file and whose dependencies are
5199  all the files `#include'd in it.
5200  This rule may be a single line or may be continued with `
5201 \backslash 
5202 '-newline if it is long.
5203  The list of rules is printed on standard output instead of the preprocessed
5204  C program.
5205  `-M' implies `-E
5206 \begin_inset LatexCommand \index{-E}
5207
5208 \end_inset 
5209
5210 '.
5211 \layout List
5212 \labelwidthstring 00.00.0000
5213
5214
5215 \series bold 
5216 -C
5217 \begin_inset LatexCommand \index{-C}
5218
5219 \end_inset 
5220
5221
5222 \series default 
5223  Tell the preprocessor not to discard comments.
5224  Used with the `-E' option.
5225 \layout List
5226 \labelwidthstring 00.00.0000
5227
5228
5229 \series bold 
5230 -MM
5231 \begin_inset LatexCommand \index{-MM}
5232
5233 \end_inset 
5234
5235
5236 \size large 
5237 \bar under 
5238  
5239 \series default 
5240 \size default 
5241 \bar default 
5242 Like `-M' but the output mentions only the user header files included with
5243  `#include 
5244 \begin_inset Quotes eld
5245 \end_inset 
5246
5247 file"'.
5248  System header files included with `#include <file>' are omitted.
5249 \layout List
5250 \labelwidthstring 00.00.0000
5251
5252
5253 \series bold 
5254 -Aquestion(answer)
5255 \begin_inset LatexCommand \index{-Aquestion(answer)}
5256
5257 \end_inset 
5258
5259
5260 \series default 
5261  Assert the answer answer for question, in case it is tested with a preprocessor
5262  conditional such as `#if #question(answer)'.
5263  `-A-' disables the standard assertions that normally describe the target
5264  machine.
5265 \layout List
5266 \labelwidthstring 00.00.0000
5267
5268
5269 \series bold 
5270 -Umacro
5271 \begin_inset LatexCommand \index{-Umacro}
5272
5273 \end_inset 
5274
5275
5276 \series default 
5277  Undefine macro macro.
5278  `-U' options are evaluated after all `-D' options, but before any `-include'
5279  and `-imacros' options.
5280 \layout List
5281 \labelwidthstring 00.00.0000
5282
5283
5284 \series bold 
5285 -dM
5286 \begin_inset LatexCommand \index{-dM}
5287
5288 \end_inset 
5289
5290
5291 \series default 
5292  Tell the preprocessor to output only a list of the macro definitions that
5293  are in effect at the end of preprocessing.
5294  Used with the `-E' option.
5295 \layout List
5296 \labelwidthstring 00.00.0000
5297
5298
5299 \series bold 
5300 -dD
5301 \begin_inset LatexCommand \index{-dD}
5302
5303 \end_inset 
5304
5305
5306 \series default 
5307  Tell the preprocessor to pass all macro definitions into the output, in
5308  their proper sequence in the rest of the output.
5309 \layout List
5310 \labelwidthstring 00.00.0000
5311
5312
5313 \series bold 
5314 -dN
5315 \begin_inset LatexCommand \index{-dN}
5316
5317 \end_inset 
5318
5319
5320 \size large 
5321 \bar under 
5322  
5323 \series default 
5324 \size default 
5325 \bar default 
5326 Like `-dD' except that the macro arguments and contents are omitted.
5327  Only `#define name' is included in the output.
5328 \layout List
5329 \labelwidthstring 00.00.0000
5330
5331
5332 \series bold 
5333 -Wp\SpecialChar ~
5334 preprocessorOption[,preprocessorOption]
5335 \series default 
5336
5337 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5338
5339 \end_inset 
5340
5341 ...
5342  Pass the preprocessorOption to the preprocessor 
5343 \family typewriter 
5344 sdcpp
5345 \family default 
5346
5347 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5348
5349 \end_inset 
5350
5351 .
5352  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5353  Collection (gcc), if you need more dedicated options please refer to the
5354  documentation at 
5355 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5356
5357 \end_inset 
5358
5359 .
5360 \layout Subsection
5361
5362 Linker Options
5363 \begin_inset LatexCommand \index{Options linker}
5364
5365 \end_inset 
5366
5367
5368 \begin_inset LatexCommand \index{Linker options}
5369
5370 \end_inset 
5371
5372
5373 \layout List
5374 \labelwidthstring 00.00.0000
5375
5376
5377 \series bold 
5378 -L\SpecialChar ~
5379 -
5380 \series default 
5381
5382 \begin_inset ERT
5383 status Collapsed
5384
5385 \layout Standard
5386
5387 \backslash 
5388 /
5389 \end_inset 
5390
5391
5392 \series bold 
5393 -lib-path
5394 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5395
5396 \end_inset 
5397
5398
5399 \begin_inset LatexCommand \index{-L -\/-lib-path}
5400
5401 \end_inset 
5402
5403
5404 \series default 
5405 \SpecialChar ~
5406 <absolute path to additional libraries> This option is passed to the linkage
5407  editor's additional libraries
5408 \begin_inset LatexCommand \index{Libraries}
5409
5410 \end_inset 
5411
5412  search path.
5413  The path name must be absolute.
5414  Additional library files may be specified in the command line.
5415  See section Compiling programs for more details.
5416 \layout List
5417 \labelwidthstring 00.00.0000
5418
5419
5420 \series bold 
5421 -
5422 \begin_inset ERT
5423 status Collapsed
5424
5425 \layout Standard
5426
5427 \backslash 
5428 /
5429 \end_inset 
5430
5431 -xram-loc
5432 \series default 
5433
5434 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5435
5436 \end_inset 
5437
5438 \SpecialChar ~
5439 <Value> The start location of the external ram
5440 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5441
5442 \end_inset 
5443
5444 , default value is 0.
5445  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5446 \begin_inset ERT
5447 status Collapsed
5448
5449 \layout Standard
5450
5451 \backslash 
5452 /
5453 \end_inset 
5454
5455 -xram-loc 0x8000 or -
5456 \begin_inset ERT
5457 status Collapsed
5458
5459 \layout Standard
5460
5461 \backslash 
5462 /
5463 \end_inset 
5464
5465 -xram-loc 32768.
5466 \layout List
5467 \labelwidthstring 00.00.0000
5468
5469
5470 \series bold 
5471 -
5472 \begin_inset ERT
5473 status Collapsed
5474
5475 \layout Standard
5476
5477 \backslash 
5478 /
5479 \end_inset 
5480
5481 -code-loc
5482 \series default 
5483
5484 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5485
5486 \end_inset 
5487
5488 \SpecialChar ~
5489 <Value> The start location of the code
5490 \begin_inset LatexCommand \index{code}
5491
5492 \end_inset 
5493
5494  segment, default value 0.
5495  Note when this option is used the interrupt vector table is also relocated
5496  to the given address.
5497  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5498 \begin_inset ERT
5499 status Collapsed
5500
5501 \layout Standard
5502
5503 \backslash 
5504 /
5505 \end_inset 
5506
5507 -code-loc 0x8000 or -
5508 \begin_inset ERT
5509 status Collapsed
5510
5511 \layout Standard
5512
5513 \backslash 
5514 /
5515 \end_inset 
5516
5517 -code-loc 32768.
5518 \layout List
5519 \labelwidthstring 00.00.0000
5520
5521
5522 \series bold 
5523 -
5524 \begin_inset ERT
5525 status Collapsed
5526
5527 \layout Standard
5528
5529 \backslash 
5530 /
5531 \end_inset 
5532
5533 -stack-loc
5534 \series default 
5535
5536 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5537
5538 \end_inset 
5539
5540 \SpecialChar ~
5541 <Value> By default the stack
5542 \begin_inset LatexCommand \index{stack}
5543
5544 \end_inset 
5545
5546  is placed after the data segment.
5547  Using this option the stack can be placed anywhere in the internal memory
5548  space of the 8051.
5549  The value entered can be in Hexadecimal or Decimal format, e.g.
5550  -
5551 \begin_inset ERT
5552 status Collapsed
5553
5554 \layout Standard
5555
5556 \backslash 
5557 /
5558 \end_inset 
5559
5560 -stack-loc 0x20 or -
5561 \begin_inset ERT
5562 status Collapsed
5563
5564 \layout Standard
5565
5566 \backslash 
5567 /
5568 \end_inset 
5569
5570 -stack-loc 32.
5571  Since the sp register is incremented before a push or call, the initial
5572  sp will be set to one byte prior the provided value.
5573  The provided value should not overlap any other memory areas such as used
5574  register banks or the data segment and with enough space for the current
5575  application.
5576 \layout List
5577 \labelwidthstring 00.00.0000
5578
5579
5580 \series bold 
5581 -
5582 \begin_inset ERT
5583 status Collapsed
5584
5585 \layout Standard
5586
5587 \backslash 
5588 /
5589 \end_inset 
5590
5591 -data-loc
5592 \series default 
5593
5594 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5595
5596 \end_inset 
5597
5598 \SpecialChar ~
5599 <Value> The start location of the internal ram data
5600 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5601
5602 \end_inset 
5603
5604  segment.
5605  The value entered can be in Hexadecimal or Decimal format, eg.
5606  -
5607 \begin_inset ERT
5608 status Collapsed
5609
5610 \layout Standard
5611
5612 \backslash 
5613 /
5614 \end_inset 
5615
5616 -data-loc 0x20 or -
5617 \begin_inset ERT
5618 status Collapsed
5619
5620 \layout Standard
5621
5622 \backslash 
5623 /
5624 \end_inset 
5625
5626 -data-loc 32.
5627  (By default, the start location of the internal ram data segment  is set
5628  as low as possible in memory, taking into account the used register banks
5629  and the bit segment at address 0x20.
5630  For example if register banks 0 and 1 are used without bit variables, the
5631  data segment will be set, if -
5632 \begin_inset ERT
5633 status Collapsed
5634
5635 \layout Standard
5636
5637 \backslash 
5638 /
5639 \end_inset 
5640
5641 -data-loc is not used, to location 0x10.)
5642 \layout List
5643 \labelwidthstring 00.00.0000
5644
5645
5646 \series bold 
5647 -
5648 \begin_inset ERT
5649 status Collapsed
5650
5651 \layout Standard
5652
5653 \backslash 
5654 /
5655 \end_inset 
5656
5657 -idata-loc
5658 \series default 
5659
5660 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5661
5662 \end_inset 
5663
5664 \SpecialChar ~
5665 <Value> The start location of the indirectly addressable internal ram
5666 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5667
5668 \end_inset 
5669
5670  of the 8051, default value is 0x80.
5671  The value entered can be in Hexadecimal or Decimal format, eg.
5672  -
5673 \begin_inset ERT
5674 status Collapsed
5675
5676 \layout Standard
5677
5678 \backslash 
5679 /
5680 \end_inset 
5681
5682 -idata-loc 0x88 or -
5683 \begin_inset ERT
5684 status Collapsed
5685
5686 \layout Standard
5687
5688 \backslash 
5689 /
5690 \end_inset 
5691
5692 -idata-loc 136.
5693 \layout List
5694 \labelwidthstring 00.00.0000
5695
5696
5697 \series bold 
5698 -
5699 \begin_inset ERT
5700 status Collapsed
5701
5702 \layout Standard
5703
5704 \backslash 
5705 /
5706 \end_inset 
5707
5708 -bit-loc
5709 \series default 
5710 \SpecialChar ~
5711 <Value> The start location of the bit
5712 \begin_inset LatexCommand \index{bit}
5713
5714 \end_inset 
5715
5716  addressable internal ram of the 8051.
5717  This is 
5718 \emph on 
5719 not
5720 \emph default 
5721  implemented yet.
5722  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5723 -bBSEG=<Value>.
5724 \layout List
5725 \labelwidthstring 00.00.0000
5726
5727
5728 \series bold 
5729 -
5730 \begin_inset ERT
5731 status Collapsed
5732
5733 \layout Standard
5734
5735 \backslash 
5736 /
5737 \end_inset 
5738
5739 -out-fmt-ihx
5740 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5741
5742 \end_inset 
5743
5744
5745 \bar under 
5746  
5747 \series default 
5748 \bar default 
5749 The linker output (final object code) is in Intel Hex format.
5750 \begin_inset LatexCommand \index{Intel hex format}
5751
5752 \end_inset 
5753
5754  This is the default option.
5755  The format itself is documented in the documentation of srecord
5756 \begin_inset LatexCommand \index{srecord (tool)}
5757
5758 \end_inset 
5759
5760 .
5761 \layout List
5762 \labelwidthstring 00.00.0000
5763
5764
5765 \series bold 
5766 -
5767 \begin_inset ERT
5768 status Collapsed
5769
5770 \layout Standard
5771
5772 \backslash 
5773 /
5774 \end_inset 
5775
5776 -out-fmt-s19
5777 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5778
5779 \end_inset 
5780
5781
5782 \bar under 
5783  
5784 \series default 
5785 \bar default 
5786 The linker output (final object code) is in Motorola S19 format
5787 \begin_inset LatexCommand \index{Motorola S19 format}
5788
5789 \end_inset 
5790
5791 .
5792  The format itself is documented in the documentation of srecord.
5793 \layout List
5794 \labelwidthstring 00.00.0000
5795
5796
5797 \series bold 
5798 -Wl\SpecialChar ~
5799 linkOption[,linkOption]
5800 \series default 
5801
5802 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5803
5804 \end_inset 
5805
5806 ...
5807  Pass the linkOption to the linker.
5808  See file sdcc/as/doc/asxhtm.html for more on linker options.
5809 \layout Subsection
5810
5811 MCS51 Options
5812 \begin_inset LatexCommand \index{Options MCS51}
5813
5814 \end_inset 
5815
5816
5817 \begin_inset LatexCommand \index{MCS51 options}
5818
5819 \end_inset 
5820
5821
5822 \layout List
5823 \labelwidthstring 00.00.0000
5824
5825
5826 \series bold 
5827 -
5828 \begin_inset ERT
5829 status Collapsed
5830
5831 \layout Standard
5832
5833 \backslash 
5834 /
5835 \end_inset 
5836
5837 -model-small
5838 \begin_inset LatexCommand \index{-\/-model-small}
5839
5840 \end_inset 
5841
5842
5843 \series default 
5844 \size large 
5845 \emph on 
5846  
5847 \size default 
5848 \emph default 
5849 Generate code for Small Model programs, see section Memory Models for more
5850  details.
5851  This is the default model.
5852 \layout List
5853 \labelwidthstring 00.00.0000
5854
5855
5856 \series bold 
5857 -
5858 \begin_inset ERT
5859 status Collapsed
5860
5861 \layout Standard
5862
5863 \backslash 
5864 /
5865 \end_inset 
5866
5867 -model-large
5868 \begin_inset LatexCommand \index{-\/-model-large}
5869
5870 \end_inset 
5871
5872
5873 \series default 
5874  Generate code for Large model programs, see section Memory Models for more
5875  details.
5876  If this option is used all source files in the project have to be compiled
5877  with this option.
5878 \layout List
5879 \labelwidthstring 00.00.0000
5880
5881
5882 \series bold 
5883 -
5884 \begin_inset ERT
5885 status Collapsed
5886
5887 \layout Standard
5888
5889 \backslash 
5890 /
5891 \end_inset 
5892
5893 -xstack
5894 \begin_inset LatexCommand \index{-\/-xstack}
5895
5896 \end_inset 
5897
5898
5899 \series default 
5900  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5901  variables and passing parameters.
5902  See section 
5903 \begin_inset LatexCommand \ref{sub:External-Stack}
5904
5905 \end_inset 
5906
5907 \SpecialChar ~
5908  External Stack for more details.
5909 \layout List
5910 \labelwidthstring 00.00.0000
5911
5912
5913 \series bold 
5914 -
5915 \begin_inset ERT
5916 status Collapsed
5917
5918 \layout Standard
5919
5920 \backslash 
5921 /
5922 \end_inset 
5923
5924 -iram-size
5925 \series default 
5926 \SpecialChar ~
5927 <Value>
5928 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5929
5930 \end_inset 
5931
5932  Causes the linker to check if the internal ram usage is within limits of
5933  the given value.
5934 \layout List
5935 \labelwidthstring 00.00.0000
5936
5937
5938 \series bold 
5939 -
5940 \begin_inset ERT
5941 status Collapsed
5942
5943 \layout Standard
5944
5945 \backslash 
5946 /
5947 \end_inset 
5948
5949 -xram-size
5950 \series default 
5951 \SpecialChar ~
5952 <Value>
5953 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5954
5955 \end_inset 
5956
5957  Causes the linker to check if the external ram usage is within limits of
5958  the given value.
5959 \layout List
5960 \labelwidthstring 00.00.0000
5961
5962
5963 \series bold 
5964 -
5965 \begin_inset ERT
5966 status Collapsed
5967
5968 \layout Standard
5969
5970 \backslash 
5971 /
5972 \end_inset 
5973
5974 -code-size
5975 \series default 
5976 \SpecialChar ~
5977 <Value>
5978 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5979
5980 \end_inset 
5981
5982  Causes the linker to check if the code memory usage is within limits of
5983  the given value.
5984 \layout List
5985 \labelwidthstring 00.00.0000
5986
5987
5988 \series bold 
5989 -
5990 \begin_inset ERT
5991 status Collapsed
5992
5993 \layout Standard
5994
5995 \backslash 
5996 /
5997 \end_inset 
5998
5999 -stack-size
6000 \series default 
6001 \SpecialChar ~
6002 <Value>
6003 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
6004
6005 \end_inset 
6006
6007  Causes the linker to check if there is at minimum <Value> bytes for stack.
6008 \layout List
6009 \labelwidthstring 00.00.0000
6010
6011
6012 \series bold 
6013 -
6014 \begin_inset ERT
6015 status Collapsed
6016
6017 \layout Standard
6018
6019 \backslash 
6020 /
6021 \end_inset 
6022
6023 -pack-iram
6024 \series default 
6025 \SpecialChar ~
6026
6027 \begin_inset LatexCommand \index{-\/-pack-iram}
6028
6029 \end_inset 
6030
6031  Causes the linker use unused register banks for data variables or stack.
6032 \layout Subsection
6033
6034 DS390 / DS400 Options
6035 \begin_inset LatexCommand \index{Options DS390}
6036
6037 \end_inset 
6038
6039
6040 \begin_inset LatexCommand \index{DS390 options}
6041
6042 \end_inset 
6043
6044
6045 \layout List
6046 \labelwidthstring 00.00.0000
6047
6048
6049 \series bold 
6050 -
6051 \begin_inset ERT
6052 status Collapsed
6053
6054 \layout Standard
6055
6056 \backslash 
6057 /
6058 \end_inset 
6059
6060 -model-flat24
6061 \series default 
6062
6063 \begin_inset LatexCommand \index{-\/-model-flat24}
6064
6065 \end_inset 
6066
6067
6068 \size large 
6069 \emph on 
6070  
6071 \size default 
6072 \emph default 
6073 Generate 24-bit flat mode code.
6074  This is the one and only that the ds390 code generator supports right now
6075  and is default when using 
6076 \emph on 
6077 -mds390
6078 \emph default 
6079 .
6080  See section Memory Models for more details.
6081 \layout List
6082 \labelwidthstring 00.00.0000
6083
6084
6085 \series bold 
6086 -
6087 \begin_inset ERT
6088 status Collapsed
6089
6090 \layout Standard
6091
6092 \backslash 
6093 /
6094 \end_inset 
6095
6096 -protect-sp-update
6097 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6098
6099 \end_inset 
6100
6101
6102 \series default 
6103  disable interrupts during ESP:SP updates.
6104 \layout List
6105 \labelwidthstring 00.00.0000
6106
6107
6108 \series bold 
6109 -
6110 \begin_inset ERT
6111 status Collapsed
6112
6113 \layout Standard
6114
6115 \backslash 
6116 /
6117 \end_inset 
6118
6119 -stack-10bit
6120 \series default 
6121
6122 \begin_inset LatexCommand \index{-\/-stack-10bit}
6123
6124 \end_inset 
6125
6126  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6127  This is the one and only that the ds390 code generator supports right now
6128  and is default when using 
6129 \emph on 
6130 -mds390
6131 \emph default 
6132 .
6133  In this mode, the stack is located in the lower 1K of the internal RAM,
6134  which is mapped to 0x400000.
6135  Note that the support is incomplete, since it still uses a single byte
6136  as the stack pointer.
6137  This means that only the lower 256 bytes of the potential 1K stack space
6138  will actually be used.
6139  However, this does allow you to reclaim the precious 256 bytes of low RAM
6140  for use for the DATA and IDATA segments.
6141  The compiler will not generate any code to put the processor into 10 bit
6142  stack mode.
6143  It is important to ensure that the processor is in this mode before calling
6144  any re-entrant functions compiled with this option.
6145  In principle, this should work with the 
6146 \emph on 
6147 -
6148 \begin_inset ERT
6149 status Collapsed
6150
6151 \layout Standard
6152
6153 \backslash 
6154 /
6155 \end_inset 
6156
6157 -stack-auto
6158 \begin_inset LatexCommand \index{-\/-stack-auto}
6159
6160 \end_inset 
6161
6162
6163 \emph default 
6164  option, but that has not been tested.
6165  It is incompatible with the 
6166 \emph on 
6167 -
6168 \begin_inset ERT
6169 status Collapsed
6170
6171 \layout Standard
6172
6173 \backslash 
6174 /
6175 \end_inset 
6176
6177 -xstack
6178 \begin_inset LatexCommand \index{-\/-xstack}
6179
6180 \end_inset 
6181
6182
6183 \emph default 
6184  option.
6185  It also only makes sense if the processor is in 24 bit contiguous addressing
6186  mode (see the 
6187 \emph on 
6188 -
6189 \begin_inset ERT
6190 status Collapsed
6191
6192 \layout Standard
6193
6194 \backslash 
6195 /
6196 \end_inset 
6197
6198 -model-flat24 option
6199 \emph default 
6200 ).
6201 \layout List
6202 \labelwidthstring 00.00.0000
6203
6204
6205 \series bold 
6206 -
6207 \begin_inset ERT
6208 status Collapsed
6209
6210 \layout Standard
6211
6212 \backslash 
6213 /
6214 \end_inset 
6215
6216 -stack-probe
6217 \begin_inset LatexCommand \index{-\/-stack-probe}
6218
6219 \end_inset 
6220
6221
6222 \series default 
6223  insert call to function __stack_probe at each function prologue.
6224 \layout List
6225 \labelwidthstring 00.00.0000
6226
6227
6228 \series bold 
6229 -
6230 \begin_inset ERT
6231 status Collapsed
6232
6233 \layout Standard
6234
6235 \backslash 
6236 /
6237 \end_inset 
6238
6239 -tini-libid
6240 \begin_inset LatexCommand \index{-\/-tini-libid}
6241
6242 \end_inset 
6243
6244
6245 \series default 
6246  <nnnn> LibraryID used in -mTININative.
6247  
6248 \layout List
6249 \labelwidthstring 00.00.0000
6250
6251
6252 \series bold 
6253 -
6254 \begin_inset ERT
6255 status Collapsed
6256
6257 \layout Standard
6258
6259 \backslash 
6260 /
6261 \end_inset 
6262
6263 -use-accelerator
6264 \begin_inset LatexCommand \index{-\/-use-accelerator}
6265
6266 \end_inset 
6267
6268
6269 \series default 
6270  generate code for DS390 Arithmetic Accelerator.
6271  
6272 \layout Subsection
6273
6274 Z80 Options
6275 \begin_inset LatexCommand \index{Options Z80}
6276
6277 \end_inset 
6278
6279
6280 \begin_inset LatexCommand \index{Z80 options}
6281
6282 \end_inset 
6283
6284
6285 \layout List
6286 \labelwidthstring 00.00.0000
6287
6288
6289 \series bold 
6290 -
6291 \begin_inset ERT
6292 status Collapsed
6293
6294 \layout Standard
6295
6296 \backslash 
6297 /
6298 \end_inset 
6299
6300 -callee-saves-bc
6301 \series default 
6302
6303 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6304
6305 \end_inset 
6306
6307
6308 \size large 
6309 \emph on 
6310  
6311 \size default 
6312 \emph default 
6313 Force a called function to always save BC.
6314 \layout List
6315 \labelwidthstring 00.00.0000
6316
6317
6318 \series bold 
6319 -
6320 \begin_inset ERT
6321 status Collapsed
6322
6323 \layout Standard
6324
6325 \backslash 
6326 /
6327 \end_inset 
6328
6329 -no-std-crt0
6330 \series default 
6331
6332 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6333
6334 \end_inset 
6335
6336  When linking, skip the standard crt0.o object file.
6337  You must provide your own crt0.o for your system when linking.
6338  
6339 \layout Subsection
6340
6341 Optimization Options
6342 \begin_inset LatexCommand \index{Options optimization}
6343
6344 \end_inset 
6345
6346
6347 \begin_inset LatexCommand \index{Optimization options}
6348
6349 \end_inset 
6350
6351
6352 \layout List
6353 \labelwidthstring 00.00.0000
6354
6355
6356 \series bold 
6357 -
6358 \begin_inset ERT
6359 status Collapsed
6360
6361 \layout Standard
6362
6363 \backslash 
6364 /
6365 \end_inset 
6366
6367 -nogcse
6368 \begin_inset LatexCommand \index{-\/-nogcse}
6369
6370 \end_inset 
6371
6372
6373 \series default 
6374  Will not do global subexpression elimination, this option may be used when
6375  the compiler creates undesirably large stack/data spaces to store compiler
6376  temporaries.
6377  A warning message will be generated when this happens and the compiler
6378  will indicate the number of extra bytes it allocated.
6379  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6380 nogcse
6381 \begin_inset LatexCommand \index{\#pragma nogcse}
6382
6383 \end_inset 
6384
6385  can be used to turn off global subexpression elimination
6386 \begin_inset LatexCommand \index{Subexpression elimination}
6387
6388 \end_inset 
6389
6390  for a given function only.
6391 \layout List
6392 \labelwidthstring 00.00.0000
6393
6394
6395 \series bold 
6396 -
6397 \begin_inset ERT
6398 status Collapsed
6399
6400 \layout Standard
6401
6402 \backslash 
6403 /
6404 \end_inset 
6405
6406 -noinvariant
6407 \begin_inset LatexCommand \index{-\/-noinvariant}
6408
6409 \end_inset 
6410
6411
6412 \series default 
6413  Will not do loop invariant optimizations, this may be turned off for reasons
6414  explained for the previous option.
6415  For more details of loop optimizations performed see Loop Invariants in
6416  section 
6417 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
6418
6419 \end_inset 
6420
6421 .
6422  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6423 noinvariant
6424 \begin_inset LatexCommand \index{\#pragma noinvariant}
6425
6426 \end_inset 
6427
6428  can be used to turn off invariant optimizations for a given function only.
6429 \layout List
6430 \labelwidthstring 00.00.0000
6431
6432
6433 \series bold 
6434 -
6435 \begin_inset ERT
6436 status Collapsed
6437
6438 \layout Standard
6439
6440 \backslash 
6441 /
6442 \end_inset 
6443
6444 -noinduction
6445 \begin_inset LatexCommand \index{-\/-noinduction}
6446
6447 \end_inset 
6448
6449
6450 \series default 
6451  Will not do loop induction optimizations, see section strength reduction
6452  for more details.
6453  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6454 noinduction
6455 \begin_inset LatexCommand \index{\#pragma noinduction}
6456
6457 \end_inset 
6458
6459  can be used to turn off induction optimizations for a given function only.
6460 \layout List
6461 \labelwidthstring 00.00.0000
6462
6463
6464 \series bold 
6465 -
6466 \begin_inset ERT
6467 status Collapsed
6468
6469 \layout Standard
6470
6471 \backslash 
6472 /
6473 \end_inset 
6474
6475 -nojtbound
6476 \begin_inset LatexCommand \index{-\/-nojtbound}
6477
6478 \end_inset 
6479
6480
6481 \size large 
6482 \bar under 
6483  
6484 \series default 
6485 \size default 
6486 \bar default 
6487  Will not generate boundary condition check when switch statements
6488 \begin_inset LatexCommand \index{switch statement}
6489
6490 \end_inset 
6491
6492  are implemented using jump-tables.
6493  See section 
6494 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6495
6496 \end_inset 
6497
6498 \SpecialChar ~
6499 Switch Statements for more details.
6500  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6501 nojtbound
6502 \begin_inset LatexCommand \index{\#pragma nojtbound}
6503
6504 \end_inset 
6505
6506  can be used to turn off boundary checking for jump tables for a given function
6507  only.
6508 \layout List
6509 \labelwidthstring 00.00.0000
6510
6511
6512 \series bold 
6513 -
6514 \begin_inset ERT
6515 status Collapsed
6516
6517 \layout Standard
6518
6519 \backslash 
6520 /
6521 \end_inset 
6522
6523 -noloopreverse
6524 \begin_inset LatexCommand \index{-\/-noloopreverse}
6525
6526 \end_inset 
6527
6528
6529 \series default 
6530 \size large 
6531  
6532 \size default 
6533 Will not do loop reversal 
6534 \begin_inset LatexCommand \index{Loop reversing}
6535
6536 \end_inset 
6537
6538 optimization.
6539 \layout List
6540 \labelwidthstring 00.00.0000
6541
6542 -
6543 \begin_inset ERT
6544 status Collapsed
6545
6546 \layout Standard
6547
6548 \backslash 
6549 /
6550 \end_inset 
6551
6552 -
6553 \series bold 
6554 nolabelopt
6555 \series default 
6556  
6557 \begin_inset LatexCommand \index{-\/-nolabelopt }
6558
6559 \end_inset 
6560
6561 Will not optimize labels (makes the dumpfiles more readable).
6562 \layout List
6563 \labelwidthstring 00.00.0000
6564
6565
6566 \series bold 
6567 -
6568 \begin_inset ERT
6569 status Collapsed
6570
6571 \layout Standard
6572
6573 \backslash 
6574 /
6575 \end_inset 
6576
6577 -no-xinit-opt
6578 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6579
6580 \end_inset 
6581
6582
6583 \series default 
6584  Will not memcpy initialized data from code space into xdata space.
6585  This saves a few bytes in code space if you don't have initialized data.
6586 \layout List
6587 \labelwidthstring 00.00.0000
6588
6589
6590 \series bold 
6591 -
6592 \begin_inset ERT
6593 status Collapsed
6594
6595 \layout Standard
6596
6597 \backslash 
6598 /
6599 \end_inset 
6600
6601 -nooverlay
6602 \begin_inset LatexCommand \index{-\/-nooverlay}
6603
6604 \end_inset 
6605
6606
6607 \series default 
6608   The compiler will not overlay parameters and local variables of any function,
6609  see section Parameters and local variables for more details.
6610 \layout List
6611 \labelwidthstring 00.00.0000
6612
6613
6614 \series bold 
6615 -
6616 \begin_inset ERT
6617 status Collapsed
6618
6619 \layout Standard
6620
6621 \backslash 
6622 /
6623 \end_inset 
6624
6625 -no-peep
6626 \begin_inset LatexCommand \index{-\/-no-peep}
6627
6628 \end_inset 
6629
6630
6631 \series default 
6632  Disable peep-hole optimization.
6633 \layout List
6634 \labelwidthstring 00.00.0000
6635
6636
6637 \series bold 
6638 -
6639 \begin_inset ERT
6640 status Collapsed
6641
6642 \layout Standard
6643
6644 \backslash 
6645 /
6646 \end_inset 
6647
6648 -peep-file
6649 \series default 
6650
6651 \begin_inset LatexCommand \index{-\/-peep-file}
6652
6653 \end_inset 
6654
6655 \SpecialChar ~
6656 <filename> This option can be used to use additional rules to be used by
6657  the peep hole optimizer.
6658  See section 
6659 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6660
6661 \end_inset 
6662
6663 \SpecialChar ~
6664 Peep Hole optimizations for details on how to write these rules.
6665 \layout List
6666 \labelwidthstring 00.00.0000
6667
6668
6669 \series bold 
6670 -
6671 \begin_inset ERT
6672 status Collapsed
6673
6674 \layout Standard
6675
6676 \backslash 
6677 /
6678 \end_inset 
6679
6680 -peep-asm
6681 \begin_inset LatexCommand \index{-\/-peep-asm}
6682
6683 \end_inset 
6684
6685
6686 \series default 
6687   Pass the inline assembler code through the peep hole optimizer.
6688  This can cause unexpected changes to inline assembler code, please go through
6689  the peephole optimizer
6690 \begin_inset LatexCommand \index{Peephole optimizer}
6691
6692 \end_inset 
6693
6694  rules defined in the source file tree '<target>/peeph.def' before using
6695  this option.
6696 \layout Subsection
6697
6698 Other Options
6699 \begin_inset LatexCommand \index{Options other}
6700
6701 \end_inset 
6702
6703
6704 \layout List
6705 \labelwidthstring 00.00.0000
6706
6707
6708 \series bold 
6709 -c\SpecialChar ~
6710 -
6711 \begin_inset ERT
6712 status Collapsed
6713
6714 \layout Standard
6715
6716 \backslash 
6717 /
6718 \end_inset 
6719
6720 -compile-only
6721 \begin_inset LatexCommand \index{-\/-compile-only}
6722
6723 \end_inset 
6724
6725
6726 \begin_inset LatexCommand \index{-c -\/-compile-only}
6727
6728 \end_inset 
6729
6730
6731 \series default 
6732  will compile and assemble the source, but will not call the linkage editor.
6733 \layout List
6734 \labelwidthstring 00.00.0000
6735
6736
6737 \series bold 
6738 -
6739 \series default 
6740
6741 \begin_inset ERT
6742 status Collapsed
6743
6744 \layout Standard
6745
6746 \backslash 
6747 /
6748 \end_inset 
6749
6750
6751 \series bold 
6752 -c1mode
6753 \begin_inset LatexCommand \index{-\/-c1mode}
6754
6755 \end_inset 
6756
6757
6758 \series default 
6759  reads the preprocessed source from standard input and compiles it.
6760  The file name for the assembler output must be specified using the -o option.
6761 \layout List
6762 \labelwidthstring 00.00.0000
6763
6764
6765 \series bold 
6766 -E
6767 \begin_inset LatexCommand \index{-E}
6768
6769 \end_inset 
6770
6771
6772 \series default 
6773  Run only the C preprocessor.
6774  Preprocess all the C source files specified and output the results to standard
6775  output.
6776 \layout List
6777 \labelwidthstring 00.00.0000
6778
6779
6780 \series bold 
6781 -o\SpecialChar ~
6782 <path/file>
6783 \begin_inset LatexCommand \index{-o <path/file>}
6784
6785 \end_inset 
6786
6787  
6788 \series default 
6789 The output path resp.
6790  file where everything will be placed.
6791  If the parameter is a path, it must have a trailing slash (or backslash
6792  for the Windows binaries) to be recognized as a path.
6793  
6794 \layout List
6795 \labelwidthstring 00.00.0000
6796
6797
6798 \series bold 
6799 -
6800 \begin_inset ERT
6801 status Collapsed
6802
6803 \layout Standard
6804
6805 \backslash 
6806 /
6807 \end_inset 
6808
6809 -stack-auto
6810 \begin_inset LatexCommand \index{-\/-stack-auto}
6811
6812 \end_inset 
6813
6814
6815 \series default 
6816 \size large 
6817 \emph on 
6818  
6819 \size default 
6820 \emph default 
6821 All functions in the source file will be compiled as 
6822 \emph on 
6823 reentrant
6824 \emph default 
6825
6826 \begin_inset LatexCommand \index{reentrant}
6827
6828 \end_inset 
6829
6830 , i.e.
6831  the parameters and local variables will be allocated on the stack
6832 \begin_inset LatexCommand \index{stack}
6833
6834 \end_inset 
6835
6836 .
6837  See section 
6838 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
6839
6840 \end_inset 
6841
6842  Parameters and Local Variables for more details.
6843  If this option is used all source files in the project should be compiled
6844  with this option.
6845  
6846 \layout List
6847 \labelwidthstring 00.00.0000
6848
6849
6850 \series bold 
6851 -
6852 \begin_inset ERT
6853 status Collapsed
6854
6855 \layout Standard
6856
6857 \backslash 
6858 /
6859 \end_inset 
6860
6861 -callee-saves
6862 \begin_inset LatexCommand \index{-\/-callee-saves}
6863
6864 \end_inset 
6865
6866  function1[,function2][,function3]....
6867
6868 \series default 
6869  The compiler by default uses a caller saves convention for register saving
6870  across function calls, however this can cause unnecessary register pushing
6871  & popping when calling small functions from larger functions.
6872  This option can be used to switch the register saving convention for the
6873  function names specified.
6874  The compiler will not save registers when calling these functions, no extra
6875  code will be generated at the entry & exit (function prologue
6876 \series bold 
6877
6878 \begin_inset LatexCommand \index{function prologue}
6879
6880 \end_inset 
6881
6882
6883 \series default 
6884  & epilogue
6885 \series bold 
6886
6887 \begin_inset LatexCommand \index{function epilogue}
6888
6889 \end_inset 
6890
6891
6892 \series default 
6893 ) for these functions to save & restore the registers used by these functions,
6894  this can SUBSTANTIALLY reduce code & improve run time performance of the
6895  generated code.
6896  In the future the compiler (with inter procedural analysis) will be able
6897  to determine the appropriate scheme to use for each function call.
6898  DO NOT use this option for built-in functions such as _mulint..., if this
6899  option is used for a library function the appropriate library function
6900  needs to be recompiled with the same option.
6901  If the project consists of multiple source files then all the source file
6902  should be compiled with the same -
6903 \begin_inset ERT
6904 status Collapsed
6905
6906 \layout Standard
6907
6908 \backslash 
6909 /
6910 \end_inset 
6911
6912 -callee-saves option string.
6913  Also see #pragma\SpecialChar ~
6914 callee_saves
6915 \begin_inset LatexCommand \index{\#pragma callee\_saves}
6916
6917 \end_inset 
6918
6919 .
6920 \layout List
6921 \labelwidthstring 00.00.0000
6922
6923
6924 \series bold 
6925 -
6926 \begin_inset ERT
6927 status Open
6928
6929 \layout Standard
6930
6931 \backslash 
6932 /
6933 \end_inset 
6934
6935 -debug
6936 \begin_inset LatexCommand \index{-\/-debug}
6937
6938 \end_inset 
6939
6940
6941 \bar under 
6942  
6943 \series default 
6944 \bar default 
6945 When this option is used the compiler will generate debug information.
6946  The debug information collected in a file with .cdb extension can be used
6947  with the SDCDB.
6948  For more information see documentation for SDCDB.
6949  Another file with no extension contains debug information in AOMF or AOMF51
6950 \begin_inset LatexCommand \index{AOMF, AOMF51}
6951
6952 \end_inset 
6953
6954  format which is commonly used by third party tools.
6955 \layout List
6956 \labelwidthstring 00.00.0000
6957
6958
6959 \series bold 
6960 -S
6961 \begin_inset LatexCommand \index{-S}
6962
6963 \end_inset 
6964
6965
6966 \size large 
6967 \bar under 
6968  
6969 \series default 
6970 \size default 
6971 \bar default 
6972 Stop after the stage of compilation proper; do not assemble.
6973  The output is an assembler code file for the input file specified.
6974 \layout List
6975 \labelwidthstring 00.00.0000
6976
6977
6978 \series bold 
6979 -
6980 \begin_inset ERT
6981 status Collapsed
6982
6983 \layout Standard
6984
6985 \backslash 
6986 /
6987 \end_inset 
6988
6989 -int-long-reent
6990 \begin_inset LatexCommand \index{-\/-int-long-reent}
6991
6992 \end_inset 
6993
6994
6995 \series default 
6996  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6997  Note by default these libraries are compiled as non-reentrant.
6998  See section Installation for more details.
6999 \layout List
7000 \labelwidthstring 00.00.0000
7001
7002
7003 \series bold 
7004 -
7005 \begin_inset ERT
7006 status Collapsed
7007
7008 \layout Standard
7009
7010 \backslash 
7011 /
7012 \end_inset 
7013
7014 -cyclomatic
7015 \begin_inset LatexCommand \index{-\/-cyclomatic}
7016
7017 \end_inset 
7018
7019
7020 \bar under 
7021  
7022 \series default 
7023 \bar default 
7024 This option will cause the compiler to generate an information message for
7025  each function in the source file.
7026  The message contains some 
7027 \emph on 
7028 important
7029 \emph default 
7030  information about the function.
7031  The number of edges and nodes the compiler detected in the control flow
7032  graph of the function, and most importantly the 
7033 \emph on 
7034 cyclomatic complexity
7035 \begin_inset LatexCommand \index{Cyclomatic complexity}
7036
7037 \end_inset 
7038
7039
7040 \emph default 
7041  see section on Cyclomatic Complexity for more details.
7042 \layout List
7043 \labelwidthstring 00.00.0000
7044
7045
7046 \series bold 
7047 -
7048 \begin_inset ERT
7049 status Collapsed
7050
7051 \layout Standard
7052
7053 \backslash 
7054 /
7055 \end_inset 
7056
7057 -float-reent
7058 \begin_inset LatexCommand \index{-\/-float-reent}
7059
7060 \end_inset 
7061
7062
7063 \series default 
7064  Floating point library is compiled as reentrant
7065 \begin_inset LatexCommand \index{reentrant}
7066
7067 \end_inset 
7068
7069 .
7070  See section Installation for more details.
7071 \layout List
7072 \labelwidthstring 00.00.0000
7073
7074
7075 \series bold 
7076 -
7077 \begin_inset ERT
7078 status Collapsed
7079
7080 \layout Standard
7081
7082 \backslash 
7083 /
7084 \end_inset 
7085
7086 -main-return
7087 \begin_inset LatexCommand \index{-\/-main-return}
7088
7089 \end_inset 
7090
7091
7092 \series default 
7093  This option can be used if the code generated is called by a monitor program
7094  or if the main routine includes an endless loop.
7095  This option might result in slightly smaller code and save two bytes of
7096  stack space.
7097  The return from the 'main'
7098 \begin_inset LatexCommand \index{main return}
7099
7100 \end_inset 
7101
7102  function will return to the function calling main.
7103  The default setting is to lock up i.e.
7104  generate a '
7105 \family typewriter 
7106 sjmp .
7107 \family default 
7108 '.
7109 \layout List
7110 \labelwidthstring 00.00.0000
7111
7112
7113 \series bold 
7114 -
7115 \begin_inset ERT
7116 status Collapsed
7117
7118 \layout Standard
7119
7120 \backslash 
7121 /
7122 \end_inset 
7123
7124 -nostdincl
7125 \begin_inset LatexCommand \index{-\/-nostdincl}
7126
7127 \end_inset 
7128
7129
7130 \series default 
7131  This will prevent the compiler from passing on the default include path
7132  to the preprocessor.
7133 \layout List
7134 \labelwidthstring 00.00.0000
7135
7136
7137 \series bold 
7138 -
7139 \begin_inset ERT
7140 status Collapsed
7141
7142 \layout Standard
7143
7144 \backslash 
7145 /
7146 \end_inset 
7147
7148 -nostdlib
7149 \begin_inset LatexCommand \index{-\/-nostdlib}
7150
7151 \end_inset 
7152
7153
7154 \series default 
7155  This will prevent the compiler from passing on the default library
7156 \begin_inset LatexCommand \index{Libraries}
7157
7158 \end_inset 
7159
7160  path to the linker.
7161 \layout List
7162 \labelwidthstring 00.00.0000
7163
7164
7165 \series bold 
7166 -
7167 \begin_inset ERT
7168 status Collapsed
7169
7170 \layout Standard
7171
7172 \backslash 
7173 /
7174 \end_inset 
7175
7176 -verbose
7177 \begin_inset LatexCommand \index{-\/-verbose}
7178
7179 \end_inset 
7180
7181
7182 \series default 
7183  Shows the various actions the compiler is performing.
7184 \layout List
7185 \labelwidthstring 00.00.0000
7186
7187
7188 \series bold 
7189 -V
7190 \begin_inset LatexCommand \index{-V}
7191
7192 \end_inset 
7193
7194
7195 \series default 
7196  Shows the actual commands the compiler is executing.
7197 \layout List
7198 \labelwidthstring 00.00.0000
7199
7200
7201 \series bold 
7202 -
7203 \begin_inset ERT
7204 status Collapsed
7205
7206 \layout Standard
7207
7208 \backslash 
7209 /
7210 \end_inset 
7211
7212 -no-c-code-in-asm
7213 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7214
7215 \end_inset 
7216
7217
7218 \series default 
7219  Hides your ugly and inefficient c-code from the asm file, so you can always
7220  blame the compiler :)
7221 \layout List
7222 \labelwidthstring 00.00.0000
7223
7224
7225 \series bold 
7226 -
7227 \begin_inset ERT
7228 status Collapsed
7229
7230 \layout Standard
7231
7232 \backslash 
7233 /
7234 \end_inset 
7235
7236 -no-peep-comments
7237 \begin_inset LatexCommand \index{-\/-no-peep-comments}
7238
7239 \end_inset 
7240
7241
7242 \series default 
7243  Will not include peep-hole comments in the generated files.
7244 \layout List
7245 \labelwidthstring 00.00.0000
7246
7247
7248 \series bold 
7249 -
7250 \begin_inset ERT
7251 status Collapsed
7252
7253 \layout Standard
7254
7255 \backslash 
7256 /
7257 \end_inset 
7258
7259 -i-code-in-asm
7260 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7261
7262 \end_inset 
7263
7264
7265 \series default 
7266  Include i-codes in the asm file.
7267  Sounds like noise but is most helpful for debugging the compiler itself.
7268 \layout List
7269 \labelwidthstring 00.00.0000
7270
7271
7272 \series bold 
7273 -
7274 \begin_inset ERT
7275 status Collapsed
7276
7277 \layout Standard
7278
7279 \backslash 
7280 /
7281 \end_inset 
7282
7283 -less-pedantic
7284 \begin_inset LatexCommand \index{-\/-less-pedantic}
7285
7286 \end_inset 
7287
7288
7289 \series default 
7290  Disable some of the more pedantic warnings
7291 \begin_inset LatexCommand \index{Warnings}
7292
7293 \end_inset 
7294
7295  (jwk burps: please be more specific here, please!).
7296  If you want rather more than less warnings you should consider using a
7297  separate tool dedicated to syntax checking like splint 
7298 \begin_inset LatexCommand \url{www.splint.org}
7299
7300 \end_inset 
7301
7302 .
7303 \layout List
7304 \labelwidthstring 00.00.0000
7305
7306
7307 \series bold 
7308 -
7309 \begin_inset ERT
7310 status Collapsed
7311
7312 \layout Standard
7313
7314 \backslash 
7315 /
7316 \end_inset 
7317
7318 -print-search-dirs
7319 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7320
7321 \end_inset 
7322
7323
7324 \series default 
7325  Display the directories in the compiler's search path
7326 \layout List
7327 \labelwidthstring 00.00.0000
7328
7329
7330 \series bold 
7331 -
7332 \begin_inset ERT
7333 status Collapsed
7334
7335 \layout Standard
7336
7337 \backslash 
7338 /
7339 \end_inset 
7340
7341 -vc
7342 \begin_inset LatexCommand \index{-\/-vc}
7343
7344 \end_inset 
7345
7346
7347 \series default 
7348  Display errors and warnings using MSVC style, so you can use SDCC with
7349  visual studio.
7350 \layout List
7351 \labelwidthstring 00.00.0000
7352
7353
7354 \series bold 
7355 -
7356 \begin_inset ERT
7357 status Collapsed
7358
7359 \layout Standard
7360
7361 \backslash 
7362 /
7363 \end_inset 
7364
7365 -use-stdout
7366 \begin_inset LatexCommand \index{-\/-use-stdout}
7367
7368 \end_inset 
7369
7370
7371 \series default 
7372  Send errors and warnings to stdout instead of stderr.
7373 \layout List
7374 \labelwidthstring 00.00.0000
7375
7376
7377 \series bold 
7378 -Wa\SpecialChar ~
7379 asmOption[,asmOption]
7380 \series default 
7381
7382 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7383
7384 \end_inset 
7385
7386 ...
7387  Pass the asmOption to the assembler
7388 \begin_inset LatexCommand \index{Options assembler}
7389
7390 \end_inset 
7391
7392
7393 \begin_inset LatexCommand \index{Assembler options}
7394
7395 \end_inset 
7396
7397 .
7398  See file sdcc/as/doc/asxhtm.html for assembler options.
7399 \layout Subsection
7400
7401 Intermediate Dump Options
7402 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7403
7404 \end_inset 
7405
7406
7407 \begin_inset LatexCommand \index{Options intermediate dump}
7408
7409 \end_inset 
7410
7411
7412 \begin_inset LatexCommand \index{Intermediate dump options}
7413
7414 \end_inset 
7415
7416
7417 \layout Standard
7418
7419 The following options are provided for the purpose of retargetting and debugging
7420  the compiler.
7421  These provided a means to dump the intermediate code (iCode
7422 \begin_inset LatexCommand \index{iCode}
7423
7424 \end_inset 
7425
7426 ) generated by the compiler in human readable form at various stages of
7427  the compilation process.
7428  More on iCodes see chapter 
7429 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7430
7431 \end_inset 
7432
7433  
7434 \begin_inset Quotes srd
7435 \end_inset 
7436
7437 The anatomy of the compiler
7438 \begin_inset Quotes srd
7439 \end_inset 
7440
7441 .
7442 \layout List
7443 \labelwidthstring 00.00.0000
7444
7445
7446 \series bold 
7447 -
7448 \begin_inset ERT
7449 status Collapsed
7450
7451 \layout Standard
7452
7453 \backslash 
7454 /
7455 \end_inset 
7456
7457 -dumpraw
7458 \begin_inset LatexCommand \index{-\/-dumpraw}
7459
7460 \end_inset 
7461
7462
7463 \series default 
7464  This option will cause the compiler to dump the intermediate code into
7465  a file of named 
7466 \emph on 
7467 <source filename>.dumpraw
7468 \emph default 
7469  just after the intermediate code has been generated for a function, i.e.
7470  before any optimizations are done.
7471  The basic blocks
7472 \begin_inset LatexCommand \index{Basic blocks}
7473
7474 \end_inset 
7475
7476  at this stage ordered in the depth first number, so they may not be in
7477  sequence of execution.
7478 \layout List
7479 \labelwidthstring 00.00.0000
7480
7481
7482 \series bold 
7483 -
7484 \begin_inset ERT
7485 status Collapsed
7486
7487 \layout Standard
7488
7489 \backslash 
7490 /
7491 \end_inset 
7492
7493 -dumpgcse
7494 \begin_inset LatexCommand \index{-\/-dumpgcse}
7495
7496 \end_inset 
7497
7498
7499 \series default 
7500  Will create a dump of iCode's, after global subexpression elimination
7501 \begin_inset LatexCommand \index{Global subexpression elimination}
7502
7503 \end_inset 
7504
7505 , into a file named 
7506 \emph on 
7507 <source filename>.dumpgcse.
7508 \layout List
7509 \labelwidthstring 00.00.0000
7510
7511
7512 \series bold 
7513 -
7514 \begin_inset ERT
7515 status Collapsed
7516
7517 \layout Standard
7518
7519 \backslash 
7520 /
7521 \end_inset 
7522
7523 -dumpdeadcode
7524 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7525
7526 \end_inset 
7527
7528
7529 \series default 
7530  Will create a dump of iCode's, after deadcode elimination
7531 \begin_inset LatexCommand \index{Dead-code elimination}
7532
7533 \end_inset 
7534
7535 , into a file named 
7536 \emph on 
7537 <source filename>.dumpdeadcode.
7538 \layout List
7539 \labelwidthstring 00.00.0000
7540
7541
7542 \series bold 
7543 -
7544 \begin_inset ERT
7545 status Collapsed
7546
7547 \layout Standard
7548
7549 \backslash 
7550 /
7551 \end_inset 
7552
7553 -dumploop
7554 \begin_inset LatexCommand \index{-\/-dumploop}
7555
7556 \end_inset 
7557
7558
7559 \series default 
7560 \size large 
7561  
7562 \size default 
7563 Will create a dump of iCode's, after loop optimizations
7564 \begin_inset LatexCommand \index{Loop optimization}
7565
7566 \end_inset 
7567
7568 , into a file named 
7569 \emph on 
7570 <source filename>.dumploop.
7571 \layout List
7572 \labelwidthstring 00.00.0000
7573
7574
7575 \series bold 
7576 -
7577 \begin_inset ERT
7578 status Collapsed
7579
7580 \layout Standard
7581
7582 \backslash 
7583 /
7584 \end_inset 
7585
7586 -dumprange
7587 \begin_inset LatexCommand \index{-\/-dumprange}
7588
7589 \end_inset 
7590
7591
7592 \series default 
7593 \size large 
7594  
7595 \size default 
7596 Will create a dump of iCode's, after live range analysis
7597 \begin_inset LatexCommand \index{Live range analysis}
7598
7599 \end_inset 
7600
7601 , into a file named 
7602 \emph on 
7603 <source filename>.dumprange.
7604 \layout List
7605 \labelwidthstring 00.00.0000
7606
7607
7608 \series bold 
7609 -
7610 \begin_inset ERT
7611 status Collapsed
7612
7613 \layout Standard
7614
7615 \backslash 
7616 /
7617 \end_inset 
7618
7619 -dumlrange
7620 \begin_inset LatexCommand \index{-\/-dumlrange}
7621
7622 \end_inset 
7623
7624
7625 \series default 
7626  Will dump the life ranges
7627 \begin_inset LatexCommand \index{Live range analysis}
7628
7629 \end_inset 
7630
7631  for all symbols.
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 -dumpregassign
7648 \begin_inset LatexCommand \index{-\/-dumpregassign}
7649
7650 \end_inset 
7651
7652
7653 \bar under 
7654  
7655 \series default 
7656 \bar default 
7657 Will create a dump of iCode's, after register assignment
7658 \begin_inset LatexCommand \index{Register assignment}
7659
7660 \end_inset 
7661
7662 , into a file named 
7663 \emph on 
7664 <source filename>.dumprassgn.
7665 \layout List
7666 \labelwidthstring 00.00.0000
7667
7668
7669 \series bold 
7670 -
7671 \begin_inset ERT
7672 status Collapsed
7673
7674 \layout Standard
7675
7676 \backslash 
7677 /
7678 \end_inset 
7679
7680 -dumplrange
7681 \begin_inset LatexCommand \index{-\/-dumplrange}
7682
7683 \end_inset 
7684
7685
7686 \series default 
7687  Will create a dump of the live ranges of iTemp's
7688 \layout List
7689 \labelwidthstring 00.00.0000
7690
7691
7692 \series bold 
7693 -
7694 \begin_inset ERT
7695 status Collapsed
7696
7697 \layout Standard
7698
7699 \backslash 
7700 /
7701 \end_inset 
7702
7703 -dumpall
7704 \begin_inset LatexCommand \index{-\/-dumpall}
7705
7706 \end_inset 
7707
7708
7709 \size large 
7710 \bar under 
7711  
7712 \series default 
7713 \size default 
7714 \bar default 
7715 Will cause all the above mentioned dumps to be created.
7716 \layout Subsection
7717
7718 Redirecting output on Windows Shells
7719 \layout Standard
7720
7721 By default SDCC writes it's error messages to 
7722 \begin_inset Quotes sld
7723 \end_inset 
7724
7725 standard error
7726 \begin_inset Quotes srd
7727 \end_inset 
7728
7729 .
7730  To force all messages to 
7731 \begin_inset Quotes sld
7732 \end_inset 
7733
7734 standard output
7735 \begin_inset Quotes srd
7736 \end_inset 
7737
7738  use 
7739 \series bold 
7740 -
7741 \series default 
7742 \emph on 
7743
7744 \begin_inset ERT
7745 status Collapsed
7746
7747 \layout Standard
7748
7749 \backslash 
7750 /
7751 \end_inset 
7752
7753
7754 \series bold 
7755 \emph default 
7756 -
7757 \series default 
7758 use-stdout
7759 \begin_inset LatexCommand \index{-\/-use-stdout}
7760
7761 \end_inset 
7762
7763 .
7764  Additionally, if you happen to have visual studio installed in your windows
7765  machine, you can use it to compile your sources using a custom build and
7766  the SDCC -
7767 \emph on 
7768
7769 \begin_inset ERT
7770 status Collapsed
7771
7772 \layout Standard
7773
7774 \backslash 
7775 /
7776 \end_inset 
7777
7778
7779 \emph default 
7780 -vc
7781 \begin_inset LatexCommand \index{-\/-vc}
7782
7783 \end_inset 
7784
7785  option.
7786  Something like this should work:
7787 \newline 
7788
7789 \newline 
7790
7791 \series bold 
7792 c:
7793 \backslash 
7794 sdcc
7795 \backslash 
7796 bin
7797 \backslash 
7798 sdcc.exe -
7799 \series default 
7800 \emph on 
7801
7802 \begin_inset ERT
7803 status Collapsed
7804
7805 \layout Standard
7806
7807 \backslash 
7808 /
7809 \end_inset 
7810
7811
7812 \series bold 
7813 \emph default 
7814 -vc -
7815 \series default 
7816 \emph on 
7817
7818 \begin_inset ERT
7819 status Collapsed
7820
7821 \layout Standard
7822
7823 \backslash 
7824 /
7825 \end_inset 
7826
7827
7828 \series bold 
7829 \emph default 
7830 -model-large -c $(InputPath)
7831 \layout Section
7832
7833 Environment variables
7834 \begin_inset LatexCommand \index{Environment variables}
7835
7836 \end_inset 
7837
7838
7839 \layout Standard
7840
7841 SDCC recognizes the following environment variables:
7842 \layout List
7843 \labelwidthstring 00.00.0000
7844
7845
7846 \series bold 
7847 SDCC_LEAVE_SIGNALS
7848 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7849
7850 \end_inset 
7851
7852
7853 \series default 
7854  SDCC installs a signal handler
7855 \begin_inset LatexCommand \index{signal handler}
7856
7857 \end_inset 
7858
7859  to be able to delete temporary files after an user break (^C) or an exception.
7860  If this environment variable is set, SDCC won't install the signal handler
7861  in order to be able to debug SDCC.
7862 \layout List
7863 \labelwidthstring 00.00.0000
7864
7865
7866 \series bold 
7867 TMP,\SpecialChar ~
7868 TEMP,\SpecialChar ~
7869 TMPDIR
7870 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7871
7872 \end_inset 
7873
7874
7875 \series default 
7876  Path, where temporary files will be created.
7877  The order of the variables is the search order.
7878  In a standard *nix environment these variables are not set, and there's
7879  no need to set them.
7880  On Windows it's recommended to set one of them.
7881 \layout List
7882 \labelwidthstring 00.00.0000
7883
7884
7885 \series bold 
7886 SDCC_HOME
7887 \begin_inset LatexCommand \index{SDCC\_HOME}
7888
7889 \end_inset 
7890
7891
7892 \series default 
7893  Path, see section 
7894 \begin_inset LatexCommand \ref{sub:Install-paths}
7895
7896 \end_inset 
7897
7898 \SpecialChar ~
7899
7900 \begin_inset Quotes sld
7901 \end_inset 
7902
7903  Install Paths
7904 \begin_inset Quotes srd
7905 \end_inset 
7906
7907 .
7908 \layout List
7909 \labelwidthstring 00.00.0000
7910
7911
7912 \series bold 
7913 SDCC_INCLUDE
7914 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7915
7916 \end_inset 
7917
7918
7919 \series default 
7920  Path, see section 
7921 \begin_inset LatexCommand \ref{sub:Search-Paths}
7922
7923 \end_inset 
7924
7925 \SpecialChar ~
7926
7927 \begin_inset Quotes sld
7928 \end_inset 
7929
7930 Search Paths
7931 \begin_inset Quotes srd
7932 \end_inset 
7933
7934 .
7935 \layout List
7936 \labelwidthstring 00.00.0000
7937
7938
7939 \series bold 
7940 SDCC_LIB
7941 \begin_inset LatexCommand \index{SDCC\_LIB}
7942
7943 \end_inset 
7944
7945
7946 \series default 
7947  Path, see section 
7948 \begin_inset LatexCommand \ref{sub:Search-Paths}
7949
7950 \end_inset 
7951
7952 \SpecialChar ~
7953
7954 \begin_inset Quotes sld
7955 \end_inset 
7956
7957 Search Paths
7958 \begin_inset Quotes srd
7959 \end_inset 
7960
7961 ..
7962 \layout Standard
7963
7964 There are some more environment variables recognized by SDCC, but these
7965  are solely used for debugging purposes.
7966  They can change or disappear very quickly, and will never be documented.
7967 \layout Section
7968
7969 Storage Class Language Extensions
7970 \layout Subsection
7971
7972 MCS51/DS390 Storage Class
7973 \begin_inset LatexCommand \index{Storage class}
7974
7975 \end_inset 
7976
7977  Language Extensions
7978 \layout Standard
7979
7980 In addition to the ANSI storage classes SDCC allows the following MCS51
7981  specific storage classes:
7982 \layout Subsubsection
7983
7984 data
7985 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7986
7987 \end_inset 
7988
7989  / near
7990 \begin_inset LatexCommand \index{near (storage class)}
7991
7992 \end_inset 
7993
7994
7995 \layout Standard
7996
7997 This is the 
7998 \series bold 
7999 default
8000 \series default 
8001  storage class for the Small Memory model (
8002 \emph on 
8003 data
8004 \emph default 
8005  and 
8006 \emph on 
8007 near
8008 \emph default 
8009  can be used synonymously).
8010  Variables declared with this storage class will be allocated in the directly
8011  addressable portion of the internal RAM of a 8051, e.g.:
8012 \layout Verse
8013
8014
8015 \family typewriter 
8016 data unsigned char test_data;
8017 \layout Standard
8018
8019 Writing 0x01 to this variable generates the assembly code:
8020 \layout Verse
8021
8022
8023 \family typewriter 
8024 75*00 01\SpecialChar ~
8025 \SpecialChar ~
8026 \SpecialChar ~
8027 mov\SpecialChar ~
8028 \SpecialChar ~
8029 _test_data,#0x01 
8030 \layout Subsubsection
8031
8032 xdata
8033 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8034
8035 \end_inset 
8036
8037  / far
8038 \begin_inset LatexCommand \index{far (storage class)}
8039
8040 \end_inset 
8041
8042
8043 \layout Standard
8044
8045 Variables declared with this storage class will be placed in the external
8046  RAM.
8047  This is the 
8048 \series bold 
8049 default
8050 \series default 
8051  storage class for the Large Memory model, e.g.:
8052 \layout Verse
8053
8054
8055 \family typewriter 
8056 xdata unsigned char test_xdata;
8057 \layout Standard
8058
8059 Writing 0x01 to this variable generates the assembly code:
8060 \layout Verse
8061
8062
8063 \family typewriter 
8064 90s00r00\SpecialChar ~
8065 \SpecialChar ~
8066 \SpecialChar ~
8067 mov\SpecialChar ~
8068 \SpecialChar ~
8069 dptr,#_test_xdata 
8070 \newline 
8071 74\SpecialChar ~
8072 01\SpecialChar ~
8073 \SpecialChar ~
8074 \SpecialChar ~
8075 \SpecialChar ~
8076 \SpecialChar ~
8077 \SpecialChar ~
8078 mov\SpecialChar ~
8079 \SpecialChar ~
8080 a,#0x01 
8081 \newline 
8082 F0\SpecialChar ~
8083 \SpecialChar ~
8084 \SpecialChar ~
8085 \SpecialChar ~
8086 \SpecialChar ~
8087 \SpecialChar ~
8088 \SpecialChar ~
8089 \SpecialChar ~
8090 \SpecialChar ~
8091 movx\SpecialChar ~
8092 @dptr,a 
8093 \layout Subsubsection
8094
8095 idata
8096 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8097
8098 \end_inset 
8099
8100
8101 \layout Standard
8102
8103 Variables declared with this storage class will be allocated into the indirectly
8104  addressable portion of the internal ram of a 8051, e.g.:
8105 \layout Verse
8106
8107
8108 \family typewriter 
8109 idata unsigned char test_idata;
8110 \layout Standard
8111
8112 Writing 0x01 to this variable generates the assembly code:
8113 \layout Verse
8114
8115
8116 \family typewriter 
8117 78r00\SpecialChar ~
8118 \SpecialChar ~
8119 \SpecialChar ~
8120 \SpecialChar ~
8121 \SpecialChar ~
8122 \SpecialChar ~
8123 \SpecialChar ~
8124 mov\SpecialChar ~
8125 \SpecialChar ~
8126 r0,#_test_idata
8127 \newline 
8128 76\SpecialChar ~
8129 01\SpecialChar ~
8130 \SpecialChar ~
8131 \SpecialChar ~
8132 \SpecialChar ~
8133 \SpecialChar ~
8134 \SpecialChar ~
8135 \SpecialChar ~
8136 mov\SpecialChar ~
8137 \SpecialChar ~
8138 @r0,#0x01
8139 \layout Standard
8140
8141 Please note, the first 128 byte of idata physically access the same RAM
8142  as the data memory.
8143  The original 8051 had 128 byte idata memory, nowadays most devices have
8144  256 byte idata memory.
8145  The stack
8146 \begin_inset LatexCommand \index{stack}
8147
8148 \end_inset 
8149
8150  is located in idata memory.
8151 \layout Subsubsection
8152
8153 pdata
8154 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8155
8156 \end_inset 
8157
8158
8159 \layout Standard
8160
8161 Paged xdata access is currently not as straightforward as using the other
8162  addressing modes of a 8051.
8163  The following example writes 0x01 to the address pointed to.
8164  Please note, pdata access physically accesses xdata memory.
8165  The high byte of the address is determined by port P2 
8166 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8167
8168 \end_inset 
8169
8170 (or in case of some 8051 variants by a separate Special Function Register,
8171  see section 
8172 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8173
8174 \end_inset 
8175
8176 ).
8177 \layout Verse
8178
8179
8180 \family typewriter 
8181 pdata unsigned char *test_pdata_ptr;
8182 \newline 
8183
8184 \newline 
8185 void main() 
8186 \newline 
8187
8188 \newline 
8189 \SpecialChar ~
8190 \SpecialChar ~
8191 \SpecialChar ~
8192 \SpecialChar ~
8193 test_pdata_ptr = (pdata *)0xfe; 
8194 \newline 
8195 \SpecialChar ~
8196 \SpecialChar ~
8197 \SpecialChar ~
8198 \SpecialChar ~
8199 *test_pdata_ptr = 1; 
8200 \newline 
8201
8202 \layout Standard
8203
8204 Generates the assembly code:
8205 \layout Verse
8206
8207
8208 \family typewriter 
8209 75*01 FE\SpecialChar ~
8210 \SpecialChar ~
8211 \SpecialChar ~
8212 mov\SpecialChar ~
8213  _test_pdata_ptr,#0xFE
8214 \newline 
8215 78 FE\SpecialChar ~
8216 \SpecialChar ~
8217 \SpecialChar ~
8218 \SpecialChar ~
8219 \SpecialChar ~
8220 \SpecialChar ~
8221 mov\SpecialChar ~
8222  r0,#0xFE 
8223 \newline 
8224 74 01\SpecialChar ~
8225 \SpecialChar ~
8226 \SpecialChar ~
8227 \SpecialChar ~
8228 \SpecialChar ~
8229 \SpecialChar ~
8230 mov\SpecialChar ~
8231  a,#0x01
8232 \newline 
8233 F2\SpecialChar ~
8234 \SpecialChar ~
8235 \SpecialChar ~
8236 \SpecialChar ~
8237 \SpecialChar ~
8238 \SpecialChar ~
8239 \SpecialChar ~
8240 \SpecialChar ~
8241 \SpecialChar ~
8242 movx @r0,a 
8243 \layout Standard
8244
8245 Be extremely carefull if you use pdata together with the -
8246 \begin_inset ERT
8247 status Collapsed
8248
8249 \layout Standard
8250
8251 \backslash 
8252 /
8253 \end_inset 
8254
8255 -xstack
8256 \begin_inset LatexCommand \index{-\/-xstack}
8257
8258 \end_inset 
8259
8260  option.
8261 \layout Subsubsection
8262
8263 code
8264 \begin_inset LatexCommand \index{code}
8265
8266 \end_inset 
8267
8268
8269 \layout Standard
8270
8271 'Variables' declared with this storage class will be placed in the code
8272  memory:
8273 \layout Verse
8274
8275
8276 \family typewriter 
8277 code unsigned char test_code;
8278 \layout Standard
8279
8280 Read access to this variable generates the assembly code:
8281 \layout Verse
8282
8283
8284 \family typewriter 
8285 90s00r6F\SpecialChar ~
8286 \SpecialChar ~
8287 \SpecialChar ~
8288 mov dptr,#_test_code
8289 \newline 
8290 E4\SpecialChar ~
8291 \SpecialChar ~
8292 \SpecialChar ~
8293 \SpecialChar ~
8294 \SpecialChar ~
8295 \SpecialChar ~
8296 \SpecialChar ~
8297 \SpecialChar ~
8298 \SpecialChar ~
8299 clr a
8300 \newline 
8301 93\SpecialChar ~
8302 \SpecialChar ~
8303 \SpecialChar ~
8304 \SpecialChar ~
8305 \SpecialChar ~
8306 \SpecialChar ~
8307 \SpecialChar ~
8308 \SpecialChar ~
8309 \SpecialChar ~
8310 movc a,@a+dptr 
8311 \layout Standard
8312
8313
8314 \family typewriter 
8315 char
8316 \family default 
8317  indexed arrays of characters in code memory can be accessed efficiently:
8318 \layout Verse
8319
8320
8321 \family typewriter 
8322 code char test_array[] = {'c','h','e','a','p'}; 
8323 \layout Standard
8324
8325 Read access to this array using an 8-bit unsigned index generates the assembly
8326  code:
8327 \layout Verse
8328
8329
8330 \family typewriter 
8331 E5*00\SpecialChar ~
8332 \SpecialChar ~
8333 \SpecialChar ~
8334 \SpecialChar ~
8335 \SpecialChar ~
8336 \SpecialChar ~
8337 mov a,_index 
8338 \layout Verse
8339
8340
8341 \family typewriter 
8342 90s00r41\SpecialChar ~
8343 \SpecialChar ~
8344 \SpecialChar ~
8345 mov dptr,#_test_array
8346 \layout Verse
8347
8348
8349 \family typewriter 
8350 93\SpecialChar ~
8351 \SpecialChar ~
8352 \SpecialChar ~
8353 \SpecialChar ~
8354 \SpecialChar ~
8355 \SpecialChar ~
8356 \SpecialChar ~
8357 \SpecialChar ~
8358 \SpecialChar ~
8359 movc a,@a+dptr 
8360 \layout Subsubsection
8361
8362 bit
8363 \begin_inset LatexCommand \index{bit}
8364
8365 \end_inset 
8366
8367
8368 \layout Standard
8369
8370 This is a data-type and a storage class specifier.
8371  When a variable is declared as a bit, it is allocated into the bit addressable
8372  memory of 8051, e.g.:
8373 \layout Verse
8374
8375
8376 \family typewriter 
8377 bit test_bit;
8378 \layout Standard
8379
8380 Writing 1 to this variable generates the assembly code:
8381 \layout Verse
8382
8383
8384 \family typewriter 
8385 D2*00\SpecialChar ~
8386 \SpecialChar ~
8387 \SpecialChar ~
8388 \SpecialChar ~
8389 \SpecialChar ~
8390 \SpecialChar ~
8391 \SpecialChar ~
8392 setb\SpecialChar ~
8393 _test_bit
8394 \layout Standard
8395
8396 The bit addressable memory consists of 128 bits which are located from 0x20
8397  to 0x2f in data memory.
8398  
8399 \newline 
8400 Apart from this 8051 specific storage class most architectures support ANSI-C
8401  bitfields
8402 \begin_inset LatexCommand \index{bitfields}
8403
8404 \end_inset 
8405
8406
8407 \begin_inset Foot
8408 collapsed false
8409
8410 \layout Standard
8411
8412 Not really meant as examples, but nevertheless showing what bitfields are
8413  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8414 \end_inset 
8415
8416 .
8417  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
8418  signed modifier are implemented as unsigned.
8419 \layout Subsubsection
8420
8421 sfr
8422 \begin_inset LatexCommand \index{sfr}
8423
8424 \end_inset 
8425
8426  / sbit
8427 \begin_inset LatexCommand \index{sbit}
8428
8429 \end_inset 
8430
8431
8432 \layout Standard
8433
8434 Like the bit keyword, 
8435 \emph on 
8436 sfr / sbit 
8437 \emph default 
8438 signifies both a data-type and storage class, they are used to describe
8439  the 
8440 \emph on 
8441 s
8442 \emph default 
8443 pecial 
8444 \emph on 
8445 f
8446 \emph default 
8447 unction 
8448 \emph on 
8449 r
8450 \emph default 
8451 egisters and 
8452 \emph on 
8453 s
8454 \emph default 
8455 pecial 
8456 \emph on 
8457 bit
8458 \emph default 
8459  variables of a 8051, eg:
8460 \layout Verse
8461
8462
8463 \family typewriter 
8464 sfr at
8465 \begin_inset LatexCommand \index{at}
8466
8467 \end_inset 
8468
8469  0x80 P0;\SpecialChar ~
8470  /* special function register P0 at location 0x80 */
8471 \newline 
8472 sbit at 0xd7 CY; /* CY (Carry Flag
8473 \begin_inset LatexCommand \index{Flags}
8474
8475 \end_inset 
8476
8477
8478 \begin_inset LatexCommand \index{Carry flag}
8479
8480 \end_inset 
8481
8482 ) */
8483 \layout Standard
8484
8485 Special function registers which are located on an address dividable by
8486  8 are bit-addressable, an
8487 \emph on 
8488  sbit
8489 \emph default 
8490  addresses a specific bit within these sfr.
8491 \layout Subsubsection
8492
8493 Pointers
8494 \begin_inset LatexCommand \index{Pointer}
8495
8496 \end_inset 
8497
8498  to MCS51/DS390 specific memory spaces
8499 \layout Standard
8500
8501 SDCC allows (via language extensions) pointers to explicitly point to any
8502  of the memory spaces
8503 \begin_inset LatexCommand \index{Memory model}
8504
8505 \end_inset 
8506
8507  of the 8051.
8508  In addition to the explicit pointers, the compiler uses (by default) generic
8509  pointers which can be used to point to any of the memory spaces.
8510 \newline 
8511
8512 \newline 
8513 Pointer declaration examples:
8514 \layout Verse
8515
8516
8517 \family typewriter 
8518 /* pointer physically in internal ram pointing to object in external ram
8519  */ 
8520 \newline 
8521 xdata unsigned char * data p;
8522 \newline 
8523
8524 \newline 
8525 /* pointer physically in external ram pointing to object in internal ram
8526  */ 
8527 \newline 
8528 data unsigned char * xdata p;
8529 \newline 
8530
8531 \newline 
8532 /* pointer physically in code rom pointing to data in xdata space */ 
8533 \newline 
8534 xdata unsigned char * code p;
8535 \newline 
8536
8537 \newline 
8538 /* pointer physically in code space pointing to data in code space */ 
8539 \newline 
8540 code unsigned char * code p;
8541 \newline 
8542
8543 \newline 
8544 /* the following is a generic pointer physically located in xdata space
8545  */
8546 \newline 
8547 char * xdata p;
8548 \layout Standard
8549
8550 Well you get the idea.
8551  
8552 \newline 
8553
8554 \newline 
8555 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
8556 \emph on 
8557 generic
8558 \emph default 
8559  pointers.
8560  
8561 \size small 
8562
8563 \newline 
8564
8565 \newline 
8566
8567 \size default 
8568 The highest order byte of the 
8569 \emph on 
8570 generic
8571 \emph default 
8572  pointers contains the data space information.
8573  Assembler support routines are called whenever data is stored or retrieved
8574  using 
8575 \emph on 
8576 generic
8577 \emph default 
8578  pointers.
8579  These are useful for developing reusable library
8580 \begin_inset LatexCommand \index{Libraries}
8581
8582 \end_inset 
8583
8584  routines.
8585  Explicitly specifying the pointer type will generate the most efficient
8586  code.
8587 \layout Subsubsection
8588
8589 Notes on MCS51 memory
8590 \begin_inset LatexCommand \index{MCS51 memory}
8591
8592 \end_inset 
8593
8594  layout
8595 \layout Standard
8596
8597 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8598  RAM memory which is structured as follows:
8599 \newline 
8600
8601 \newline 
8602 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8603  
8604 \newline 
8605 - Bytes 20-2F - 16 bytes to hold 128 bit
8606 \begin_inset LatexCommand \index{bit}
8607
8608 \end_inset 
8609
8610  variables and, 
8611 \newline 
8612 - Bytes 30-7F - 80 bytes for general purpose use.
8613 \newline 
8614
8615 \layout Standard
8616
8617 Additionally some members of the MCS51 family may have up to 128 bytes of
8618  additional, indirectly addressable, internal RAM memory (
8619 \emph on 
8620 idata
8621 \emph default 
8622
8623 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8624
8625 \end_inset 
8626
8627 ).
8628  Furthermore, some chips may have some built in external memory (
8629 \emph on 
8630 xdata
8631 \emph default 
8632
8633 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8634
8635 \end_inset 
8636
8637 ) which should not be confused with the internal, directly addressable RAM
8638  memory (
8639 \emph on 
8640 data
8641 \emph default 
8642
8643 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8644
8645 \end_inset 
8646
8647 ).
8648  Sometimes this built in 
8649 \emph on 
8650 xdata
8651 \emph default 
8652  memory has to be activated before using it (you can probably find this
8653  information on the datasheet of the microcontroller your are using, see
8654  also section 
8655 \begin_inset LatexCommand \ref{sub:Startup-Code}
8656
8657 \end_inset 
8658
8659 \SpecialChar ~
8660 Startup-Code).
8661 \layout Standard
8662
8663 Normally SDCC will only use the first bank
8664 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8665
8666 \end_inset 
8667
8668  of registers (register bank 0), but it is possible to specify that other
8669  banks of registers should be used in interrupt
8670 \begin_inset LatexCommand \index{interrupt}
8671
8672 \end_inset 
8673
8674  routines.
8675  By default, the compiler will place the stack after the last byte of allocated
8676  memory for variables.
8677  For example, if the first 2 banks of registers are used, and only four
8678  bytes are used for 
8679 \emph on 
8680 data
8681 \emph default 
8682  variables, it will position the base of the internal stack at address 20
8683  (0x14).
8684  This implies that as the stack
8685 \begin_inset LatexCommand \index{stack}
8686
8687 \end_inset 
8688
8689  grows, it will use up the remaining register banks, and the 16 bytes used
8690  by the 128 bit variables, and 80 bytes for general purpose use.
8691  If any bit variables are used, the data variables will be placed after
8692  the byte holding the last bit variable.
8693  For example, if register banks 0 and 1 are used, and there are 9 bit variables
8694  (two bytes used), 
8695 \emph on 
8696 data
8697 \emph default 
8698  variables will be placed starting at address 0x22.
8699  You can also use -
8700 \begin_inset ERT
8701 status Collapsed
8702
8703 \layout Standard
8704
8705 \backslash 
8706 /
8707 \end_inset 
8708
8709 -data-loc
8710 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8711
8712 \end_inset 
8713
8714  to specify the start address of the 
8715 \emph on 
8716 data
8717 \emph default 
8718  and -
8719 \begin_inset ERT
8720 status Collapsed
8721
8722 \layout Standard
8723
8724 \backslash 
8725 /
8726 \end_inset 
8727
8728 -iram-size to specify the size of the total internal RAM (
8729 \emph on 
8730 data
8731 \emph default 
8732 +
8733 \emph on 
8734 idata
8735 \emph default 
8736 ).
8737  
8738 \layout Standard
8739
8740 By default the 8051 linker will place the stack after the last byte of data
8741  variables.
8742  Option -
8743 \begin_inset ERT
8744 status Collapsed
8745
8746 \layout Standard
8747
8748 \backslash 
8749 /
8750 \end_inset 
8751
8752 -stack-loc
8753 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8754
8755 \end_inset 
8756
8757  allows you to specify the start of the stack, i.e.
8758  you could start it after any data in the general purpose area.
8759  If your microcontroller has additional indirectly addressable internal
8760  RAM (
8761 \emph on 
8762 idata
8763 \emph default 
8764 ) you can place the stack on it.
8765  You may also need to use -
8766 \begin_inset ERT
8767 status Collapsed
8768
8769 \layout Standard
8770
8771 \backslash 
8772 /
8773 \end_inset 
8774
8775 -xdata-loc
8776 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8777
8778 \end_inset 
8779
8780  to set the start address of the external RAM (
8781 \emph on 
8782 xdata
8783 \emph default 
8784 ) and -
8785 \begin_inset ERT
8786 status Collapsed
8787
8788 \layout Standard
8789
8790 \backslash 
8791 /
8792 \end_inset 
8793
8794 -xram-size
8795 \begin_inset LatexCommand \index{-\/-data-loc}
8796
8797 \end_inset 
8798
8799  to specify its size.
8800  Same goes for the code memory, using -
8801 \begin_inset ERT
8802 status Collapsed
8803
8804 \layout Standard
8805
8806 \backslash 
8807 /
8808 \end_inset 
8809
8810 -code-loc
8811 \begin_inset LatexCommand \index{-\/-data-loc}
8812
8813 \end_inset 
8814
8815  and -
8816 \begin_inset ERT
8817 status Collapsed
8818
8819 \layout Standard
8820
8821 \backslash 
8822 /
8823 \end_inset 
8824
8825 -code-size
8826 \begin_inset LatexCommand \index{-\/-data-loc}
8827
8828 \end_inset 
8829
8830 .
8831  If in doubt, don't specify any options and see if the resulting memory
8832  layout is appropriate, then you can adjust it.
8833 \layout Standard
8834
8835 The linker generates two files with memory allocation information.
8836  The first, with extension .map
8837 \begin_inset LatexCommand \index{<file>.map}
8838
8839 \end_inset 
8840
8841  shows all the variables and segments.
8842  The second with extension .mem
8843 \begin_inset LatexCommand \index{<file>.mem}
8844
8845 \end_inset 
8846
8847  shows the final memory layout.
8848  The linker will complain either if memory segments overlap, there is not
8849  enough memory, or there is not enough space for stack.
8850  If you get any linking warnings and/or errors related to stack or segments
8851  allocation, take a look at either the .map or .mem files to find out what
8852  the problem is.
8853  The .mem file may even suggest a solution to the problem.
8854 \layout Subsection
8855
8856 Z80/Z180 Storage Class
8857 \begin_inset LatexCommand \index{Storage class}
8858
8859 \end_inset 
8860
8861  Language Extensions
8862 \layout Subsubsection
8863
8864 sfr
8865 \begin_inset LatexCommand \index{sfr}
8866
8867 \end_inset 
8868
8869  (in/out to 8-bit addresses)
8870 \layout Standard
8871
8872 The Z80
8873 \begin_inset LatexCommand \index{Z80}
8874
8875 \end_inset 
8876
8877  family has separate address spaces for memory and 
8878 \emph on 
8879 i
8880 \emph default 
8881 nput/
8882 \emph on 
8883 o
8884 \emph default 
8885 utput memory.
8886  I/O memory
8887 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
8888
8889 \end_inset 
8890
8891  is accessed with special instructions, e.g.:
8892 \layout Verse
8893
8894
8895 \family typewriter 
8896 sfr at 0x78 IoPort;\SpecialChar ~
8897 \SpecialChar ~
8898 /* define a var in I/O space at 78h called IoPort */
8899  
8900 \layout Standard
8901
8902 Writing 0x01 to this variable generates the assembly code:
8903 \layout Verse
8904
8905
8906 \family typewriter 
8907 3E 01\SpecialChar ~
8908 \SpecialChar ~
8909 \SpecialChar ~
8910 \SpecialChar ~
8911 \SpecialChar ~
8912 \SpecialChar ~
8913 ld a,#0x01
8914 \newline 
8915 D3 78\SpecialChar ~
8916 \SpecialChar ~
8917 \SpecialChar ~
8918 \SpecialChar ~
8919 \SpecialChar ~
8920 \SpecialChar ~
8921 out (_IoPort),a 
8922 \layout Subsubsection
8923
8924 banked sfr
8925 \begin_inset LatexCommand \index{sfr}
8926
8927 \end_inset 
8928
8929  (in/out to 16-bit addresses)
8930 \layout Standard
8931
8932 The keyword 
8933 \emph on 
8934 banked
8935 \emph default 
8936  is used to support 16 bit addresses in I/O memory e.g.:
8937 \layout Verse
8938
8939
8940 \family typewriter 
8941 sfr banked at
8942 \begin_inset LatexCommand \index{at}
8943
8944 \end_inset 
8945
8946  0x123 IoPort; 
8947 \layout Standard
8948
8949 Writing 0x01 to this variable generates the assembly code:
8950 \layout Verse
8951
8952
8953 \family typewriter 
8954 01 23 01\SpecialChar ~
8955 \SpecialChar ~
8956 \SpecialChar ~
8957 ld bc,#_IoPort
8958 \newline 
8959 3E 01\SpecialChar ~
8960 \SpecialChar ~
8961 \SpecialChar ~
8962 \SpecialChar ~
8963 \SpecialChar ~
8964 \SpecialChar ~
8965 ld a,#0x01 
8966 \newline 
8967 ED 79\SpecialChar ~
8968 \SpecialChar ~
8969 \SpecialChar ~
8970 \SpecialChar ~
8971 \SpecialChar ~
8972 \SpecialChar ~
8973 out (c),a 
8974 \layout Subsubsection
8975
8976 sfr
8977 \begin_inset LatexCommand \index{sfr}
8978
8979 \end_inset 
8980
8981  (in0/out0 to 8 bit addresses on Z180
8982 \begin_inset LatexCommand \index{Z180}
8983
8984 \end_inset 
8985
8986 /HD64180
8987 \begin_inset LatexCommand \index{HD64180}
8988
8989 \end_inset 
8990
8991 )
8992 \layout Standard
8993
8994 The compiler option -
8995 \begin_inset ERT
8996 status Collapsed
8997
8998 \layout Standard
8999
9000 \backslash 
9001 /
9002 \end_inset 
9003
9004 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
9005 portmode
9006 \begin_inset LatexCommand \index{\#pragma portmode}
9007
9008 \end_inset 
9009
9010 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
9011 ns 
9012 \family typewriter 
9013 in0/out0
9014 \family default 
9015  instead of 
9016 \family typewriter 
9017 in/out
9018 \family default 
9019 .
9020  If you include the file z180.h this will be set automatically.
9021 \layout Subsection
9022
9023 HC08 Storage Class
9024 \begin_inset LatexCommand \index{Storage class}
9025
9026 \end_inset 
9027
9028  Language Extensions
9029 \layout Subsubsection
9030
9031 data
9032 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9033
9034 \end_inset 
9035
9036
9037 \layout Standard
9038
9039 The data storage class declares a variable that resides in the first 256
9040  bytes of memory (the direct page).
9041  The HC08 is most efficient at accessing variables (especially pointers)
9042  stored here.
9043 \layout Subsubsection
9044
9045 xdata
9046 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9047
9048 \end_inset 
9049
9050
9051 \layout Standard
9052
9053 The xdata storage class declares a variable that can reside anywhere in
9054  memory.
9055  This is the default if no storage class is specified.
9056  
9057 \layout Section
9058
9059 Absolute Addressing
9060 \begin_inset LatexCommand \index{Absolute addressing}
9061
9062 \end_inset 
9063
9064
9065 \layout Standard
9066
9067 Data items can be assigned an absolute address with the 
9068 \emph on 
9069 at
9070 \begin_inset LatexCommand \index{at}
9071
9072 \end_inset 
9073
9074  <address>
9075 \emph default 
9076  keyword, in addition to a storage class, e.g.:
9077 \layout Verse
9078
9079
9080 \family typewriter 
9081 xdata
9082 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9083
9084 \end_inset 
9085
9086  at
9087 \begin_inset LatexCommand \index{at}
9088
9089 \end_inset 
9090
9091  0x7ffe unsigned int chksum;
9092 \layout Standard
9093
9094 In the above example the variable chksum will located at 0x7ffe and 0x7fff
9095  of the external ram.
9096  The compiler does 
9097 \emph on 
9098 not
9099 \emph default 
9100  reserve any space for variables declared in this way (they are implemented
9101  with an equate in the assembler).
9102  Thus it is left to the programmer to make sure there are no overlaps with
9103  other variables that are declared without the absolute address.
9104  The assembler listing file (.lst
9105 \begin_inset LatexCommand \index{<file>.lst}
9106
9107 \end_inset 
9108
9109 ) and the linker output files (.rst
9110 \begin_inset LatexCommand \index{<file>.rst}
9111
9112 \end_inset 
9113
9114 ) and (.map
9115 \begin_inset LatexCommand \index{<file>.map}
9116
9117 \end_inset 
9118
9119 ) are good places to look for such overlaps.
9120  Variables with an absolute address are 
9121 \emph on 
9122 not
9123 \emph default 
9124  initialized
9125 \begin_inset LatexCommand \index{Variable initialization}
9126
9127 \end_inset 
9128
9129 .
9130 \layout Standard
9131
9132 In case of memory mapped I/O devices the keyword 
9133 \emph on 
9134 volatile
9135 \emph default 
9136  have to be used to tell the compiler that accesses might not be optimized
9137  away:
9138 \layout Verse
9139
9140
9141 \family typewriter 
9142 volatile
9143 \begin_inset LatexCommand \index{volatile}
9144
9145 \end_inset 
9146
9147  xdata
9148 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9149
9150 \end_inset 
9151
9152  at
9153 \begin_inset LatexCommand \index{at}
9154
9155 \end_inset 
9156
9157  0x8000 unsigned char PORTA_8255;
9158 \layout Standard
9159
9160 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9161 r) array
9162 \family typewriter 
9163 \size footnotesize 
9164
9165 \begin_inset LatexCommand \index{Aligned array}
9166
9167 \end_inset 
9168
9169
9170 \family default 
9171 \size default 
9172  starts at a block (256 byte) boundary
9173 \begin_inset LatexCommand \index{block boundary}
9174
9175 \end_inset 
9176
9177  (section 
9178 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9179
9180 \end_inset 
9181
9182  has an example).
9183 \newline 
9184 Absolute addresses can be specified for variables in all storage classes,
9185  e.g.:
9186 \layout Verse
9187
9188
9189 \family typewriter 
9190 bit
9191 \begin_inset LatexCommand \index{bit}
9192
9193 \end_inset 
9194
9195  at
9196 \begin_inset LatexCommand \index{at}
9197
9198 \end_inset 
9199
9200  0x02 bvar;
9201 \layout Standard
9202
9203 The above example will allocate the variable at offset 0x02 in the bit-addressab
9204 le space.
9205  There is no real advantage to assigning absolute addresses to variables
9206  in this manner, unless you want strict control over all the variables allocated.
9207  One possible use would be to write hardware portable code.
9208  For example, if you have a routine that uses one or more of the microcontroller
9209  I/O pins, and such pins are different for two different hardwares, you
9210  can declare the I/O pins in your routine using:
9211 \layout Verse
9212
9213
9214 \family typewriter 
9215 extern volatile bit MOSI;\SpecialChar ~
9216 \SpecialChar ~
9217 \SpecialChar ~
9218 \SpecialChar ~
9219 /* master out, slave in */
9220 \newline 
9221 extern volatile bit MISO;\SpecialChar ~
9222 \SpecialChar ~
9223 \SpecialChar ~
9224 \SpecialChar ~
9225 /* master in, slave out */
9226 \newline 
9227 extern volatile bit MCLK;\SpecialChar ~
9228 \SpecialChar ~
9229 \SpecialChar ~
9230 \SpecialChar ~
9231 /* master clock */
9232 \newline 
9233
9234 \newline 
9235 /* Input and Output of a byte on a 3-wire serial bus.
9236 \newline 
9237 \SpecialChar ~
9238 \SpecialChar ~
9239 \SpecialChar ~
9240 If needed adapt polarity of clock, polarity of data and bit order
9241 \newline 
9242 \SpecialChar ~
9243 */
9244 \newline 
9245 unsigned char spi_io(unsigned char out_byte) 
9246 \newline 
9247
9248 \newline 
9249 \SpecialChar ~
9250 \SpecialChar ~
9251 \SpecialChar ~
9252 \SpecialChar ~
9253 unsigned char i=8;
9254 \newline 
9255 \SpecialChar ~
9256 \SpecialChar ~
9257 \SpecialChar ~
9258 \SpecialChar ~
9259 do { 
9260 \newline 
9261 \SpecialChar ~
9262 \SpecialChar ~
9263 \SpecialChar ~
9264 \SpecialChar ~
9265 \SpecialChar ~
9266 \SpecialChar ~
9267 \SpecialChar ~
9268 \SpecialChar ~
9269 MOSI = out_byte & 0x80; 
9270 \newline 
9271 \SpecialChar ~
9272 \SpecialChar ~
9273 \SpecialChar ~
9274 \SpecialChar ~
9275 \SpecialChar ~
9276 \SpecialChar ~
9277 \SpecialChar ~
9278 \SpecialChar ~
9279 out_byte <<= 1;
9280 \newline 
9281 \SpecialChar ~
9282 \SpecialChar ~
9283 \SpecialChar ~
9284 \SpecialChar ~
9285 \SpecialChar ~
9286 \SpecialChar ~
9287 \SpecialChar ~
9288 \SpecialChar ~
9289 MCLK = 1; 
9290 \newline 
9291 \SpecialChar ~
9292 \SpecialChar ~
9293 \SpecialChar ~
9294 \SpecialChar ~
9295 \SpecialChar ~
9296 \SpecialChar ~
9297 \SpecialChar ~
9298 \SpecialChar ~
9299 /* _asm nop _endasm; */\SpecialChar ~
9300 \SpecialChar ~
9301 \SpecialChar ~
9302 \SpecialChar ~
9303 \SpecialChar ~
9304 \SpecialChar ~
9305 \SpecialChar ~
9306 \SpecialChar ~
9307 /* for slow peripherals */
9308 \newline 
9309 \SpecialChar ~
9310 \SpecialChar ~
9311 \SpecialChar ~
9312 \SpecialChar ~
9313 \SpecialChar ~
9314 \SpecialChar ~
9315 \SpecialChar ~
9316 \SpecialChar ~
9317 if(MISO) 
9318 \newline 
9319 \SpecialChar ~
9320 \SpecialChar ~
9321 \SpecialChar ~
9322 \SpecialChar ~
9323 \SpecialChar ~
9324 \SpecialChar ~
9325 \SpecialChar ~
9326 \SpecialChar ~
9327 \SpecialChar ~
9328 \SpecialChar ~
9329 \SpecialChar ~
9330 \SpecialChar ~
9331 out_byte += 1; 
9332 \newline 
9333 \SpecialChar ~
9334 \SpecialChar ~
9335 \SpecialChar ~
9336 \SpecialChar ~
9337 \SpecialChar ~
9338 \SpecialChar ~
9339 \SpecialChar ~
9340 \SpecialChar ~
9341 MCLK = 0; 
9342 \newline 
9343 \SpecialChar ~
9344 \SpecialChar ~
9345 \SpecialChar ~
9346 \SpecialChar ~
9347 } while(--i);
9348 \newline 
9349 \SpecialChar ~
9350 \SpecialChar ~
9351 \SpecialChar ~
9352 \SpecialChar ~
9353 return out_byte; 
9354 \newline 
9355 }
9356 \layout Standard
9357
9358 Then, someplace in the code for the first hardware you would use
9359 \layout Verse
9360
9361
9362 \family typewriter 
9363 bit at 0x80 MOSI;\SpecialChar ~
9364 \SpecialChar ~
9365 \SpecialChar ~
9366 \SpecialChar ~
9367 /* I/O port 0, bit 0 */
9368 \newline 
9369 bit at 0x81 MISO;\SpecialChar ~
9370 \SpecialChar ~
9371 \SpecialChar ~
9372 \SpecialChar ~
9373 /* I/O port 0, bit 1 */
9374 \newline 
9375 bit at 0x82 MCLK;\SpecialChar ~
9376 \SpecialChar ~
9377 \SpecialChar ~
9378 \SpecialChar ~
9379 /* I/O port 0, bit 2 */
9380 \layout Standard
9381
9382 Similarly, for the second hardware you would use
9383 \layout Verse
9384
9385
9386 \family typewriter 
9387 bit at 0x83 MOSI;\SpecialChar ~
9388 \SpecialChar ~
9389 \SpecialChar ~
9390 \SpecialChar ~
9391 /* I/O port 0, bit 3 */
9392 \newline 
9393 bit at 0x91 MISO;\SpecialChar ~
9394 \SpecialChar ~
9395 \SpecialChar ~
9396 \SpecialChar ~
9397 /* I/O port 1, bit 1 */
9398 \newline 
9399 bit
9400 \begin_inset LatexCommand \index{bit}
9401
9402 \end_inset 
9403
9404  at 0x92 MCLK;\SpecialChar ~
9405 \SpecialChar ~
9406 \SpecialChar ~
9407 \SpecialChar ~
9408 /* I/O port 1, bit 2 */
9409 \layout Standard
9410
9411 and you can use the same hardware dependent routine without changes, as
9412  for example in a library.
9413  This is somehow similar to sbit, but only one absolute address has to be
9414  specified in the whole project.
9415 \layout Section
9416
9417 Parameters
9418 \begin_inset LatexCommand \index{Parameters}
9419
9420 \end_inset 
9421
9422
9423 \begin_inset LatexCommand \index{function parameter}
9424
9425 \end_inset 
9426
9427  & Local Variables
9428 \begin_inset LatexCommand \index{local variables}
9429
9430 \end_inset 
9431
9432
9433 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
9434
9435 \end_inset 
9436
9437
9438 \layout Standard
9439
9440 Automatic (local) variables and parameters to functions can either be placed
9441  on the stack or in data-space.
9442  The default action of the compiler is to place these variables in the internal
9443  RAM (for small model) or external RAM (for large model).
9444  This in fact makes them similar to 
9445 \emph on 
9446 static
9447 \begin_inset LatexCommand \index{static}
9448
9449 \end_inset 
9450
9451
9452 \emph default 
9453  so by default functions are non-reentrant
9454 \begin_inset LatexCommand \index{reentrant}
9455
9456 \end_inset 
9457
9458 .
9459  
9460 \newline 
9461
9462 \newline 
9463 They can be placed on the stack
9464 \begin_inset LatexCommand \index{stack}
9465
9466 \end_inset 
9467
9468  by using the
9469 \emph on 
9470  -
9471 \begin_inset ERT
9472 status Collapsed
9473
9474 \layout Standard
9475
9476 \backslash 
9477 /
9478 \end_inset 
9479
9480 -stack-auto
9481 \begin_inset LatexCommand \index{-\/-stack-auto}
9482
9483 \end_inset 
9484
9485
9486 \emph default 
9487  option, by using 
9488 \emph on 
9489 #pragma\SpecialChar ~
9490 stackauto
9491 \emph default 
9492
9493 \begin_inset LatexCommand \index{\#pragma stackauto}
9494
9495 \end_inset 
9496
9497  or by using the 
9498 \emph on 
9499 reentrant
9500 \begin_inset LatexCommand \index{reentrant}
9501
9502 \end_inset 
9503
9504
9505 \emph default 
9506  keyword in the function declaration, e.g.:
9507 \layout Verse
9508
9509
9510 \family typewriter 
9511 unsigned char foo(char i) reentrant 
9512 \newline 
9513
9514 \newline 
9515 \SpecialChar ~
9516 \SpecialChar ~
9517 \SpecialChar ~
9518 \SpecialChar ~
9519 ...
9520  
9521 \newline 
9522 }
9523 \layout Standard
9524
9525 Since stack space on 8051 is limited, the 
9526 \emph on 
9527 reentrant 
9528 \emph default 
9529 keyword or the
9530 \emph on 
9531  -
9532 \begin_inset ERT
9533 status Collapsed
9534
9535 \layout Standard
9536
9537 \backslash 
9538 /
9539 \end_inset 
9540
9541 -stack-auto
9542 \emph default 
9543  option should be used sparingly.
9544  Note that the reentrant keyword just means that the parameters & local
9545  variables will be allocated to the stack, it 
9546 \emph on 
9547 does not
9548 \emph default 
9549  mean that the function is register bank
9550 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9551
9552 \end_inset 
9553
9554  independent.
9555 \newline 
9556
9557 \newline 
9558 Local variables
9559 \begin_inset LatexCommand \index{local variables}
9560
9561 \end_inset 
9562
9563  can be assigned storage classes and absolute
9564 \begin_inset LatexCommand \index{Absolute addressing}
9565
9566 \end_inset 
9567
9568  addresses, e.g.: 
9569 \layout Verse
9570
9571
9572 \family typewriter 
9573 unsigned char foo() 
9574 \newline 
9575 {
9576 \newline 
9577 \SpecialChar ~
9578 \SpecialChar ~
9579 \SpecialChar ~
9580 \SpecialChar ~
9581 xdata unsigned char i;
9582 \newline 
9583 \SpecialChar ~
9584 \SpecialChar ~
9585 \SpecialChar ~
9586 \SpecialChar ~
9587 bit bvar;
9588 \newline 
9589 \SpecialChar ~
9590 \SpecialChar ~
9591 \SpecialChar ~
9592 \SpecialChar ~
9593 data at
9594 \begin_inset LatexCommand \index{at}
9595
9596 \end_inset 
9597
9598  0x31 unsigned char j;
9599 \newline 
9600 \SpecialChar ~
9601 \SpecialChar ~
9602 \SpecialChar ~
9603 \SpecialChar ~
9604 ...
9605  
9606 \newline 
9607 }
9608 \layout Standard
9609
9610 In the above example the variable 
9611 \emph on 
9612 i
9613 \emph default 
9614  will be allocated in the external ram, 
9615 \emph on 
9616 bvar
9617 \emph default 
9618  in bit addressable space and
9619 \emph on 
9620  j
9621 \emph default 
9622  in internal ram.
9623  When compiled with 
9624 \emph on 
9625 -
9626 \begin_inset ERT
9627 status Collapsed
9628
9629 \layout Standard
9630
9631 \backslash 
9632 /
9633 \end_inset 
9634
9635 -stack-auto
9636 \emph default 
9637  or when a function is declared as 
9638 \emph on 
9639 reentrant
9640 \emph default 
9641  this should only be done for static variables.
9642 \layout Standard
9643
9644 Parameters
9645 \begin_inset LatexCommand \index{function parameter}
9646
9647 \end_inset 
9648
9649  however are not allowed any storage class
9650 \begin_inset LatexCommand \index{Storage class}
9651
9652 \end_inset 
9653
9654 , (storage classes for parameters will be ignored), their allocation is
9655  governed by the memory model in use, and the reentrancy options.
9656 \layout Section
9657
9658 Overlaying
9659 \begin_inset LatexCommand \label{sub:Overlaying}
9660
9661 \end_inset 
9662
9663
9664 \begin_inset LatexCommand \index{Overlaying}
9665
9666 \end_inset 
9667
9668
9669 \layout Standard
9670
9671 For non-reentrant
9672 \begin_inset LatexCommand \index{reentrant}
9673
9674 \end_inset 
9675
9676  functions SDCC will try to reduce internal ram space usage by overlaying
9677  parameters and local variables of a function (if possible).
9678  Parameters and local variables
9679 \begin_inset LatexCommand \index{local variables}
9680
9681 \end_inset 
9682
9683  of a function will be allocated to an overlayable segment if the function
9684  has 
9685 \emph on 
9686 no other function calls and the function is non-reentrant and the memory
9687  model
9688 \begin_inset LatexCommand \index{Memory model}
9689
9690 \end_inset 
9691
9692  is small.
9693
9694 \emph default 
9695  If an explicit storage class
9696 \begin_inset LatexCommand \index{Storage class}
9697
9698 \end_inset 
9699
9700  is specified for a local variable, it will NOT be overlayed.
9701 \layout Standard
9702
9703 Note that the compiler (not the linkage editor) makes the decision for overlayin
9704 g the data items.
9705  Functions that are called from an interrupt service routine should be preceded
9706  by a #pragma\SpecialChar ~
9707 nooverlay
9708 \begin_inset LatexCommand \index{\#pragma nooverlay}
9709
9710 \end_inset 
9711
9712  if they are not reentrant.
9713 \layout Standard
9714
9715 Also note that the compiler does not do any processing of inline assembler
9716  code, so the compiler might incorrectly assign local variables and parameters
9717  of a function into the overlay segment if the inline assembler code calls
9718  other c-functions that might use the overlay.
9719  In that case the #pragma\SpecialChar ~
9720 nooverlay should be used.
9721 \layout Standard
9722
9723 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9724 tion
9725 \begin_inset LatexCommand \index{Multiplication}
9726
9727 \end_inset 
9728
9729  or division
9730 \begin_inset LatexCommand \index{Division}
9731
9732 \end_inset 
9733
9734  will NOT be overlayed since these are implemented using external functions,
9735  e.g.:
9736 \layout Verse
9737
9738
9739 \family typewriter 
9740 #pragma save 
9741 \newline 
9742 #pragma nooverlay
9743 \begin_inset LatexCommand \index{\#pragma nooverlay}
9744
9745 \end_inset 
9746
9747  
9748 \newline 
9749 void set_error(unsigned char errcd) 
9750 \newline 
9751 {
9752 \newline 
9753 \SpecialChar ~
9754 \SpecialChar ~
9755 \SpecialChar ~
9756 \SpecialChar ~
9757 P3 = errcd;
9758 \newline 
9759
9760 \newline 
9761 #pragma restore 
9762 \newline 
9763
9764 \newline 
9765 void some_isr () interrupt
9766 \begin_inset LatexCommand \index{interrupt}
9767
9768 \end_inset 
9769
9770  2
9771 \newline 
9772 {
9773 \newline 
9774 \SpecialChar ~
9775 \SpecialChar ~
9776 \SpecialChar ~
9777 \SpecialChar ~
9778 ...
9779 \newline 
9780 \SpecialChar ~
9781 \SpecialChar ~
9782 \SpecialChar ~
9783 \SpecialChar ~
9784 set_error(10);
9785 \newline 
9786 \SpecialChar ~
9787 \SpecialChar ~
9788 \SpecialChar ~
9789 \SpecialChar ~
9790 ...
9791  
9792 \newline 
9793 }
9794 \layout Standard
9795
9796 In the above example the parameter 
9797 \emph on 
9798 errcd
9799 \emph default 
9800  for the function 
9801 \emph on 
9802 set_error
9803 \emph default 
9804  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9805 nooverlay was
9806  not present, this could cause unpredictable runtime behavior when called
9807  from an interrupt service routine.
9808  The #pragma\SpecialChar ~
9809 nooverlay ensures that the parameters and local variables for
9810  the function are NOT overlayed.
9811 \layout Section
9812
9813 Interrupt Service Routines
9814 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9815
9816 \end_inset 
9817
9818
9819 \layout Subsection
9820
9821 General Information
9822 \layout Standard
9823
9824 SDCC allows 
9825 \emph on 
9826 i
9827 \emph default 
9828 nterrupt 
9829 \emph on 
9830 s
9831 \emph default 
9832 ervice 
9833 \emph on 
9834 r
9835 \emph default 
9836 outines to be coded in C, with some extended keywords.
9837 \layout Verse
9838
9839
9840 \family typewriter 
9841 void timer_isr (void) interrupt 1 using 1 
9842 \newline 
9843
9844 \newline 
9845 \SpecialChar ~
9846 \SpecialChar ~
9847 \SpecialChar ~
9848 \SpecialChar ~
9849 ...
9850  
9851 \newline 
9852 }
9853 \layout Standard
9854
9855 The optional number following the 
9856 \emph on 
9857 interrupt
9858 \begin_inset LatexCommand \index{interrupt}
9859
9860 \end_inset 
9861
9862
9863 \emph default 
9864  keyword is the interrupt number this routine will service.
9865  When present, the compiler will insert a call to this routine in the interrupt
9866  vector table for the interrupt number specified.
9867  If you have multiple source files in your project, interrupt service routines
9868  can be present in any of them, but a prototype of the isr MUST be present
9869  or included in the file that contains the function 
9870 \emph on 
9871 main
9872 \emph default 
9873 .
9874  The 
9875 \emph on 
9876 using
9877 \emph default 
9878  keyword can be used to tell the compiler to use the specified register
9879  bank (8051 specific) when generating code for this function.
9880  
9881 \newline 
9882
9883 \layout Standard
9884
9885 Interrupt service routines open the door for some very interesting bugs:
9886 \newline 
9887 If an interrupt service routine changes variables which are accessed by
9888  other functions these variables have to be declared 
9889 \emph on 
9890 volatile
9891 \emph default 
9892
9893 \begin_inset LatexCommand \index{volatile}
9894
9895 \end_inset 
9896
9897 .
9898  
9899 \layout Standard
9900
9901 If the access to these variables is not 
9902 \emph on 
9903 atomic
9904 \begin_inset LatexCommand \index{atomic access}
9905
9906 \end_inset 
9907
9908
9909 \emph default 
9910  (i.e.
9911  the processor needs more than one instruction for the access and could
9912  be interrupted while accessing the variable) the interrupt must be disabled
9913  during the access to avoid inconsistent data.
9914  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9915  and should be protected by disabling interrupts.
9916  You're not automatically on the safe side if you use 8 bit variables though.
9917  We need an example here: f.e.
9918  on the 8051 the harmless looking 
9919 \begin_inset Quotes srd
9920 \end_inset 
9921
9922
9923 \family typewriter 
9924 flags\SpecialChar ~
9925 |=\SpecialChar ~
9926 0x80;
9927 \family default 
9928
9929 \begin_inset Quotes sld
9930 \end_inset 
9931
9932  is not atomic if 
9933 \family typewriter 
9934 flags
9935 \family default 
9936  resides in xdata.
9937  Setting 
9938 \begin_inset Quotes srd
9939 \end_inset 
9940
9941
9942 \family typewriter 
9943 flags\SpecialChar ~
9944 |=\SpecialChar ~
9945 0x40;
9946 \family default 
9947
9948 \begin_inset Quotes sld
9949 \end_inset 
9950
9951  from within an interrupt routine might get lost if the interrupt occurs
9952  at the wrong time.
9953  
9954 \begin_inset Quotes sld
9955 \end_inset 
9956
9957
9958 \family typewriter 
9959 counter\SpecialChar ~
9960 +=\SpecialChar ~
9961 8;
9962 \family default 
9963
9964 \begin_inset Quotes srd
9965 \end_inset 
9966
9967  is not atomic on the 8051 even if 
9968 \family typewriter 
9969 counter
9970 \family default 
9971  is located in data memory.
9972  Bugs like these are hard to reproduce and can cause a lot of trouble.
9973  
9974 \layout Standard
9975
9976 The return address and the registers used in the interrupt service routine
9977  are saved on the stack
9978 \begin_inset LatexCommand \index{stack}
9979
9980 \end_inset 
9981
9982  so there must be sufficient stack space.
9983  If there isn't variables or registers (or even the return address itself)
9984  will be corrupted.
9985  This 
9986 \emph on 
9987 stack overflow
9988 \emph default 
9989
9990 \begin_inset LatexCommand \index{stack overflow}
9991
9992 \end_inset 
9993
9994  is most likely to happen if the interrupt occurs during the 
9995 \begin_inset Quotes sld
9996 \end_inset 
9997
9998 deepest
9999 \begin_inset Quotes srd
10000 \end_inset 
10001
10002  subroutine when the stack is already in use for f.e.
10003  many return addresses.
10004 \layout Standard
10005
10006 A special note here, int (16 bit) and long (32 bit) integer division
10007 \begin_inset LatexCommand \index{Division}
10008
10009 \end_inset 
10010
10011 , multiplication
10012 \begin_inset LatexCommand \index{Multiplication}
10013
10014 \end_inset 
10015
10016  & modulus
10017 \begin_inset LatexCommand \index{Modulus}
10018
10019 \end_inset 
10020
10021  and floating-point
10022 \begin_inset LatexCommand \index{Floating point support}
10023
10024 \end_inset 
10025
10026  operations are implemented using external support routines developed in
10027  ANSI-C.
10028  If an interrupt service routine needs to do any of these operations then
10029  the support routines (as mentioned in a following section) will have to
10030  be recompiled using the
10031 \emph on 
10032  -
10033 \begin_inset ERT
10034 status Collapsed
10035
10036 \layout Standard
10037
10038 \backslash 
10039 /
10040 \end_inset 
10041
10042 -stack-auto
10043 \begin_inset LatexCommand \index{-\/-stack-auto}
10044
10045 \end_inset 
10046
10047
10048 \emph default 
10049  option and the source file will need to be compiled using the 
10050 \emph on 
10051 -
10052 \begin_inset ERT
10053 status Collapsed
10054
10055 \layout Standard
10056
10057 \backslash 
10058 /
10059 \end_inset 
10060
10061 -int-long-reent
10062 \emph default 
10063
10064 \begin_inset LatexCommand \index{-\/-int-long-reent}
10065
10066 \end_inset 
10067
10068  compiler option.
10069 \layout Standard
10070
10071 Calling other functions from an interrupt service routine is not recommended,
10072  avoid it if possible.
10073  Note that when some function is called from an interrupt service routine
10074  it should be preceded by a #pragma\SpecialChar ~
10075 nooverlay
10076 \begin_inset LatexCommand \index{\#pragma nooverlay}
10077
10078 \end_inset 
10079
10080  if it is not reentrant.
10081  Furthermore nonreentrant functions should not be called from the main program
10082  while the interrupt service routine might be active.
10083  
10084 \newline 
10085
10086 \newline 
10087 Also see section 
10088 \begin_inset LatexCommand \ref{sub:Overlaying}
10089
10090 \end_inset 
10091
10092 \SpecialChar ~
10093 about Overlaying and section 
10094 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10095
10096 \end_inset 
10097
10098 \SpecialChar ~
10099 about Functions using private register banks.
10100 \layout Subsection
10101
10102 MCS51/DS390 Interrupt Service Routines
10103 \layout Standard
10104
10105 Interrupt numbers and the corresponding address & descriptions for the Standard
10106  8051/8052 are listed below.
10107  SDCC will automatically adjust the interrupt vector table to the maximum
10108  interrupt number specified.
10109 \newline 
10110
10111 \layout Standard
10112 \align center 
10113
10114 \begin_inset  Tabular
10115 <lyxtabular version="3" rows="7" columns="3">
10116 <features>
10117 <column alignment="center" valignment="top" leftline="true" width="0in">
10118 <column alignment="center" valignment="top" leftline="true" width="0in">
10119 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
10120 <row topline="true" bottomline="true">
10121 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10122 \begin_inset Text
10123
10124 \layout Standard
10125
10126 Interrupt #
10127 \end_inset 
10128 </cell>
10129 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10130 \begin_inset Text
10131
10132 \layout Standard
10133
10134 Description
10135 \end_inset 
10136 </cell>
10137 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10138 \begin_inset Text
10139
10140 \layout Standard
10141
10142 Vector Address
10143 \end_inset 
10144 </cell>
10145 </row>
10146 <row topline="true">
10147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10148 \begin_inset Text
10149
10150 \layout Standard
10151
10152 0
10153 \end_inset 
10154 </cell>
10155 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10156 \begin_inset Text
10157
10158 \layout Standard
10159
10160 External 0
10161 \end_inset 
10162 </cell>
10163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10164 \begin_inset Text
10165
10166 \layout Standard
10167
10168 0x0003
10169 \end_inset 
10170 </cell>
10171 </row>
10172 <row topline="true">
10173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10174 \begin_inset Text
10175
10176 \layout Standard
10177
10178 1
10179 \end_inset 
10180 </cell>
10181 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10182 \begin_inset Text
10183
10184 \layout Standard
10185
10186 Timer 0
10187 \end_inset 
10188 </cell>
10189 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10190 \begin_inset Text
10191
10192 \layout Standard
10193
10194 0x000B
10195 \end_inset 
10196 </cell>
10197 </row>
10198 <row topline="true">
10199 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10200 \begin_inset Text
10201
10202 \layout Standard
10203
10204 2
10205 \end_inset 
10206 </cell>
10207 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10208 \begin_inset Text
10209
10210 \layout Standard
10211
10212 External 1
10213 \end_inset 
10214 </cell>
10215 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10216 \begin_inset Text
10217
10218 \layout Standard
10219
10220 0x0013
10221 \end_inset 
10222 </cell>
10223 </row>
10224 <row topline="true">
10225 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10226 \begin_inset Text
10227
10228 \layout Standard
10229
10230 3
10231 \end_inset 
10232 </cell>
10233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10234 \begin_inset Text
10235
10236 \layout Standard
10237
10238 Timer 1
10239 \end_inset 
10240 </cell>
10241 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10242 \begin_inset Text
10243
10244 \layout Standard
10245
10246 0x001B
10247 \end_inset 
10248 </cell>
10249 </row>
10250 <row topline="true">
10251 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10252 \begin_inset Text
10253
10254 \layout Standard
10255
10256 4
10257 \end_inset 
10258 </cell>
10259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10260 \begin_inset Text
10261
10262 \layout Standard
10263
10264 Serial
10265 \end_inset 
10266 </cell>
10267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10268 \begin_inset Text
10269
10270 \layout Standard
10271
10272 0x0023
10273 \end_inset 
10274 </cell>
10275 </row>
10276 <row topline="true" bottomline="true">
10277 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10278 \begin_inset Text
10279
10280 \layout Standard
10281
10282 5
10283 \end_inset 
10284 </cell>
10285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10286 \begin_inset Text
10287
10288 \layout Standard
10289
10290 Timer 2 (8052)
10291 \end_inset 
10292 </cell>
10293 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10294 \begin_inset Text
10295
10296 \layout Standard
10297
10298 0x002B
10299 \end_inset 
10300 </cell>
10301 </row>
10302 </lyxtabular>
10303
10304 \end_inset 
10305
10306
10307 \newline 
10308
10309 \layout Standard
10310
10311 If the interrupt service routine is defined without 
10312 \emph on 
10313 using
10314 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10315
10316 \end_inset 
10317
10318
10319 \emph default 
10320  a register bank or with register bank 0 (
10321 \emph on 
10322 using
10323 \emph default 
10324  0), the compiler will save the registers used by itself on the stack upon
10325  entry and restore them at exit, however if such an interrupt service routine
10326  calls another function then the entire register bank will be saved on the
10327  stack.
10328  This scheme may be advantageous for small interrupt service routines which
10329  have low register usage.
10330 \layout Standard
10331
10332 If the interrupt service routine is defined to be using a specific register
10333  bank then only 
10334 \emph on 
10335 a, b, dptr
10336 \emph default 
10337  & psw are saved and restored, if such an interrupt service routine calls
10338  another function (using another register bank) then the entire register
10339  bank of the called function will be saved on the stack.
10340  This scheme is recommended for larger interrupt service routines.
10341 \layout Subsection
10342
10343 HC08 Interrupt Service Routines
10344 \layout Standard
10345
10346 Since the number of interrupts available is chip specific and the interrupt
10347  vector table always ends at the last byte of memory, the interrupt numbers
10348  corresponds to the interrupt vectors in reverse order of address.
10349  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
10350  2 will use the interrupt vector at 0xfffa, and so on.
10351  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
10352  this way; instead see section 
10353 \begin_inset LatexCommand \ref{sub:Startup-Code}
10354
10355 \end_inset 
10356
10357  for details on customizing startup.
10358 \layout Subsection
10359
10360 Z80 Interrupt Service Routines
10361 \layout Standard
10362
10363 The Z80 uses several different methods for determining the correct interrupt
10364  vector depending on the hardware implementation.
10365  Therefore, SDCC ignores the optional interrupt number and does not attempt
10366  to generate an interrupt vector table.
10367 \layout Standard
10368
10369 By default, SDCC generates code for a maskable interrupt, which uses an
10370  RETI instruction to return from the interrupt.
10371  To write an interrupt handler for the non-maskable interrupt, which needs
10372  an RETN instruction instead, add the 
10373 \emph on 
10374 critical
10375 \emph default 
10376  keyword:
10377 \layout Verse
10378
10379
10380 \family typewriter 
10381 void nmi_isr (void) critical interrupt
10382 \newline 
10383
10384 \newline 
10385 \SpecialChar ~
10386 \SpecialChar ~
10387 \SpecialChar ~
10388 \SpecialChar ~
10389 ...
10390  
10391 \newline 
10392 }
10393 \layout Section
10394
10395 Enabling and Disabling Interrupts
10396 \layout Subsection
10397
10398 Critical Functions and Critical Statements
10399 \layout Standard
10400
10401 A special keyword may be associated with a block or a function declaring
10402  it as 
10403 \emph on 
10404 critical
10405 \emph default 
10406 .
10407  SDCC will generate code to disable all interrupts
10408 \begin_inset LatexCommand \index{interrupt}
10409
10410 \end_inset 
10411
10412  upon entry to a critical function and restore the interrupt enable to the
10413  previous state before returning.
10414  Nesting critical functions will need one additional byte on the stack
10415 \begin_inset LatexCommand \index{stack}
10416
10417 \end_inset 
10418
10419  for each call.
10420 \layout Verse
10421
10422
10423 \family typewriter 
10424 int foo () critical
10425 \begin_inset LatexCommand \index{critical}
10426
10427 \end_inset 
10428
10429  
10430 \newline 
10431
10432 \newline 
10433 \SpecialChar ~
10434 \SpecialChar ~
10435 \SpecialChar ~
10436 \SpecialChar ~
10437 ...
10438  
10439 \newline 
10440 \SpecialChar ~
10441 \SpecialChar ~
10442 \SpecialChar ~
10443 \SpecialChar ~
10444 ...
10445  
10446 \newline 
10447 }
10448 \layout Standard
10449
10450 The critical attribute maybe used with other attributes like 
10451 \emph on 
10452 reentrant.
10453 \emph default 
10454
10455 \newline 
10456 The keyword 
10457 \emph on 
10458 critical
10459 \emph default 
10460  may also be used to disable interrupts more locally:
10461 \layout Verse
10462
10463
10464 \family typewriter 
10465 critical{ i++; }
10466 \layout Standard
10467
10468 More than one statement could have been included in the block.
10469 \layout Subsection
10470
10471 Enabling and Disabling Interrupts directly
10472 \layout Standard
10473
10474 Interrupts
10475 \begin_inset LatexCommand \index{interrupt}
10476
10477 \end_inset 
10478
10479  can also be disabled and enabled directly (8051):
10480 \layout Verse
10481
10482
10483 \family typewriter 
10484 EA = 0;\SpecialChar ~
10485 \SpecialChar ~
10486 \SpecialChar ~
10487 \SpecialChar ~
10488 \SpecialChar ~
10489 \SpecialChar ~
10490 \SpecialChar ~
10491 \SpecialChar ~
10492 \SpecialChar ~
10493 \SpecialChar ~
10494 \SpecialChar ~
10495 \SpecialChar ~
10496 or:\SpecialChar ~
10497 \SpecialChar ~
10498 \SpecialChar ~
10499 \SpecialChar ~
10500 \SpecialChar ~
10501 \SpecialChar ~
10502 \SpecialChar ~
10503 \SpecialChar ~
10504 \SpecialChar ~
10505 \SpecialChar ~
10506 \SpecialChar ~
10507 EA_SAVE = EA;
10508 \layout Verse
10509
10510
10511 \family typewriter 
10512 ...\SpecialChar ~
10513 \SpecialChar ~
10514 \SpecialChar ~
10515 \SpecialChar ~
10516 \SpecialChar ~
10517 \SpecialChar ~
10518 \SpecialChar ~
10519 \SpecialChar ~
10520 \SpecialChar ~
10521 \SpecialChar ~
10522 \SpecialChar ~
10523 \SpecialChar ~
10524 \SpecialChar ~
10525 \SpecialChar ~
10526 \SpecialChar ~
10527 \SpecialChar ~
10528 \SpecialChar ~
10529 \SpecialChar ~
10530 \SpecialChar ~
10531 \SpecialChar ~
10532 \SpecialChar ~
10533 \SpecialChar ~
10534 \SpecialChar ~
10535 \SpecialChar ~
10536 \SpecialChar ~
10537 \SpecialChar ~
10538 \SpecialChar ~
10539 \SpecialChar ~
10540 \SpecialChar ~
10541 \SpecialChar ~
10542 EA = 0;
10543 \layout Verse
10544
10545
10546 \family typewriter 
10547 EA = 1;\SpecialChar ~
10548 \SpecialChar ~
10549 \SpecialChar ~
10550 \SpecialChar ~
10551 \SpecialChar ~
10552 \SpecialChar ~
10553 \SpecialChar ~
10554 \SpecialChar ~
10555 \SpecialChar ~
10556 \SpecialChar ~
10557 \SpecialChar ~
10558 \SpecialChar ~
10559 \SpecialChar ~
10560 \SpecialChar ~
10561 \SpecialChar ~
10562 \SpecialChar ~
10563 \SpecialChar ~
10564 \SpecialChar ~
10565 \SpecialChar ~
10566 \SpecialChar ~
10567 \SpecialChar ~
10568 \SpecialChar ~
10569 \SpecialChar ~
10570 \SpecialChar ~
10571 \SpecialChar ~
10572 \SpecialChar ~
10573 ...
10574 \layout Verse
10575
10576
10577 \family typewriter 
10578 \SpecialChar ~
10579 \SpecialChar ~
10580 \SpecialChar ~
10581 \SpecialChar ~
10582 \SpecialChar ~
10583 \SpecialChar ~
10584 \SpecialChar ~
10585 \SpecialChar ~
10586 \SpecialChar ~
10587 \SpecialChar ~
10588 \SpecialChar ~
10589 \SpecialChar ~
10590 \SpecialChar ~
10591 \SpecialChar ~
10592 \SpecialChar ~
10593 \SpecialChar ~
10594 \SpecialChar ~
10595 \SpecialChar ~
10596 \SpecialChar ~
10597 \SpecialChar ~
10598 \SpecialChar ~
10599 \SpecialChar ~
10600 \SpecialChar ~
10601 \SpecialChar ~
10602 \SpecialChar ~
10603 \SpecialChar ~
10604 \SpecialChar ~
10605 \SpecialChar ~
10606 \SpecialChar ~
10607 \SpecialChar ~
10608 \SpecialChar ~
10609 \SpecialChar ~
10610 \SpecialChar ~
10611 EA = EA_SAVE;
10612 \layout Standard
10613
10614 On other architectures which have seperate opcodes for enabling and disabling
10615  interrupts you might want to make use of defines with inline assembly
10616 \begin_inset LatexCommand \index{Assembler routines}
10617
10618 \end_inset 
10619
10620  (HC08):
10621 \layout Verse
10622
10623
10624 \family typewriter 
10625 #define CLI _asm
10626 \begin_inset LatexCommand \index{\_asm}
10627
10628 \end_inset 
10629
10630 \SpecialChar ~
10631 \SpecialChar ~
10632 cli\SpecialChar ~
10633 \SpecialChar ~
10634 _endasm
10635 \begin_inset LatexCommand \index{\_endasm}
10636
10637 \end_inset 
10638
10639
10640 \layout Verse
10641
10642
10643 \family typewriter 
10644 #define SEI _asm\SpecialChar ~
10645 \SpecialChar ~
10646 sei\SpecialChar ~
10647 \SpecialChar ~
10648 _endasm; 
10649 \layout Verse
10650
10651
10652 \family typewriter 
10653 ...
10654 \layout Standard
10655
10656 Note: it is sometimes sufficient to disable only a specific interrupt source
10657  like f.e.
10658  a timer or serial interrupt by manipulating an 
10659 \emph on 
10660 interrupt mask
10661 \begin_inset LatexCommand \index{interrupt mask}
10662
10663 \end_inset 
10664
10665
10666 \emph default 
10667  register.
10668  
10669 \layout Standard
10670
10671 Usually the time during which interrupts are disabled should be kept as
10672  short as possible.
10673  This minimizes both 
10674 \emph on 
10675 interrupt latency
10676 \emph default 
10677
10678 \begin_inset LatexCommand \index{interrupt latency}
10679
10680 \end_inset 
10681
10682  (the time between the occurrence of the interrupt and the execution of
10683  the first code in the interrupt routine) and 
10684 \emph on 
10685 interrupt jitter
10686 \emph default 
10687
10688 \begin_inset LatexCommand \index{interrupt jitter}
10689
10690 \end_inset 
10691
10692  (the difference between the shortest and the longest interrupt latency).
10693  These really are something different, f.e.
10694  a serial interrupt has to be served before its buffer overruns so it cares
10695  for the maximum interrupt latency, whereas it does not care about jitter.
10696  On a loudspeaker driven via a digital to analog converter which is fed
10697  by an interrupt a latency of a few milliseconds might be tolerable, whereas
10698  a much smaller jitter will be very audible.
10699 \layout Standard
10700
10701 You can reenable interrupts within an interrupt routine and on some architecture
10702 s you can make use of two (or more) levels of 
10703 \emph on 
10704 interrupt priorities
10705 \emph default 
10706
10707 \begin_inset LatexCommand \index{interrupt priority}
10708
10709 \end_inset 
10710
10711 .
10712  On some architectures which don't support interrupt priorities these can
10713  be implemented by manipulating the interrupt mask and reenabling interrupts
10714  within the interrupt routine.
10715  Check there is sufficient space on the stack
10716 \begin_inset LatexCommand \index{stack}
10717
10718 \end_inset 
10719
10720  and don't add complexity unless you have to.
10721  
10722 \layout Section
10723
10724 Functions using private register banks
10725 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10726
10727 \end_inset 
10728
10729  (mcs51/ds390)
10730 \layout Standard
10731
10732 Some architectures have support for quickly changing register sets.
10733  SDCC supports this feature with the 
10734 \emph on 
10735 using
10736 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10737
10738 \end_inset 
10739
10740
10741 \emph default 
10742  attribute (which tells the compiler to use a register bank
10743 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10744
10745 \end_inset 
10746
10747  other than the default bank zero).
10748  It should only be applied to 
10749 \emph on 
10750 interrupt
10751 \begin_inset LatexCommand \index{interrupt}
10752
10753 \end_inset 
10754
10755
10756 \emph default 
10757  functions (see footnote below).
10758  This will in most circumstances make the generated ISR code more efficient
10759  since it will not have to save registers on the stack.
10760 \layout Standard
10761
10762 The 
10763 \emph on 
10764 using
10765 \emph default 
10766  attribute will have no effect on the generated code for a 
10767 \emph on 
10768 non-interrupt
10769 \emph default 
10770  function (but may occasionally be useful anyway
10771 \begin_inset Foot
10772 collapsed false
10773
10774 \layout Standard
10775
10776 possible exception: if a function is called ONLY from 'interrupt' functions
10777  using a particular bank, it can be declared with the same 'using' attribute
10778  as the calling 'interrupt' functions.
10779  For instance, if you have several ISRs using bank one, and all of them
10780  call memcpy(), it might make sense to create a specialized version of memcpy()
10781  'using 1', since this would prevent the ISR from having to save bank zero
10782  to the stack on entry and switch to bank zero before calling the function
10783 \end_inset 
10784
10785 ).
10786 \newline 
10787
10788 \emph on 
10789 (pending: I don't think this has been done yet)
10790 \layout Standard
10791
10792 An 
10793 \emph on 
10794 interrupt
10795 \emph default 
10796  function using a non-zero bank will assume that it can trash that register
10797  bank, and will not save it.
10798  Since high-priority interrupts
10799 \begin_inset LatexCommand \index{interrupt priority}
10800
10801 \end_inset 
10802
10803  can interrupt low-priority ones on the 8051 and friends, this means that
10804  if a high-priority ISR 
10805 \emph on 
10806 using
10807 \emph default 
10808  a particular bank occurs while processing a low-priority ISR 
10809 \emph on 
10810 using
10811 \emph default 
10812  the same bank, terrible and bad things can happen.
10813  To prevent this, no single register bank should be 
10814 \emph on 
10815 used
10816 \emph default 
10817  by both a high priority and a low priority ISR.
10818  This is probably most easily done by having all high priority ISRs use
10819  one bank and all low priority ISRs use another.
10820  If you have an ISR which can change priority at runtime, you're on your
10821  own: I suggest using the default bank zero and taking the small performance
10822  hit.
10823 \layout Standard
10824
10825 It is most efficient if your ISR calls no other functions.
10826  If your ISR must call other functions, it is most efficient if those functions
10827  use the same bank as the ISR (see note 1 below); the next best is if the
10828  called functions use bank zero.
10829  It is very inefficient to call a function using a different, non-zero bank
10830  from an ISR.
10831  
10832 \layout Section
10833
10834 Startup Code
10835 \begin_inset LatexCommand \label{sub:Startup-Code}
10836
10837 \end_inset 
10838
10839
10840 \begin_inset LatexCommand \index{Startup code}
10841
10842 \end_inset 
10843
10844
10845 \layout Subsection
10846
10847 MCS51/DS390 Startup Code
10848 \layout Standard
10849
10850 The compiler inserts a call to the C routine 
10851 \emph on 
10852 _sdcc_external_startup()
10853 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
10854
10855 \end_inset 
10856
10857
10858 \series bold 
10859 \emph default 
10860  
10861 \series default 
10862 at the start of the CODE area.
10863  This routine is in the runtime library
10864 \begin_inset LatexCommand \index{Runtime library}
10865
10866 \end_inset 
10867
10868 .
10869  By default this routine returns 0, if this routine returns a non-zero value,
10870  the static & global variable initialization will be skipped and the function
10871  main will be invoked.
10872  Otherwise static & global variables will be initialized before the function
10873  main is invoked.
10874  You could add a 
10875 \emph on 
10876 _sdcc_external_startup()
10877 \emph default 
10878  routine to your program to override the default if you need to setup hardware
10879  or perform some other critical operation prior to static & global variable
10880  initialization.
10881  On some mcs51 variants xdata has to be explicitly enabled before it can
10882  be accessed, this is the place to do it.
10883  The startup code clears the complete 256 byte of idata memory, this might
10884  cause problems for 128 byte devices (endless loop reported for Chipcon
10885  CC1010).
10886 \layout Standard
10887
10888 See also the compiler option 
10889 \emph on 
10890 -
10891 \begin_inset ERT
10892 status Collapsed
10893
10894 \layout Standard
10895
10896 \backslash 
10897 /
10898 \end_inset 
10899
10900 -no-xinit
10901 \emph default 
10902 -
10903 \emph on 
10904 opt
10905 \emph default 
10906
10907 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
10908
10909 \end_inset 
10910
10911  and section 
10912 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10913
10914 \end_inset 
10915
10916 \SpecialChar ~
10917 about MCS51-variants.
10918 \layout Subsection
10919
10920 HC08 Startup Code
10921 \layout Standard
10922
10923 The HC08 startup code follows the same scheme as the MCS51 startup code.
10924 \layout Subsection
10925
10926 Z80 Startup Code
10927 \layout Standard
10928
10929 On the Z80 the startup code is inserted by linking with crt0.o which is generated
10930  from sdcc/device/lib/z80/crt0.s.
10931  If you need a different startup code you can use the compiler option 
10932 \emph on 
10933 -
10934 \series bold 
10935 \emph default 
10936
10937 \begin_inset ERT
10938 status Collapsed
10939
10940 \layout Standard
10941
10942 \backslash 
10943 /
10944 \end_inset 
10945
10946
10947 \series default 
10948 \emph on 
10949 -no-std-crt0
10950 \emph default 
10951
10952 \begin_inset LatexCommand \index{-\/-no-std-crt0}
10953
10954 \end_inset 
10955
10956  and provide your own crt0.o.
10957  
10958 \layout Section
10959
10960 Inline Assembler Code
10961 \begin_inset LatexCommand \index{Assembler routines}
10962
10963 \end_inset 
10964
10965
10966 \layout Subsection
10967
10968 A Step by Step Introduction
10969 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
10970
10971 \end_inset 
10972
10973
10974 \layout Standard
10975
10976 Starting from a small snippet of c-code this example shows for the MCS51
10977  how to use inline assembly, access variables, a function parameter and
10978  an array in xdata memory.
10979  The example uses an MCS51 here but is easily adapted for other architectures.
10980  This is a buffer routine which should be optimized:
10981 \layout Verse
10982
10983
10984 \family typewriter 
10985 \size footnotesize 
10986 unsigned char far
10987 \begin_inset LatexCommand \index{far (storage class)}
10988
10989 \end_inset 
10990
10991  at
10992 \begin_inset LatexCommand \index{at}
10993
10994 \end_inset 
10995
10996  0x7f00 buf[0x100];
10997 \begin_inset LatexCommand \index{Aligned array}
10998
10999 \end_inset 
11000
11001
11002 \newline 
11003 unsigned char head,tail;
11004 \newline 
11005
11006 \newline 
11007 void to_buffer( unsigned char c ) 
11008 \newline 
11009 {
11010 \newline 
11011 \SpecialChar ~
11012 \SpecialChar ~
11013 \SpecialChar ~
11014 \SpecialChar ~
11015 if( head != tail-1 ) 
11016 \newline 
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 \SpecialChar ~
11020 \SpecialChar ~
11021 \SpecialChar ~
11022 \SpecialChar ~
11023 \SpecialChar ~
11024 \SpecialChar ~
11025 buf[ head++ ] = c;\SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 \SpecialChar ~
11029 /* access to a 256 byte aligned array */
11030 \newline 
11031
11032 \layout Standard
11033
11034 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
11035  then a corresponding buffer.asm file is generated.
11036  We define a new function 
11037 \family typewriter 
11038 to_buffer_asm()
11039 \family default 
11040  in file buffer.c in which we cut and paste the generated code, removing
11041  unwanted comments and some ':'.
11042  Then add 
11043 \begin_inset Quotes sld
11044 \end_inset 
11045
11046 _asm
11047 \begin_inset Quotes srd
11048 \end_inset 
11049
11050  and 
11051 \begin_inset Quotes sld
11052 \end_inset 
11053
11054 _endasm;
11055 \begin_inset Quotes srd
11056 \end_inset 
11057
11058  to the beginning and the end of the function body:
11059 \layout Verse
11060
11061
11062 \family typewriter 
11063 \size footnotesize 
11064 /* With a cut and paste from the .asm file, we have something to start with.
11065 \newline 
11066 \SpecialChar ~
11067 \SpecialChar ~
11068 \SpecialChar ~
11069 The function is not yet OK! (registers aren't saved) */ 
11070 \newline 
11071 void to_buffer_asm( unsigned char c ) 
11072 \newline 
11073
11074 \newline 
11075 \SpecialChar ~
11076 \SpecialChar ~
11077 \SpecialChar ~
11078 \SpecialChar ~
11079 _asm
11080 \begin_inset LatexCommand \index{\_asm}
11081
11082 \end_inset 
11083
11084
11085 \newline 
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 \SpecialChar ~
11089 \SpecialChar ~
11090 mov\SpecialChar ~
11091 \SpecialChar ~
11092 r2,dpl 
11093 \newline 
11094 ;buffer.c if( head != tail-1 ) 
11095 \newline 
11096 \SpecialChar ~
11097 \SpecialChar ~
11098 \SpecialChar ~
11099 \SpecialChar ~
11100 mov\SpecialChar ~
11101 \SpecialChar ~
11102 a,_tail 
11103 \newline 
11104 \SpecialChar ~
11105 \SpecialChar ~
11106 \SpecialChar ~
11107 \SpecialChar ~
11108 dec\SpecialChar ~
11109 \SpecialChar ~
11110
11111 \newline 
11112 \SpecialChar ~
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 mov\SpecialChar ~
11117 \SpecialChar ~
11118 r3,a 
11119 \newline 
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 \SpecialChar ~
11124 mov\SpecialChar ~
11125 \SpecialChar ~
11126 a,_head 
11127 \newline 
11128 \SpecialChar ~
11129 \SpecialChar ~
11130 \SpecialChar ~
11131 \SpecialChar ~
11132 cjne a,ar3,00106$ 
11133 \newline 
11134 \SpecialChar ~
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 ret
11139 \newline 
11140 00106$: 
11141 \newline 
11142 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
11143 \begin_inset LatexCommand \index{Aligned array}
11144
11145 \end_inset 
11146
11147
11148 \newline 
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 mov\SpecialChar ~
11154 \SpecialChar ~
11155 r3,_head 
11156 \newline 
11157 \SpecialChar ~
11158 \SpecialChar ~
11159 \SpecialChar ~
11160 \SpecialChar ~
11161 inc\SpecialChar ~
11162 \SpecialChar ~
11163 _head 
11164 \newline 
11165 \SpecialChar ~
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 mov\SpecialChar ~
11170 \SpecialChar ~
11171 dpl,r3 
11172 \newline 
11173 \SpecialChar ~
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 mov\SpecialChar ~
11178 \SpecialChar ~
11179 dph,#(_buf >> 8) 
11180 \newline 
11181 \SpecialChar ~
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 mov\SpecialChar ~
11186 \SpecialChar ~
11187 a,r2 
11188 \newline 
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 \SpecialChar ~
11192 \SpecialChar ~
11193 movx @dptr,a 
11194 \newline 
11195 00103$: 
11196 \newline 
11197 \SpecialChar ~
11198 \SpecialChar ~
11199 \SpecialChar ~
11200 \SpecialChar ~
11201 ret
11202 \newline 
11203 \SpecialChar ~
11204 \SpecialChar ~
11205 \SpecialChar ~
11206 \SpecialChar ~
11207 _endasm;
11208 \newline 
11209
11210 \layout Standard
11211
11212 The new file buffer.c should compile with only one warning about the unreferenced
11213  function argument 'c'.
11214  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
11215  (1) and finally have:
11216 \layout Verse
11217
11218
11219 \family typewriter 
11220 \size footnotesize 
11221 unsigned char far at 0x7f00 buf[0x100];
11222 \newline 
11223 unsigned char head,tail;
11224 \newline 
11225 #define USE_ASSEMBLY (1)
11226 \newline 
11227
11228 \newline 
11229 #if !USE_ASSEMBLY
11230 \newline 
11231
11232 \newline 
11233 void to_buffer( unsigned char c )
11234 \newline 
11235 {
11236 \newline 
11237 \SpecialChar ~
11238 \SpecialChar ~
11239 \SpecialChar ~
11240 \SpecialChar ~
11241 if( head != tail-1 )
11242 \newline 
11243 \SpecialChar ~
11244 \SpecialChar ~
11245 \SpecialChar ~
11246 \SpecialChar ~
11247 \SpecialChar ~
11248 \SpecialChar ~
11249 \SpecialChar ~
11250 \SpecialChar ~
11251 buf[ head++ ] = c;
11252 \newline 
11253 }
11254 \newline 
11255
11256 \newline 
11257 #else
11258 \newline 
11259
11260 \newline 
11261 void to_buffer( unsigned char c )
11262 \newline 
11263 {
11264 \newline 
11265 \SpecialChar ~
11266 \SpecialChar ~
11267 \SpecialChar ~
11268 \SpecialChar ~
11269 c; // to avoid warning: unreferenced function argument
11270 \newline 
11271 \SpecialChar ~
11272 \SpecialChar ~
11273 \SpecialChar ~
11274 \SpecialChar ~
11275 _asm
11276 \begin_inset LatexCommand \index{\_asm}
11277
11278 \end_inset 
11279
11280
11281 \newline 
11282 \SpecialChar ~
11283 \SpecialChar ~
11284 \SpecialChar ~
11285 \SpecialChar ~
11286 \SpecialChar ~
11287 \SpecialChar ~
11288 \SpecialChar ~
11289 \SpecialChar ~
11290 ; save used registers here.
11291  
11292 \newline 
11293 \SpecialChar ~
11294 \SpecialChar ~
11295 \SpecialChar ~
11296 \SpecialChar ~
11297 \SpecialChar ~
11298 \SpecialChar ~
11299 \SpecialChar ~
11300 \SpecialChar ~
11301 ; If we were still using r2,r3 we would have to push them here.
11302  
11303 \newline 
11304 ; if( head != tail-1 )
11305 \newline 
11306 \SpecialChar ~
11307 \SpecialChar ~
11308 \SpecialChar ~
11309 \SpecialChar ~
11310 \SpecialChar ~
11311 \SpecialChar ~
11312 \SpecialChar ~
11313 \SpecialChar ~
11314 mov\SpecialChar ~
11315  a,_tail
11316 \newline 
11317 \SpecialChar ~
11318 \SpecialChar ~
11319 \SpecialChar ~
11320 \SpecialChar ~
11321 \SpecialChar ~
11322 \SpecialChar ~
11323 \SpecialChar ~
11324 \SpecialChar ~
11325 dec\SpecialChar ~
11326  a
11327 \newline 
11328 \SpecialChar ~
11329 \SpecialChar ~
11330 \SpecialChar ~
11331 \SpecialChar ~
11332 \SpecialChar ~
11333 \SpecialChar ~
11334 \SpecialChar ~
11335 \SpecialChar ~
11336 xrl\SpecialChar ~
11337  a,_head
11338 \newline 
11339 \SpecialChar ~
11340 \SpecialChar ~
11341 \SpecialChar ~
11342 \SpecialChar ~
11343 \SpecialChar ~
11344 \SpecialChar ~
11345 \SpecialChar ~
11346 \SpecialChar ~
11347 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11348 \newline 
11349 \SpecialChar ~
11350 \SpecialChar ~
11351 \SpecialChar ~
11352 \SpecialChar ~
11353 \SpecialChar ~
11354 \SpecialChar ~
11355 \SpecialChar ~
11356 \SpecialChar ~
11357 jz\SpecialChar ~
11358 \SpecialChar ~
11359  t_b_end$
11360 \newline 
11361 \SpecialChar ~
11362 \SpecialChar ~
11363 \SpecialChar ~
11364 \SpecialChar ~
11365 \SpecialChar ~
11366 \SpecialChar ~
11367 \SpecialChar ~
11368 \SpecialChar ~
11369 ;
11370 \newline 
11371 ; buf[ head++ ] = c;
11372 \newline 
11373 \SpecialChar ~
11374 \SpecialChar ~
11375 \SpecialChar ~
11376 \SpecialChar ~
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 \SpecialChar ~
11380 \SpecialChar ~
11381 mov\SpecialChar ~
11382  a,dpl \SpecialChar ~
11383 \SpecialChar ~
11384 \SpecialChar ~
11385 \SpecialChar ~
11386 \SpecialChar ~
11387 \SpecialChar ~
11388 \SpecialChar ~
11389 ; dpl holds lower byte of function argument
11390 \newline 
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 \SpecialChar ~
11394 \SpecialChar ~
11395 \SpecialChar ~
11396 \SpecialChar ~
11397 \SpecialChar ~
11398 \SpecialChar ~
11399 mov\SpecialChar ~
11400  dpl,_head \SpecialChar ~
11401 \SpecialChar ~
11402 \SpecialChar ~
11403 ; buf is 0x100 byte aligned so head can be used directly
11404 \newline 
11405 \SpecialChar ~
11406 \SpecialChar ~
11407 \SpecialChar ~
11408 \SpecialChar ~
11409 \SpecialChar ~
11410 \SpecialChar ~
11411 \SpecialChar ~
11412 \SpecialChar ~
11413 mov\SpecialChar ~
11414  dph,#(_buf>>8)
11415 \newline 
11416 \SpecialChar ~
11417 \SpecialChar ~
11418 \SpecialChar ~
11419 \SpecialChar ~
11420 \SpecialChar ~
11421 \SpecialChar ~
11422 \SpecialChar ~
11423 \SpecialChar ~
11424 movx @dptr,a
11425 \newline 
11426 \SpecialChar ~
11427 \SpecialChar ~
11428 \SpecialChar ~
11429 \SpecialChar ~
11430 \SpecialChar ~
11431 \SpecialChar ~
11432 \SpecialChar ~
11433 \SpecialChar ~
11434 inc \SpecialChar ~
11435 _head
11436 \newline 
11437 \SpecialChar ~
11438 \SpecialChar ~
11439 \SpecialChar ~
11440 \SpecialChar ~
11441 \SpecialChar ~
11442 \SpecialChar ~
11443 \SpecialChar ~
11444 \SpecialChar ~
11445 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11446 \newline 
11447 t_b_end$:
11448 \newline 
11449 \SpecialChar ~
11450 \SpecialChar ~
11451 \SpecialChar ~
11452 \SpecialChar ~
11453 \SpecialChar ~
11454 \SpecialChar ~
11455 \SpecialChar ~
11456 \SpecialChar ~
11457 ; restore used registers here 
11458 \newline 
11459 \SpecialChar ~
11460 \SpecialChar ~
11461 \SpecialChar ~
11462 \SpecialChar ~
11463 _endasm;
11464 \newline 
11465 }
11466 \newline 
11467 #endif
11468 \layout Standard
11469
11470 The inline assembler code can contain any valid code understood by the assembler
11471 , this includes any assembler directives and comment lines
11472 \begin_inset Foot
11473 collapsed false
11474
11475 \layout Standard
11476
11477 The assembler does not like some characters like ':' or ''' in comments.
11478  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11479 \end_inset 
11480
11481 .
11482  The compiler does not do any validation of the code within the 
11483 \family typewriter 
11484 _asm
11485 \begin_inset LatexCommand \index{\_asm}
11486
11487 \end_inset 
11488
11489  ...
11490  _endasm;
11491 \family default 
11492  keyword pair.
11493  Specifically it will not know which registers are used and thus register
11494  pushing/popping
11495 \begin_inset LatexCommand \index{push/pop}
11496
11497 \end_inset 
11498
11499  has to be done manually.
11500  
11501 \layout Standard
11502
11503 It is recommended that each assembly instruction (including labels) be placed
11504  in a separate line (as the example shows).
11505  When the -
11506 \begin_inset ERT
11507 status Collapsed
11508
11509 \layout Standard
11510
11511 \backslash 
11512 /
11513 \end_inset 
11514
11515 -
11516 \emph on 
11517 peep-asm
11518 \begin_inset LatexCommand \index{-\/-peep-asm}
11519
11520 \end_inset 
11521
11522
11523 \emph default 
11524  command line option is used, the inline assembler code will be passed through
11525  the peephole optimizer
11526 \begin_inset LatexCommand \index{Peephole optimizer}
11527
11528 \end_inset 
11529
11530 .
11531  There are only a few (if any) cases where this option makes sense, it might
11532  cause some unexpected changes in the inline assembler code.
11533  Please go through the peephole optimizer rules defined in file 
11534 \emph on 
11535 SDCCpeeph.def
11536 \emph default 
11537  before using this option.
11538 \layout Subsection
11539
11540 Naked Functions
11541 \begin_inset LatexCommand \label{sub:Naked-Functions}
11542
11543 \end_inset 
11544
11545
11546 \begin_inset LatexCommand \index{Naked functions}
11547
11548 \end_inset 
11549
11550
11551 \layout Standard
11552
11553 A special keyword may be associated with a function declaring it as 
11554 \emph on 
11555 _naked
11556 \begin_inset LatexCommand \index{\_naked}
11557
11558 \end_inset 
11559
11560 .
11561  
11562 \emph default 
11563 The 
11564 \emph on 
11565 _naked
11566 \emph default 
11567  function modifier attribute prevents the compiler from generating prologue
11568 \begin_inset LatexCommand \index{function prologue}
11569
11570 \end_inset 
11571
11572  and epilogue
11573 \begin_inset LatexCommand \index{function epilogue}
11574
11575 \end_inset 
11576
11577  code for that function.
11578  This means that the user is entirely responsible for such things as saving
11579  any registers that may need to be preserved, selecting the proper register
11580  bank, generating the 
11581 \emph on 
11582 return
11583 \emph default 
11584  instruction at the end, etc.
11585  Practically, this means that the contents of the function must be written
11586  in inline assembler.
11587  This is particularly useful for interrupt functions, which can have a large
11588  (and often unnecessary) prologue/epilogue.
11589  For example, compare the code generated by these two functions:
11590 \layout Verse
11591
11592
11593 \family typewriter 
11594 volatile
11595 \begin_inset LatexCommand \index{volatile}
11596
11597 \end_inset 
11598
11599  data unsigned char counter;
11600 \newline 
11601
11602 \newline 
11603 void simpleInterrupt(void) interrupt
11604 \begin_inset LatexCommand \index{interrupt}
11605
11606 \end_inset 
11607
11608  1
11609 \newline 
11610 {
11611 \newline 
11612 \SpecialChar ~
11613 \SpecialChar ~
11614 \SpecialChar ~
11615 \SpecialChar ~
11616 counter++;
11617 \newline 
11618 }
11619 \newline 
11620
11621 \newline 
11622 void nakedInterrupt(void) interrupt 2 _naked
11623 \newline 
11624 {
11625 \newline 
11626 \SpecialChar ~
11627 \SpecialChar ~
11628 \SpecialChar ~
11629 \SpecialChar ~
11630 _asm
11631 \begin_inset LatexCommand \index{\_asm}
11632
11633 \end_inset 
11634
11635
11636 \newline 
11637 \SpecialChar ~
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 \SpecialChar ~
11642 \SpecialChar ~
11643 inc\SpecialChar ~
11644 \SpecialChar ~
11645 \SpecialChar ~
11646 \SpecialChar ~
11647 \SpecialChar ~
11648 _counter ; does not change flags, no need to save psw
11649 \newline 
11650 \SpecialChar ~
11651 \SpecialChar ~
11652 \SpecialChar ~
11653 \SpecialChar ~
11654 \SpecialChar ~
11655 \SpecialChar ~
11656 reti\SpecialChar ~
11657 \SpecialChar ~
11658 \SpecialChar ~
11659 \SpecialChar ~
11660 ; MUST explicitly include ret or reti in _naked function.
11661 \newline 
11662 \SpecialChar ~
11663 \SpecialChar ~
11664 \SpecialChar ~
11665 \SpecialChar ~
11666 _endasm
11667 \begin_inset LatexCommand \index{\_endasm}
11668
11669 \end_inset 
11670
11671 ;
11672 \newline 
11673 }
11674 \layout Standard
11675
11676 For an 8051 target, the generated simpleInterrupt looks like:
11677 \layout Verse
11678
11679
11680 \family typewriter 
11681 _simpleInterrupt:
11682 \newline 
11683 \SpecialChar ~
11684 \SpecialChar ~
11685 \SpecialChar ~
11686 \SpecialChar ~
11687 push\SpecialChar ~
11688 \SpecialChar ~
11689 \SpecialChar ~
11690 \SpecialChar ~
11691 acc
11692 \newline 
11693 \SpecialChar ~
11694 \SpecialChar ~
11695 \SpecialChar ~
11696 \SpecialChar ~
11697 push\SpecialChar ~
11698 \SpecialChar ~
11699 \SpecialChar ~
11700 \SpecialChar ~
11701 b
11702 \newline 
11703 \SpecialChar ~
11704 \SpecialChar ~
11705 \SpecialChar ~
11706 \SpecialChar ~
11707 push\SpecialChar ~
11708 \SpecialChar ~
11709 \SpecialChar ~
11710 \SpecialChar ~
11711 dpl
11712 \newline 
11713 \SpecialChar ~
11714 \SpecialChar ~
11715 \SpecialChar ~
11716 \SpecialChar ~
11717 push\SpecialChar ~
11718 \SpecialChar ~
11719 \SpecialChar ~
11720 \SpecialChar ~
11721 dph
11722 \newline 
11723 \SpecialChar ~
11724 \SpecialChar ~
11725 \SpecialChar ~
11726 \SpecialChar ~
11727 push\SpecialChar ~
11728 \SpecialChar ~
11729 \SpecialChar ~
11730 \SpecialChar ~
11731 psw
11732 \newline 
11733 \SpecialChar ~
11734 \SpecialChar ~
11735 \SpecialChar ~
11736 \SpecialChar ~
11737 mov\SpecialChar ~
11738 \SpecialChar ~
11739 \SpecialChar ~
11740 \SpecialChar ~
11741 \SpecialChar ~
11742 psw,#0x00
11743 \newline 
11744 \SpecialChar ~
11745 \SpecialChar ~
11746 \SpecialChar ~
11747 \SpecialChar ~
11748 inc\SpecialChar ~
11749 \SpecialChar ~
11750 \SpecialChar ~
11751 \SpecialChar ~
11752 \SpecialChar ~
11753 _counter
11754 \newline 
11755 \SpecialChar ~
11756 \SpecialChar ~
11757 \SpecialChar ~
11758 \SpecialChar ~
11759 pop\SpecialChar ~
11760 \SpecialChar ~
11761 \SpecialChar ~
11762 \SpecialChar ~
11763 \SpecialChar ~
11764 psw
11765 \newline 
11766 \SpecialChar ~
11767 \SpecialChar ~
11768 \SpecialChar ~
11769 \SpecialChar ~
11770 pop\SpecialChar ~
11771 \SpecialChar ~
11772 \SpecialChar ~
11773 \SpecialChar ~
11774 \SpecialChar ~
11775 dph
11776 \newline 
11777 \SpecialChar ~
11778 \SpecialChar ~
11779 \SpecialChar ~
11780 \SpecialChar ~
11781 pop\SpecialChar ~
11782 \SpecialChar ~
11783 \SpecialChar ~
11784 \SpecialChar ~
11785 \SpecialChar ~
11786 dpl
11787 \newline 
11788 \SpecialChar ~
11789 \SpecialChar ~
11790 \SpecialChar ~
11791 \SpecialChar ~
11792 pop\SpecialChar ~
11793 \SpecialChar ~
11794 \SpecialChar ~
11795 \SpecialChar ~
11796 \SpecialChar ~
11797 b
11798 \newline 
11799 \SpecialChar ~
11800 \SpecialChar ~
11801 \SpecialChar ~
11802 \SpecialChar ~
11803 pop\SpecialChar ~
11804 \SpecialChar ~
11805 \SpecialChar ~
11806 \SpecialChar ~
11807 \SpecialChar ~
11808 acc
11809 \newline 
11810 \SpecialChar ~
11811 \SpecialChar ~
11812 \SpecialChar ~
11813 \SpecialChar ~
11814 reti
11815 \layout Standard
11816
11817 whereas nakedInterrupt looks like:
11818 \layout Verse
11819
11820
11821 \family typewriter 
11822 _nakedInterrupt:
11823 \newline 
11824 \SpecialChar ~
11825 \SpecialChar ~
11826 \SpecialChar ~
11827 \SpecialChar ~
11828 inc\SpecialChar ~
11829 \SpecialChar ~
11830 \SpecialChar ~
11831 \SpecialChar ~
11832 _counter ; does not change flags, no need to save psw
11833 \newline 
11834 \SpecialChar ~
11835 \SpecialChar ~
11836 \SpecialChar ~
11837 \SpecialChar ~
11838 reti\SpecialChar ~
11839 \SpecialChar ~
11840 \SpecialChar ~
11841 \SpecialChar ~
11842 \SpecialChar ~
11843 \SpecialChar ~
11844 \SpecialChar ~
11845 \SpecialChar ~
11846 \SpecialChar ~
11847 \SpecialChar ~
11848 \SpecialChar ~
11849 \SpecialChar ~
11850 ; MUST explicitly include ret or reti in _naked function
11851 \layout Standard
11852
11853 The related directive #pragma exclude
11854 \begin_inset LatexCommand \index{\#pragma exclude}
11855
11856 \end_inset 
11857
11858  allows a more fine grained control over pushing & popping
11859 \begin_inset LatexCommand \index{push/pop}
11860
11861 \end_inset 
11862
11863  the registers.
11864 \layout Standard
11865
11866 While there is nothing preventing you from writing C code inside a 
11867 \family typewriter 
11868 _naked
11869 \family default 
11870  function, there are many ways to shoot yourself in the foot doing this,
11871  and it is recommended that you stick to inline assembler.
11872 \layout Subsection
11873
11874 Use of Labels within Inline Assembler
11875 \layout Standard
11876
11877 SDCC allows the use of in-line assembler with a few restrictions regarding
11878  labels.
11879  In older versions of the compiler all labels defined within inline assembler
11880  code 
11881 \emph on 
11882 had to be
11883 \emph default 
11884  of the form 
11885 \emph on 
11886 nnnnn$
11887 \emph default 
11888  where nnnn is a number less than 100 (which implies a limit of utmost 100
11889  inline assembler labels 
11890 \emph on 
11891 per function
11892 \emph default 
11893 \noun on 
11894 )
11895 \noun default 
11896 .
11897  
11898 \layout Verse
11899
11900
11901 \family typewriter 
11902 _asm
11903 \begin_inset LatexCommand \index{\_asm}
11904
11905 \end_inset 
11906
11907  
11908 \newline 
11909 \SpecialChar ~
11910 \SpecialChar ~
11911 \SpecialChar ~
11912 \SpecialChar ~
11913 mov\SpecialChar ~
11914 \SpecialChar ~
11915 \SpecialChar ~
11916 \SpecialChar ~
11917 \SpecialChar ~
11918 b,#10 
11919 \newline 
11920 00001$: 
11921 \newline 
11922 \SpecialChar ~
11923 \SpecialChar ~
11924 \SpecialChar ~
11925 \SpecialChar ~
11926 djnz\SpecialChar ~
11927 \SpecialChar ~
11928 \SpecialChar ~
11929 \SpecialChar ~
11930 b,00001$ 
11931 \newline 
11932 _endasm
11933 \begin_inset LatexCommand \index{\_endasm}
11934
11935 \end_inset 
11936
11937  ;
11938 \layout Standard
11939
11940 Inline assembler code cannot reference any C-Labels, however it can reference
11941  labels
11942 \begin_inset LatexCommand \index{Labels}
11943
11944 \end_inset 
11945
11946  defined by the inline assembler, e.g.:
11947 \layout Verse
11948
11949
11950 \family typewriter 
11951 foo() { 
11952 \newline 
11953 \SpecialChar ~
11954 \SpecialChar ~
11955 \SpecialChar ~
11956 \SpecialChar ~
11957 /* some c code */ 
11958 \newline 
11959 \SpecialChar ~
11960 \SpecialChar ~
11961 \SpecialChar ~
11962 \SpecialChar ~
11963 _asm 
11964 \newline 
11965 \SpecialChar ~
11966 \SpecialChar ~
11967 \SpecialChar ~
11968 \SpecialChar ~
11969 \SpecialChar ~
11970 \SpecialChar ~
11971 ; some assembler code 
11972 \newline 
11973 \SpecialChar ~
11974 \SpecialChar ~
11975 \SpecialChar ~
11976 \SpecialChar ~
11977 \SpecialChar ~
11978 \SpecialChar ~
11979 ljmp $0003 
11980 \newline 
11981 \SpecialChar ~
11982 \SpecialChar ~
11983 \SpecialChar ~
11984 \SpecialChar ~
11985 _endasm; 
11986 \newline 
11987 \SpecialChar ~
11988 \SpecialChar ~
11989 \SpecialChar ~
11990 \SpecialChar ~
11991 /* some more c code */ 
11992 \newline 
11993 clabel:\SpecialChar ~
11994 \SpecialChar ~
11995 /* inline assembler cannot reference this label */ 
11996 \newline 
11997 \SpecialChar ~
11998 \SpecialChar ~
11999 \SpecialChar ~
12000 \SpecialChar ~
12001 _asm
12002 \newline 
12003 \SpecialChar ~
12004 \SpecialChar ~
12005 \SpecialChar ~
12006 \SpecialChar ~
12007 $0003: ;label (can be referenced by inline assembler only) 
12008 \newline 
12009 \SpecialChar ~
12010 \SpecialChar ~
12011 \SpecialChar ~
12012 \SpecialChar ~
12013 _endasm ; 
12014 \newline 
12015 \SpecialChar ~
12016 \SpecialChar ~
12017 \SpecialChar ~
12018 \SpecialChar ~
12019 /* some more c code */
12020 \newline 
12021 }
12022 \layout Standard
12023
12024 In other words inline assembly code can access labels defined in inline
12025  assembly within the scope of the function.
12026  The same goes the other way, i.e.
12027  labels defines in inline assembly can not be accessed by C statements.
12028 \layout Section
12029
12030 Interfacing with Assembler Code
12031 \begin_inset LatexCommand \index{Assembler routines}
12032
12033 \end_inset 
12034
12035
12036 \layout Subsection
12037
12038 Global Registers used for Parameter Passing
12039 \begin_inset LatexCommand \index{Parameter passing}
12040
12041 \end_inset 
12042
12043
12044 \layout Standard
12045
12046 The compiler always uses the global registers 
12047 \emph on 
12048 DPL, DPH
12049 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12050
12051 \end_inset 
12052
12053
12054 \begin_inset LatexCommand \index{DPTR}
12055
12056 \end_inset 
12057
12058 , B
12059 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
12060
12061 \end_inset 
12062
12063  
12064 \emph default 
12065 and
12066 \emph on 
12067  ACC
12068 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
12069
12070 \end_inset 
12071
12072
12073 \emph default 
12074  to pass the first parameter to a routine.
12075  The second parameter onwards is either allocated on the stack (for reentrant
12076  routines or if -
12077 \begin_inset ERT
12078 status Collapsed
12079
12080 \layout Standard
12081
12082 \backslash 
12083 /
12084 \end_inset 
12085
12086 -stack-auto is used) or in data / xdata memory (depending on the memory
12087  model).
12088  
12089 \layout Subsection
12090
12091 Assembler Routine (non-reentrant)
12092 \layout Standard
12093
12094 In the following example
12095 \begin_inset LatexCommand \index{reentrant}
12096
12097 \end_inset 
12098
12099
12100 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12101
12102 \end_inset 
12103
12104  the function c_func calls an assembler routine asm_func, which takes two
12105  parameters
12106 \begin_inset LatexCommand \index{function parameter}
12107
12108 \end_inset 
12109
12110 .
12111 \layout Verse
12112
12113
12114 \family typewriter 
12115 extern int asm_func(unsigned char, unsigned char);
12116 \newline 
12117
12118 \newline 
12119 int c_func (unsigned char i, unsigned char j)
12120 \newline 
12121 {
12122 \newline 
12123 \SpecialChar ~
12124 \SpecialChar ~
12125 \SpecialChar ~
12126 \SpecialChar ~
12127 return asm_func(i,j);
12128 \newline 
12129 }
12130 \newline 
12131
12132 \newline 
12133 int main()
12134 \newline 
12135 {
12136 \newline 
12137 \SpecialChar ~
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 \SpecialChar ~
12141 return c_func(10,9);
12142 \newline 
12143 }
12144 \layout Standard
12145
12146 The corresponding assembler function is:
12147 \layout Verse
12148
12149
12150 \family typewriter 
12151 .globl _asm_func_PARM_2 
12152 \newline 
12153 \SpecialChar ~
12154 \SpecialChar ~
12155 \SpecialChar ~
12156 \SpecialChar ~
12157 \SpecialChar ~
12158 \SpecialChar ~
12159 \SpecialChar ~
12160 \SpecialChar ~
12161 .globl _asm_func 
12162 \newline 
12163 \SpecialChar ~
12164 \SpecialChar ~
12165 \SpecialChar ~
12166 \SpecialChar ~
12167 \SpecialChar ~
12168 \SpecialChar ~
12169 \SpecialChar ~
12170 \SpecialChar ~
12171 .area OSEG 
12172 \newline 
12173 _asm_func_PARM_2:
12174 \newline 
12175 \SpecialChar ~
12176 \SpecialChar ~
12177 \SpecialChar ~
12178 \SpecialChar ~
12179 \SpecialChar ~
12180 \SpecialChar ~
12181 \SpecialChar ~
12182 \SpecialChar ~
12183 .ds    1 
12184 \newline 
12185 \SpecialChar ~
12186 \SpecialChar ~
12187 \SpecialChar ~
12188 \SpecialChar ~
12189 \SpecialChar ~
12190 \SpecialChar ~
12191 \SpecialChar ~
12192 \SpecialChar ~
12193 .area CSEG 
12194 \newline 
12195 _asm_func: 
12196 \newline 
12197 \SpecialChar ~
12198 \SpecialChar ~
12199 \SpecialChar ~
12200 \SpecialChar ~
12201 \SpecialChar ~
12202 \SpecialChar ~
12203 \SpecialChar ~
12204 \SpecialChar ~
12205 mov\SpecialChar ~
12206 \SpecialChar ~
12207 \SpecialChar ~
12208 \SpecialChar ~
12209 a,dpl 
12210 \newline 
12211 \SpecialChar ~
12212 \SpecialChar ~
12213 \SpecialChar ~
12214 \SpecialChar ~
12215 \SpecialChar ~
12216 \SpecialChar ~
12217 \SpecialChar ~
12218 \SpecialChar ~
12219 add\SpecialChar ~
12220 \SpecialChar ~
12221 \SpecialChar ~
12222 \SpecialChar ~
12223 a,_asm_func_PARM_2 
12224 \newline 
12225 \SpecialChar ~
12226 \SpecialChar ~
12227 \SpecialChar ~
12228 \SpecialChar ~
12229 \SpecialChar ~
12230 \SpecialChar ~
12231 \SpecialChar ~
12232 \SpecialChar ~
12233 mov\SpecialChar ~
12234 \SpecialChar ~
12235 \SpecialChar ~
12236 \SpecialChar ~
12237 dpl,a 
12238 \newline 
12239 \SpecialChar ~
12240 \SpecialChar ~
12241 \SpecialChar ~
12242 \SpecialChar ~
12243 \SpecialChar ~
12244 \SpecialChar ~
12245 \SpecialChar ~
12246 \SpecialChar ~
12247 mov\SpecialChar ~
12248 \SpecialChar ~
12249 \SpecialChar ~
12250 \SpecialChar ~
12251 dph
12252 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12253
12254 \end_inset 
12255
12256 ,#0x00 
12257 \newline 
12258 \SpecialChar ~
12259 \SpecialChar ~
12260 \SpecialChar ~
12261 \SpecialChar ~
12262 \SpecialChar ~
12263 \SpecialChar ~
12264 \SpecialChar ~
12265 \SpecialChar ~
12266 ret
12267 \layout Standard
12268
12269 Note here that the return values
12270 \begin_inset LatexCommand \index{return value}
12271
12272 \end_inset 
12273
12274  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
12275  two byte values.
12276  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12277 b' & 'acc' for four byte values.
12278 \layout Standard
12279
12280 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12281  the parameter number starting from 1, and counting from the left.
12282  The first parameter is passed in 
12283 \begin_inset Quotes eld
12284 \end_inset 
12285
12286 dpl
12287 \begin_inset Quotes erd
12288 \end_inset 
12289
12290  for a one byte parameter, 
12291 \begin_inset Quotes eld
12292 \end_inset 
12293
12294 dptr
12295 \begin_inset Quotes erd
12296 \end_inset 
12297
12298  for two bytes, 
12299 \begin_inset Quotes eld
12300 \end_inset 
12301
12302 b,dptr
12303 \begin_inset Quotes erd
12304 \end_inset 
12305
12306  for three bytes and 
12307 \begin_inset Quotes eld
12308 \end_inset 
12309
12310 acc,b,dptr
12311 \begin_inset Quotes erd
12312 \end_inset 
12313
12314  for a four bytes parameter.
12315  The variable name for the second parameter will be _<function_name>_PARM_2.
12316 \newline 
12317
12318 \newline 
12319 Assemble the assembler routine with the following command:
12320 \newline 
12321
12322 \newline 
12323
12324 \family sans 
12325 \series bold 
12326 asx8051 -losg asmfunc.asm
12327 \newline 
12328
12329 \newline 
12330
12331 \family default 
12332 \series default 
12333 Then compile and link the assembler routine to the C source file with the
12334  following command:
12335 \newline 
12336
12337 \newline 
12338
12339 \family sans 
12340 \series bold 
12341 sdcc cfunc.c asmfunc.rel
12342 \layout Subsection
12343
12344 Assembler Routine (reentrant)
12345 \layout Standard
12346
12347 In this case
12348 \begin_inset LatexCommand \index{reentrant}
12349
12350 \end_inset 
12351
12352
12353 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12354
12355 \end_inset 
12356
12357  the second parameter
12358 \begin_inset LatexCommand \index{function parameter}
12359
12360 \end_inset 
12361
12362  onwards will be passed on the stack, the parameters are pushed from right
12363  to left i.e.
12364  after the call the leftmost parameter will be on the top of the stack.
12365  Here is an example:
12366 \layout Verse
12367
12368
12369 \family typewriter 
12370 extern int asm_func(unsigned char, unsigned char);
12371 \newline 
12372
12373 \newline 
12374 int c_func (unsigned char i, unsigned char j) reentrant 
12375 \newline 
12376
12377 \newline 
12378 \SpecialChar ~
12379 \SpecialChar ~
12380 \SpecialChar ~
12381 \SpecialChar ~
12382 return asm_func(i,j); 
12383 \newline 
12384
12385 \newline 
12386
12387 \newline 
12388 int main() 
12389 \newline 
12390
12391 \newline 
12392 \SpecialChar ~
12393 \SpecialChar ~
12394 \SpecialChar ~
12395 \SpecialChar ~
12396 return c_func(10,9); 
12397 \newline 
12398 }
12399 \layout Standard
12400
12401 The corresponding assembler routine is:
12402 \layout Verse
12403
12404
12405 \family typewriter 
12406 .globl _asm_func 
12407 \newline 
12408 _asm_func: 
12409 \newline 
12410 \SpecialChar ~
12411 \SpecialChar ~
12412 \SpecialChar ~
12413 \SpecialChar ~
12414 push  _bp 
12415 \newline 
12416 \SpecialChar ~
12417 \SpecialChar ~
12418 \SpecialChar ~
12419 \SpecialChar ~
12420 mov _bp,sp 
12421 \newline 
12422 \SpecialChar ~
12423 \SpecialChar ~
12424 \SpecialChar ~
12425 \SpecialChar ~
12426 mov r2,dpl
12427 \newline 
12428 \SpecialChar ~
12429 \SpecialChar ~
12430 \SpecialChar ~
12431 \SpecialChar ~
12432 mov a,_bp 
12433 \newline 
12434 \SpecialChar ~
12435 \SpecialChar ~
12436 \SpecialChar ~
12437 \SpecialChar ~
12438 add a,#0xfd 
12439 \newline 
12440 \SpecialChar ~
12441 \SpecialChar ~
12442 \SpecialChar ~
12443 \SpecialChar ~
12444 mov r0,a 
12445 \newline 
12446 \SpecialChar ~
12447 \SpecialChar ~
12448 \SpecialChar ~
12449 \SpecialChar ~
12450 add  a,#0xfc ;?
12451 \newline 
12452 \SpecialChar ~
12453 \SpecialChar ~
12454 \SpecialChar ~
12455 \SpecialChar ~
12456 mov  r1,a 
12457 \newline 
12458 \SpecialChar ~
12459 \SpecialChar ~
12460 \SpecialChar ~
12461 \SpecialChar ~
12462 mov  a,@r0 
12463 \newline 
12464 \SpecialChar ~
12465 \SpecialChar ~
12466 \SpecialChar ~
12467 \SpecialChar ~
12468 add  a,r2 ;?
12469 \newline 
12470 \SpecialChar ~
12471 \SpecialChar ~
12472 \SpecialChar ~
12473 \SpecialChar ~
12474 mov  dpl,a 
12475 \newline 
12476 \SpecialChar ~
12477 \SpecialChar ~
12478 \SpecialChar ~
12479 \SpecialChar ~
12480 mov  dph,#0x00 
12481 \newline 
12482 \SpecialChar ~
12483 \SpecialChar ~
12484 \SpecialChar ~
12485 \SpecialChar ~
12486 mov  sp,_bp 
12487 \newline 
12488 \SpecialChar ~
12489 \SpecialChar ~
12490 \SpecialChar ~
12491 \SpecialChar ~
12492 pop  _bp 
12493 \newline 
12494 \SpecialChar ~
12495 \SpecialChar ~
12496 \SpecialChar ~
12497 \SpecialChar ~
12498 ret
12499 \layout Standard
12500
12501 The compiling and linking procedure remains the same, however note the extra
12502  entry & exit linkage required for the assembler code, _bp is the stack
12503  frame pointer and is used to compute the offset into the stack for parameters
12504  and local variables.
12505 \layout Section
12506
12507 int (16 bit)
12508 \begin_inset LatexCommand \index{int (16 bit)}
12509
12510 \end_inset 
12511
12512  and long (32 bit)
12513 \begin_inset LatexCommand \index{long (32 bit)}
12514
12515 \end_inset 
12516
12517  Support
12518 \layout Standard
12519
12520 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12521  multiplication and modulus operations are implemented by support routines.
12522  These support routines are all developed in ANSI-C to facilitate porting
12523  to other MCUs, although some model specific assembler optimizations are
12524  used.
12525  The following files contain the described routines, all of them can be
12526  found in <installdir>/share/sdcc/lib.
12527 \newline 
12528
12529 \layout Standard
12530 \align center 
12531
12532 \begin_inset  Tabular
12533 <lyxtabular version="3" rows="11" columns="2">
12534 <features>
12535 <column alignment="center" valignment="top" leftline="true" width="0">
12536 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12537 <row topline="true" bottomline="true">
12538 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12539 \begin_inset Text
12540
12541 \layout Standard
12542
12543
12544 \series bold 
12545 Function
12546 \end_inset 
12547 </cell>
12548 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12549 \begin_inset Text
12550
12551 \layout Standard
12552
12553
12554 \series bold 
12555 Description
12556 \end_inset 
12557 </cell>
12558 </row>
12559 <row topline="true">
12560 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12561 \begin_inset Text
12562
12563 \layout Standard
12564
12565 _mulint.c 
12566 \end_inset 
12567 </cell>
12568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12569 \begin_inset Text
12570
12571 \layout Standard
12572
12573 16 bit multiplication
12574 \end_inset 
12575 </cell>
12576 </row>
12577 <row topline="true">
12578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12579 \begin_inset Text
12580
12581 \layout Standard
12582
12583 _divsint.c 
12584 \end_inset 
12585 </cell>
12586 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12587 \begin_inset Text
12588
12589 \layout Standard
12590
12591  signed 16 bit division (calls _divuint)
12592 \end_inset 
12593 </cell>
12594 </row>
12595 <row topline="true">
12596 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12597 \begin_inset Text
12598
12599 \layout Standard
12600
12601 _divuint.c 
12602 \end_inset 
12603 </cell>
12604 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12605 \begin_inset Text
12606
12607 \layout Standard
12608
12609  unsigned 16 bit division
12610 \end_inset 
12611 </cell>
12612 </row>
12613 <row topline="true">
12614 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12615 \begin_inset Text
12616
12617 \layout Standard
12618
12619 _modsint.c
12620 \end_inset 
12621 </cell>
12622 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12623 \begin_inset Text
12624
12625 \layout Standard
12626
12627 signed 16 bit modulus (calls _moduint)
12628 \end_inset 
12629 </cell>
12630 </row>
12631 <row topline="true">
12632 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12633 \begin_inset Text
12634
12635 \layout Standard
12636
12637 _moduint.c
12638 \end_inset 
12639 </cell>
12640 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12641 \begin_inset Text
12642
12643 \layout Standard
12644
12645 unsigned 16 bit modulus
12646 \end_inset 
12647 </cell>
12648 </row>
12649 <row topline="true">
12650 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12651 \begin_inset Text
12652
12653 \layout Standard
12654
12655 _mullong.c
12656 \end_inset 
12657 </cell>
12658 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12659 \begin_inset Text
12660
12661 \layout Standard
12662
12663 32 bit multiplication
12664 \end_inset 
12665 </cell>
12666 </row>
12667 <row topline="true">
12668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12669 \begin_inset Text
12670
12671 \layout Standard
12672
12673 _divslong.c 
12674 \end_inset 
12675 </cell>
12676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12677 \begin_inset Text
12678
12679 \layout Standard
12680
12681  signed 32 division (calls _divulong)
12682 \end_inset 
12683 </cell>
12684 </row>
12685 <row topline="true">
12686 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12687 \begin_inset Text
12688
12689 \layout Standard
12690
12691 _divulong.c 
12692 \end_inset 
12693 </cell>
12694 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12695 \begin_inset Text
12696
12697 \layout Standard
12698
12699 unsigned 32 division
12700 \end_inset 
12701 </cell>
12702 </row>
12703 <row topline="true">
12704 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12705 \begin_inset Text
12706
12707 \layout Standard
12708
12709 _modslong.c
12710 \end_inset 
12711 </cell>
12712 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12713 \begin_inset Text
12714
12715 \layout Standard
12716
12717  signed 32 bit modulus (calls _modulong)
12718 \end_inset 
12719 </cell>
12720 </row>
12721 <row topline="true" bottomline="true">
12722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12723 \begin_inset Text
12724
12725 \layout Standard
12726
12727 _modulong.c
12728 \end_inset 
12729 </cell>
12730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12731 \begin_inset Text
12732
12733 \layout Standard
12734
12735 unsigned 32 bit modulus
12736 \end_inset 
12737 </cell>
12738 </row>
12739 </lyxtabular>
12740
12741 \end_inset 
12742
12743
12744 \newline 
12745
12746 \layout Standard
12747
12748 Since they are compiled as 
12749 \emph on 
12750 non-reentrant
12751 \emph default 
12752
12753 \begin_inset LatexCommand \index{reentrant}
12754
12755 \end_inset 
12756
12757 , interrupt
12758 \begin_inset LatexCommand \index{interrupt}
12759
12760 \end_inset 
12761
12762  service routines should not do any of the above operations.
12763  If this is unavoidable then the above routines will need to be compiled
12764  with the 
12765 \emph on 
12766 -
12767 \begin_inset ERT
12768 status Collapsed
12769
12770 \layout Standard
12771
12772 \backslash 
12773 /
12774 \end_inset 
12775
12776 -stack-auto
12777 \begin_inset LatexCommand \index{-\/-stack-auto}
12778
12779 \end_inset 
12780
12781
12782 \emph default 
12783  option, after which the source program will have to be compiled with 
12784 \emph on 
12785 -
12786 \begin_inset ERT
12787 status Collapsed
12788
12789 \layout Standard
12790
12791 \backslash 
12792 /
12793 \end_inset 
12794
12795 -int-long-reent
12796 \begin_inset LatexCommand \index{-\/-int-long-reent}
12797
12798 \end_inset 
12799
12800
12801 \emph default 
12802  option.
12803  Notice that you don't have to call these routines directly.
12804  The compiler will use them automatically every time an integer operation
12805  is required.
12806 \layout Section
12807
12808 Floating Point Support
12809 \begin_inset LatexCommand \index{Floating point support}
12810
12811 \end_inset 
12812
12813
12814 \layout Standard
12815
12816 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12817  floating point support routines are derived from gcc's floatlib.c and consist
12818  of the following routines:
12819 \newline 
12820
12821 \layout Standard
12822 \align center 
12823
12824 \size footnotesize 
12825
12826 \begin_inset  Tabular
12827 <lyxtabular version="3" rows="17" columns="2">
12828 <features>
12829 <column alignment="center" valignment="top" leftline="true" width="0">
12830 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12831 <row topline="true" bottomline="true">
12832 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12833 \begin_inset Text
12834
12835 \layout Standard
12836
12837
12838 \family roman 
12839 \series medium 
12840 \shape up 
12841 \size normal 
12842 \emph off 
12843 \bar no 
12844 \noun off 
12845 \color none
12846 Function 
12847 \end_inset 
12848 </cell>
12849 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12850 \begin_inset Text
12851
12852 \layout Standard
12853
12854 Description
12855 \end_inset 
12856 </cell>
12857 </row>
12858 <row topline="true">
12859 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12860 \begin_inset Text
12861
12862 \layout Standard
12863
12864
12865 \family roman 
12866 \series medium 
12867 \shape up 
12868 \size normal 
12869 \emph off 
12870 \bar no 
12871 \noun off 
12872 \color none
12873 _fsadd.c
12874 \end_inset 
12875 </cell>
12876 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12877 \begin_inset Text
12878
12879 \layout Standard
12880
12881
12882 \family roman 
12883 \series medium 
12884 \shape up 
12885 \size normal 
12886 \emph off 
12887 \bar no 
12888 \noun off 
12889 \color none
12890 add floating point numbers
12891 \end_inset 
12892 </cell>
12893 </row>
12894 <row topline="true">
12895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12896 \begin_inset Text
12897
12898 \layout Standard
12899
12900
12901 \family roman 
12902 \series medium 
12903 \shape up 
12904 \size normal 
12905 \emph off 
12906 \bar no 
12907 \noun off 
12908 \color none
12909 _fssub.c 
12910 \end_inset 
12911 </cell>
12912 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12913 \begin_inset Text
12914
12915 \layout Standard
12916
12917
12918 \family roman 
12919 \series medium 
12920 \shape up 
12921 \size normal 
12922 \emph off 
12923 \bar no 
12924 \noun off 
12925 \color none
12926 subtract floating point numbers 
12927 \end_inset 
12928 </cell>
12929 </row>
12930 <row topline="true">
12931 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12932 \begin_inset Text
12933
12934 \layout Standard
12935
12936
12937 \family roman 
12938 \series medium 
12939 \shape up 
12940 \size normal 
12941 \emph off 
12942 \bar no 
12943 \noun off 
12944 \color none
12945 _fsdiv.c 
12946 \end_inset 
12947 </cell>
12948 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12949 \begin_inset Text
12950
12951 \layout Standard
12952
12953
12954 \family roman 
12955 \series medium 
12956 \shape up 
12957 \size normal 
12958 \emph off 
12959 \bar no 
12960 \noun off 
12961 \color none
12962 divide floating point numbers 
12963 \end_inset 
12964 </cell>
12965 </row>
12966 <row topline="true">
12967 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12968 \begin_inset Text
12969
12970 \layout Standard
12971
12972
12973 \family roman 
12974 \series medium 
12975 \shape up 
12976 \size normal 
12977 \emph off 
12978 \bar no 
12979 \noun off 
12980 \color none
12981 _fsmul.c 
12982 \end_inset 
12983 </cell>
12984 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12985 \begin_inset Text
12986
12987 \layout Standard
12988
12989
12990 \family roman 
12991 \series medium 
12992 \shape up 
12993 \size normal 
12994 \emph off 
12995 \bar no 
12996 \noun off 
12997 \color none
12998 multiply floating point numbers 
12999 \end_inset 
13000 </cell>
13001 </row>
13002 <row topline="true">
13003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13004 \begin_inset Text
13005
13006 \layout Standard
13007
13008
13009 \family roman 
13010 \series medium 
13011 \shape up 
13012 \size normal 
13013 \emph off 
13014 \bar no 
13015 \noun off 
13016 \color none
13017 _fs2uchar.c
13018 \end_inset 
13019 </cell>
13020 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13021 \begin_inset Text
13022
13023 \layout Standard
13024
13025
13026 \family roman 
13027 \series medium 
13028 \shape up 
13029 \size normal 
13030 \emph off 
13031 \bar no 
13032 \noun off 
13033 \color none
13034 convert floating point to unsigned char
13035 \end_inset 
13036 </cell>
13037 </row>
13038 <row topline="true">
13039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13040 \begin_inset Text
13041
13042 \layout Standard
13043
13044
13045 \family roman 
13046 \series medium 
13047 \shape up 
13048 \size normal 
13049 \emph off 
13050 \bar no 
13051 \noun off 
13052 \color none
13053 _fs2char.c
13054 \end_inset 
13055 </cell>
13056 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13057 \begin_inset Text
13058
13059 \layout Standard
13060
13061
13062 \family roman 
13063 \series medium 
13064 \shape up 
13065 \size normal 
13066 \emph off 
13067 \bar no 
13068 \noun off 
13069 \color none
13070 convert floating point to signed char
13071 \end_inset 
13072 </cell>
13073 </row>
13074 <row topline="true">
13075 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13076 \begin_inset Text
13077
13078 \layout Standard
13079
13080
13081 \family roman 
13082 \series medium 
13083 \shape up 
13084 \size normal 
13085 \emph off 
13086 \bar no 
13087 \noun off 
13088 \color none
13089 _fs2uint.c
13090 \end_inset 
13091 </cell>
13092 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13093 \begin_inset Text
13094
13095 \layout Standard
13096
13097
13098 \family roman 
13099 \series medium 
13100 \shape up 
13101 \size normal 
13102 \emph off 
13103 \bar no 
13104 \noun off 
13105 \color none
13106 convert floating point to unsigned int
13107 \end_inset 
13108 </cell>
13109 </row>
13110 <row topline="true">
13111 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13112 \begin_inset Text
13113
13114 \layout Standard
13115
13116
13117 \family roman 
13118 \series medium 
13119 \shape up 
13120 \size normal 
13121 \emph off 
13122 \bar no 
13123 \noun off 
13124 \color none
13125 _fs2int.c
13126 \end_inset 
13127 </cell>
13128 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13129 \begin_inset Text
13130
13131 \layout Standard
13132
13133
13134 \family roman 
13135 \series medium 
13136 \shape up 
13137 \size normal 
13138 \emph off 
13139 \bar no 
13140 \noun off 
13141 \color none
13142 convert floating point to signed int
13143 \end_inset 
13144 </cell>
13145 </row>
13146 <row topline="true">
13147 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13148 \begin_inset Text
13149
13150 \layout Standard
13151
13152
13153 \family roman 
13154 \series medium 
13155 \shape up 
13156 \size normal 
13157 \emph off 
13158 \bar no 
13159 \noun off 
13160 \color none
13161 _fs2ulong.
13162 \family default 
13163 \series default 
13164 \shape default 
13165 \size default 
13166 \emph default 
13167 \bar default 
13168 \noun default 
13169 \color default
13170 c
13171 \end_inset 
13172 </cell>
13173 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13174 \begin_inset Text
13175
13176 \layout Standard
13177
13178
13179 \family roman 
13180 \series medium 
13181 \shape up 
13182 \size normal 
13183 \emph off 
13184 \bar no 
13185 \noun off 
13186 \color none
13187 convert floating point to unsigned long
13188 \end_inset 
13189 </cell>
13190 </row>
13191 <row topline="true">
13192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13193 \begin_inset Text
13194
13195 \layout Standard
13196
13197
13198 \family roman 
13199 \series medium 
13200 \shape up 
13201 \size normal 
13202 \emph off 
13203 \bar no 
13204 \noun off 
13205 \color none
13206 _fs2long.c
13207 \end_inset 
13208 </cell>
13209 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13210 \begin_inset Text
13211
13212 \layout Standard
13213
13214
13215 \family roman 
13216 \series medium 
13217 \shape up 
13218 \size normal 
13219 \emph off 
13220 \bar no 
13221 \noun off 
13222 \color none
13223 convert floating point to signed long
13224 \end_inset 
13225 </cell>
13226 </row>
13227 <row topline="true">
13228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13229 \begin_inset Text
13230
13231 \layout Standard
13232
13233
13234 \family roman 
13235 \series medium 
13236 \shape up 
13237 \size normal 
13238 \emph off 
13239 \bar no 
13240 \noun off 
13241 \color none
13242 _uchar2fs.c
13243 \end_inset 
13244 </cell>
13245 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13246 \begin_inset Text
13247
13248 \layout Standard
13249
13250
13251 \family roman 
13252 \series medium 
13253 \shape up 
13254 \size normal 
13255 \emph off 
13256 \bar no 
13257 \noun off 
13258 \color none
13259 convert unsigned char to floating point
13260 \end_inset 
13261 </cell>
13262 </row>
13263 <row topline="true">
13264 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13265 \begin_inset Text
13266
13267 \layout Standard
13268
13269
13270 \family roman 
13271 \series medium 
13272 \shape up 
13273 \size normal 
13274 \emph off 
13275 \bar no 
13276 \noun off 
13277 \color none
13278 _char2fs.c
13279 \end_inset 
13280 </cell>
13281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13282 \begin_inset Text
13283
13284 \layout Standard
13285
13286
13287 \family roman 
13288 \series medium 
13289 \shape up 
13290 \size normal 
13291 \emph off 
13292 \bar no 
13293 \noun off 
13294 \color none
13295 convert char to floating point number
13296 \end_inset 
13297 </cell>
13298 </row>
13299 <row topline="true">
13300 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13301 \begin_inset Text
13302
13303 \layout Standard
13304
13305
13306 \family roman 
13307 \series medium 
13308 \shape up 
13309 \size normal 
13310 \emph off 
13311 \bar no 
13312 \noun off 
13313 \color none
13314 _uint2fs.c
13315 \end_inset 
13316 </cell>
13317 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13318 \begin_inset Text
13319
13320 \layout Standard
13321
13322
13323 \family roman 
13324 \series medium 
13325 \shape up 
13326 \size normal 
13327 \emph off 
13328 \bar no 
13329 \noun off 
13330 \color none
13331 convert unsigned int to floating point
13332 \end_inset 
13333 </cell>
13334 </row>
13335 <row topline="true">
13336 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13337 \begin_inset Text
13338
13339 \layout Standard
13340
13341
13342 \family roman 
13343 \series medium 
13344 \shape up 
13345 \size normal 
13346 \emph off 
13347 \bar no 
13348 \noun off 
13349 \color none
13350 _int2fs.c
13351 \end_inset 
13352 </cell>
13353 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13354 \begin_inset Text
13355
13356 \layout Standard
13357
13358
13359 \family roman 
13360 \series medium 
13361 \shape up 
13362 \size normal 
13363 \emph off 
13364 \bar no 
13365 \noun off 
13366 \color none
13367 convert int to floating point numbers
13368 \end_inset 
13369 </cell>
13370 </row>
13371 <row topline="true">
13372 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13373 \begin_inset Text
13374
13375 \layout Standard
13376
13377
13378 \family roman 
13379 \series medium 
13380 \shape up 
13381 \size normal 
13382 \emph off 
13383 \bar no 
13384 \noun off 
13385 \color none
13386 _ulong2fs.c
13387 \end_inset 
13388 </cell>
13389 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13390 \begin_inset Text
13391
13392 \layout Standard
13393
13394
13395 \family roman 
13396 \series medium 
13397 \shape up 
13398 \size normal 
13399 \emph off 
13400 \bar no 
13401 \noun off 
13402 \color none
13403 convert unsigned long to floating point number
13404 \end_inset 
13405 </cell>
13406 </row>
13407 <row topline="true" bottomline="true">
13408 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13409 \begin_inset Text
13410
13411 \layout Standard
13412
13413
13414 \family roman 
13415 \series medium 
13416 \shape up 
13417 \size normal 
13418 \emph off 
13419 \bar no 
13420 \noun off 
13421 \color none
13422 _long2fs.c
13423 \end_inset 
13424 </cell>
13425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13426 \begin_inset Text
13427
13428 \layout Standard
13429
13430
13431 \family roman 
13432 \series medium 
13433 \shape up 
13434 \size normal 
13435 \emph off 
13436 \bar no 
13437 \noun off 
13438 \color none
13439 convert long to floating point number
13440 \end_inset 
13441 </cell>
13442 </row>
13443 </lyxtabular>
13444
13445 \end_inset 
13446
13447
13448 \newline 
13449
13450 \layout Standard
13451
13452 These support routines are developed in ANSI-C so there is room for space
13453  and speed improvement.
13454  Note if all these routines are used simultaneously the data space might
13455  overflow.
13456  For serious floating point usage it is recommended that the large model
13457  be used.
13458  Also notice that you don't have to call this routines directly.
13459  The compiler will use them automatically every time a floating point operation
13460  is required.
13461 \layout Section
13462
13463 Library Routines
13464 \begin_inset LatexCommand \index{Libraries}
13465
13466 \end_inset 
13467
13468
13469 \layout Standard
13470
13471
13472 \emph on 
13473 <pending: this is messy and incomplete - a little more information is in
13474  sdcc/doc/libdoc.txt
13475 \emph default 
13476  >
13477 \layout Subsection
13478
13479 Compiler support routines (_gptrget, _mulint etc.)
13480 \layout Subsection
13481
13482 Stdclib functions (puts, printf, strcat etc.)
13483 \layout Subsubsection
13484
13485 <stdio.h>
13486 \layout Standard
13487
13488
13489 \begin_inset LatexCommand \index{<stdio.h>}
13490
13491 \end_inset 
13492
13493 As usual on embedded systems you have to provide your own 
13494 \family typewriter 
13495 getchar()
13496 \begin_inset LatexCommand \index{getchar()}
13497
13498 \end_inset 
13499
13500  
13501 \family default 
13502 and 
13503 \family typewriter 
13504 putchar()
13505 \begin_inset LatexCommand \index{putchar()}
13506
13507 \end_inset 
13508
13509
13510 \family default 
13511  routines.
13512  SDCC does not know whether the system connects to a serial line with or
13513  without handshake, LCD, keyboard or other device.
13514  You'll find examples for serial routines f.e.
13515  in sdcc/device/lib.
13516 \layout Standard
13517
13518 If you're short on memory you might want to use 
13519 \family typewriter 
13520 printf_small()
13521 \family default 
13522  
13523 \emph on 
13524 instead
13525 \emph default 
13526  of
13527 \family typewriter 
13528  printf()
13529 \begin_inset LatexCommand \index{printf()}
13530
13531 \end_inset 
13532
13533 .
13534
13535 \family default 
13536  For the mcs51 there is an assembly version 
13537 \family typewriter 
13538 printf_fast()
13539 \family default 
13540  which should fit the requirements of many embedded systems (by unsetting
13541  #defines it can be customized to 
13542 \emph on 
13543 not
13544 \emph default 
13545  support long variables and field widths).
13546 \layout Subsection
13547
13548 Math functions (sin, pow, sqrt etc.)
13549 \layout Subsection
13550
13551 Other libraries
13552 \layout Standard
13553
13554 Libraries
13555 \begin_inset LatexCommand \index{Libraries}
13556
13557 \end_inset 
13558
13559  included in SDCC should have a license at least as liberal as the GNU Lesser
13560  General Public License
13561 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13562
13563 \end_inset 
13564
13565  
13566 \emph on 
13567 LGPL
13568 \emph default 
13569 .
13570 \layout Comment
13571
13572 license statements for the libraries are missing.
13573  sdcc/device/lib/ser_ir.c
13574 \layout Comment
13575
13576 or _decdptr f.e.
13577  come with a GPL (as opposed to LGPL) License - this will not be liberal
13578  enough for many embedded programmers.
13579 \layout Standard
13580
13581 If you have ported some library or want to share experience about some code
13582  which f.e.
13583  falls into any of these categories Busses (I
13584 \begin_inset Formula $^{\textrm{2}}$
13585 \end_inset 
13586
13587 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13588  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13589  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
13590 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13591
13592 \end_inset 
13593
13594 \SpecialChar ~
13595 would certainly like to hear about it.
13596  Programmers coding for embedded systems are not especially famous for being
13597  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13598 e these references are very valuable.
13599  Let's help to create a climate where information is shared.
13600 \layout Section
13601
13602 Memory Models
13603 \layout Subsection
13604
13605 MCS51 Memory Models
13606 \begin_inset LatexCommand \index{Memory model}
13607
13608 \end_inset 
13609
13610
13611 \begin_inset LatexCommand \index{MCS51 memory model}
13612
13613 \end_inset 
13614
13615
13616 \layout Subsubsection
13617
13618 Small and Large
13619 \layout Standard
13620
13621 SDCC allows two memory models for MCS51 code, 
13622 \shape slanted 
13623 small
13624 \shape default 
13625  and 
13626 \shape slanted 
13627 large
13628 \shape default 
13629 .
13630  Modules compiled with different memory models should 
13631 \emph on 
13632 never
13633 \emph default 
13634  be combined together or the results would be unpredictable.
13635  The library routines supplied with the compiler are compiled as both small
13636  and large.
13637  The compiled library modules are contained in separate directories as small
13638  and large so that you can link to either set.
13639  
13640 \layout Standard
13641
13642 When the large model is used all variables declared without a storage class
13643  will be allocated into the external ram, this includes all parameters and
13644  local variables (for non-reentrant
13645 \begin_inset LatexCommand \index{reentrant}
13646
13647 \end_inset 
13648
13649  functions).
13650  When the small model is used variables without storage class are allocated
13651  in the internal ram.
13652 \layout Standard
13653
13654 Judicious usage of the processor specific storage classes
13655 \begin_inset LatexCommand \index{Storage class}
13656
13657 \end_inset 
13658
13659  and the 'reentrant' function type will yield much more efficient code,
13660  than using the large model.
13661  Several optimizations are disabled when the program is compiled using the
13662  large model, it is therefore recommended that the small model be used unless
13663  absolutely required.
13664 \layout Subsubsection
13665
13666 External Stack
13667 \begin_inset LatexCommand \label{sub:External-Stack}
13668
13669 \end_inset 
13670
13671
13672 \begin_inset LatexCommand \index{stack}
13673
13674 \end_inset 
13675
13676
13677 \begin_inset LatexCommand \index{External stack (mcs51)}
13678
13679 \end_inset 
13680
13681
13682 \layout Standard
13683
13684
13685 \series bold 
13686 Attention
13687 \series default 
13688 : this option wasn't maintained for a long time and is quite buggy.
13689  Small programs might work.
13690  You've been warned!
13691 \layout Standard
13692
13693 The external stack (-
13694 \begin_inset ERT
13695 status Collapsed
13696
13697 \layout Standard
13698
13699 \backslash 
13700 /
13701 \end_inset 
13702
13703 -xstack option
13704 \begin_inset LatexCommand \index{-\/-xstack}
13705
13706 \end_inset 
13707
13708 ) is located in pdata
13709 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13710
13711 \end_inset 
13712
13713  memory (usually at the start of the external ram segment) and is 256 bytes
13714  in size.
13715  When -
13716 \begin_inset ERT
13717 status Collapsed
13718
13719 \layout Standard
13720
13721 \backslash 
13722 /
13723 \end_inset 
13724
13725 -xstack option is used to compile the program, the parameters and local
13726  variables
13727 \begin_inset LatexCommand \index{local variables}
13728
13729 \end_inset 
13730
13731  of all reentrant functions are allocated in this area.
13732  This option is provided for programs with large stack space requirements.
13733  When used with the -
13734 \begin_inset ERT
13735 status Collapsed
13736
13737 \layout Standard
13738
13739 \backslash 
13740 /
13741 \end_inset 
13742
13743 -stack-auto
13744 \begin_inset LatexCommand \index{-\/-stack-auto}
13745
13746 \end_inset 
13747
13748  option, all parameters and local variables are allocated on the external
13749  stack (note: support libraries will need to be recompiled with the same
13750  options).
13751 \layout Standard
13752
13753 The compiler outputs the higher order address byte of the external ram segment
13754  into port P2
13755 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13756
13757 \end_inset 
13758
13759  (see also section 
13760 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13761
13762 \end_inset 
13763
13764 ), therefore when using the External Stack option, this port 
13765 \emph on 
13766 may not
13767 \emph default 
13768  be used by the application program.
13769 \layout Subsection
13770
13771 DS390 Memory Model
13772 \begin_inset LatexCommand \index{Memory model}
13773
13774 \end_inset 
13775
13776
13777 \begin_inset LatexCommand \index{DS390 memory model}
13778
13779 \end_inset 
13780
13781
13782 \layout Standard
13783
13784 The only model supported is Flat 24
13785 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13786
13787 \end_inset 
13788
13789 .
13790  This generates code for the 24 bit contiguous addressing mode of the Dallas
13791  DS80C390 part.
13792  In this mode, up to four meg of external RAM or code space can be directly
13793  addressed.
13794  See the data sheets at www.dalsemi.com for further information on this part.
13795 \newline 
13796
13797 \newline 
13798 Note that the compiler does not generate any code to place the processor
13799  into 24 bitmode (although 
13800 \emph on 
13801 tinibios
13802 \emph default 
13803  in the ds390 libraries will do that for you).
13804  If you don't use 
13805 \emph on 
13806 tinibios
13807 \emph default 
13808
13809 \begin_inset LatexCommand \index{Tinibios (DS390)}
13810
13811 \end_inset 
13812
13813 , the boot loader or similar code must ensure that the processor is in 24
13814  bit contiguous addressing mode before calling the SDCC startup code.
13815 \newline 
13816
13817 \newline 
13818 Like the 
13819 \emph on 
13820 -
13821 \begin_inset ERT
13822 status Collapsed
13823
13824 \layout Standard
13825
13826 \backslash 
13827 /
13828 \end_inset 
13829
13830 -model-large
13831 \emph default 
13832  option, variables will by default be placed into the XDATA segment.
13833  
13834 \newline 
13835
13836 \newline 
13837 Segments may be placed anywhere in the 4 meg address space using the usual
13838  -
13839 \begin_inset ERT
13840 status Collapsed
13841
13842 \layout Standard
13843
13844 \backslash 
13845 /
13846 \end_inset 
13847
13848 -*-loc options.
13849  Note that if any segments are located above 64K, the -r flag must be passed
13850  to the linker to generate the proper segment relocations, and the Intel
13851  HEX output format must be used.
13852  The -r flag can be passed to the linker by using the option 
13853 \emph on 
13854 -Wl-r
13855 \emph default 
13856  on the SDCC command line.
13857  However, currently the linker can not handle code segments > 64k.
13858 \layout Section
13859
13860 Pragmas
13861 \begin_inset LatexCommand \index{Pragmas}
13862
13863 \end_inset 
13864
13865
13866 \layout Standard
13867
13868 SDCC supports the following #pragma directives:
13869 \layout Itemize
13870
13871 save
13872 \begin_inset LatexCommand \index{\#pragma save}
13873
13874 \end_inset 
13875
13876  - this will save all current options to the save/restore stack.
13877  See #pragma\SpecialChar ~
13878 restore.
13879 \layout Itemize
13880
13881 restore
13882 \begin_inset LatexCommand \index{\#pragma restore}
13883
13884 \end_inset 
13885
13886  - will restore saved options from the last save.
13887  saves & restores can be nested.
13888  SDCC uses a save/restore stack: save pushes current options to the stack,
13889  restore pulls current options from the stack.
13890  See #pragma\SpecialChar ~
13891 save.
13892 \newline 
13893
13894 \layout Itemize
13895
13896 callee_saves
13897 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13898
13899 \end_inset 
13900
13901
13902 \begin_inset LatexCommand \index{function prologue}
13903
13904 \end_inset 
13905
13906  function1[,function2[,function3...]] - The compiler by default uses a caller
13907  saves convention for register saving across function calls, however this
13908  can cause unnecessary register pushing & popping
13909 \begin_inset LatexCommand \index{push/pop}
13910
13911 \end_inset 
13912
13913  when calling small functions from larger functions.
13914  This option can be used to switch off the register saving convention for
13915  the function names specified.
13916  The compiler will not save registers when calling these functions, extra
13917  code need to be manually inserted at the entry & exit for these functions
13918  to save & restore the registers used by these functions, this can SUBSTANTIALLY
13919  reduce code & improve run time performance of the generated code.
13920  In the future the compiler (with inter procedural analysis) may be able
13921  to determine the appropriate scheme to use for each function call.
13922  If -
13923 \begin_inset ERT
13924 status Collapsed
13925
13926 \layout Standard
13927
13928 \backslash 
13929 /
13930 \end_inset 
13931
13932 -callee-saves command line option is used, the function names specified
13933  in #pragma\SpecialChar ~
13934 callee_saves
13935 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13936
13937 \end_inset 
13938
13939  is appended to the list of functions specified in the command line.
13940 \layout Itemize
13941
13942 exclude
13943 \begin_inset LatexCommand \index{\#pragma exclude}
13944
13945 \end_inset 
13946
13947  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
13948  of pairs of push/pop
13949 \begin_inset LatexCommand \index{push/pop}
13950
13951 \end_inset 
13952
13953  instructions in 
13954 \emph on 
13955 I
13956 \emph default 
13957 nterrupt
13958 \begin_inset LatexCommand \index{interrupt}
13959
13960 \end_inset 
13961
13962  
13963 \emph on 
13964 S
13965 \emph default 
13966 ervice 
13967 \emph on 
13968 R
13969 \emph default 
13970 outines.
13971  The directive should be placed immediately before the ISR function definition
13972  and it affects ALL ISR functions following it.
13973  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
13974 exclude\SpecialChar ~
13975 none
13976 \begin_inset LatexCommand \index{\#pragma exclude}
13977
13978 \end_inset 
13979
13980 .
13981  See also the related keyword _naked
13982 \begin_inset LatexCommand \index{\_naked}
13983
13984 \end_inset 
13985
13986 .
13987 \layout Itemize
13988
13989 less_pedantic
13990 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
13991
13992 \end_inset 
13993
13994  - the compiler will not warn you anymore for obvious mistakes, you'r on
13995  your own now ;-(
13996 \layout Itemize
13997
13998 nogcse
13999 \begin_inset LatexCommand \index{\#pragma nogcse}
14000
14001 \end_inset 
14002
14003  - will stop global common subexpression elimination.
14004 \layout Itemize
14005
14006 noinduction
14007 \begin_inset LatexCommand \index{\#pragma noinduction}
14008
14009 \end_inset 
14010
14011  - will stop loop induction optimizations.
14012 \layout Itemize
14013
14014 noinvariant
14015 \begin_inset LatexCommand \index{\#pragma noinvariant}
14016
14017 \end_inset 
14018
14019  - will not do loop invariant optimizations.
14020  For more details see Loop Invariants in section
14021 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
14022
14023 \end_inset 
14024
14025 .
14026 \layout Itemize
14027
14028 noiv
14029 \begin_inset LatexCommand \index{\#pragma noiv}
14030
14031 \end_inset 
14032
14033  - Do not generate interrupt
14034 \begin_inset LatexCommand \index{interrupt}
14035
14036 \end_inset 
14037
14038  vector table entries for all ISR functions defined after the pragma.
14039  This is useful in cases where the interrupt vector table must be defined
14040  manually, or when there is a secondary, manually defined interrupt vector
14041  table (e.g.
14042  for the autovector feature of the Cypress EZ-USB FX2).
14043  More elegantly this can be achieved by obmitting the optional interrupt
14044  number after the interrupt keyword, see section 
14045 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
14046
14047 \end_inset 
14048
14049 \SpecialChar ~
14050 about interrupts.
14051 \layout Itemize
14052
14053 nojtbound
14054 \begin_inset LatexCommand \index{\#pragma nojtbound}
14055
14056 \end_inset 
14057
14058  - will not generate code for boundary value checking, when switch statements
14059  are turned into jump-tables (dangerous).
14060  For more details see section 
14061 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
14062
14063 \end_inset 
14064
14065 .
14066 \layout Itemize
14067
14068 noloopreverse
14069 \begin_inset LatexCommand \index{\#pragma noloopreverse}
14070
14071 \end_inset 
14072
14073  - Will not do loop reversal optimization
14074 \layout Itemize
14075
14076 nooverlay
14077 \begin_inset LatexCommand \index{\#pragma nooverlay}
14078
14079 \end_inset 
14080
14081  - the compiler will not overlay the parameters and local variables of a
14082  function.
14083 \layout Itemize
14084
14085 stackauto
14086 \begin_inset LatexCommand \index{\#pragma stackauto}
14087
14088 \end_inset 
14089
14090 - See option -
14091 \begin_inset ERT
14092 status Collapsed
14093
14094 \layout Standard
14095
14096 \backslash 
14097 /
14098 \end_inset 
14099
14100 -stack-auto
14101 \begin_inset LatexCommand \index{-\/-stack-auto}
14102
14103 \end_inset 
14104
14105  and section 
14106 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
14107
14108 \end_inset 
14109
14110  Parameters and Local Variables.
14111 \layout Standard
14112
14113 SDCPP supports the following #pragma directives:
14114 \layout Itemize
14115
14116 preproc_asm
14117 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
14118
14119 \end_inset 
14120
14121  (+ | -) - switch _asm _endasm block preprocessing on / off.
14122  Default is on.
14123 \layout Standard
14124
14125 The pragma's are intended to be used to turn-on or off certain optimizations
14126  which might cause the compiler to generate extra stack / data space to
14127  store compiler generated temporary variables.
14128  This usually happens in large functions.
14129  Pragma directives should be used as shown in the following example, they
14130  are used to control options & optimizations for a given function; pragmas
14131  should be placed before and/or after a function, placing pragma's inside
14132  a function body could have unpredictable results.
14133 \layout Verse
14134
14135
14136 \family typewriter 
14137 #pragma save
14138 \begin_inset LatexCommand \index{\#pragma save}
14139
14140 \end_inset 
14141
14142  \SpecialChar ~
14143 \SpecialChar ~
14144 \SpecialChar ~
14145 \SpecialChar ~
14146 \SpecialChar ~
14147 \SpecialChar ~
14148 \SpecialChar ~
14149 /* save the current settings */ 
14150 \newline 
14151 #pragma nogcse
14152 \begin_inset LatexCommand \index{\#pragma nogcse}
14153
14154 \end_inset 
14155
14156  \SpecialChar ~
14157 \SpecialChar ~
14158 \SpecialChar ~
14159 \SpecialChar ~
14160 \SpecialChar ~
14161 /* turnoff global subexpression elimination */ 
14162 \newline 
14163 #pragma noinduction
14164 \begin_inset LatexCommand \index{\#pragma noinduction}
14165
14166 \end_inset 
14167
14168  /* turn off induction optimizations */ 
14169 \newline 
14170 int foo () 
14171 \newline 
14172
14173 \newline 
14174 \SpecialChar ~
14175  \SpecialChar ~
14176  ...
14177  
14178 \newline 
14179 \SpecialChar ~
14180  \SpecialChar ~
14181  /* large code */ 
14182 \newline 
14183 \SpecialChar ~
14184  \SpecialChar ~
14185  ...
14186  
14187 \newline 
14188
14189 \newline 
14190 #pragma restore
14191 \begin_inset LatexCommand \index{\#pragma restore}
14192
14193 \end_inset 
14194
14195  /* turn the optimizations back on */
14196 \layout Standard
14197
14198 The compiler will generate a warning message when extra space is allocated.
14199  It is strongly recommended that the save and restore pragma's be used when
14200  changing options for a function.
14201 \layout Section
14202
14203 Defines Created by the Compiler
14204 \layout Standard
14205
14206 The compiler creates the following #defines
14207 \begin_inset LatexCommand \index{\#defines}
14208
14209 \end_inset 
14210
14211
14212 \begin_inset LatexCommand \index{Defines created by the compiler}
14213
14214 \end_inset 
14215
14216 :
14217 \newline 
14218
14219 \layout Standard
14220
14221
14222 \begin_inset  Tabular
14223 <lyxtabular version="3" rows="10" columns="2">
14224 <features>
14225 <column alignment="center" valignment="top" leftline="true" width="0">
14226 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14227 <row topline="true" bottomline="true">
14228 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14229 \begin_inset Text
14230
14231 \layout Standard
14232
14233
14234 \series bold 
14235 #define
14236 \end_inset 
14237 </cell>
14238 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14239 \begin_inset Text
14240
14241 \layout Standard
14242
14243
14244 \series bold 
14245 Description
14246 \end_inset 
14247 </cell>
14248 </row>
14249 <row topline="true">
14250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14251 \begin_inset Text
14252
14253 \layout Standard
14254
14255 SDCC
14256 \begin_inset LatexCommand \index{SDCC}
14257
14258 \end_inset 
14259
14260  
14261 \end_inset 
14262 </cell>
14263 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14264 \begin_inset Text
14265
14266 \layout Standard
14267
14268 this Symbol is always defined
14269 \end_inset 
14270 </cell>
14271 </row>
14272 <row topline="true">
14273 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14274 \begin_inset Text
14275
14276 \layout Standard
14277
14278 SDCC_mcs51
14279 \begin_inset LatexCommand \index{SDCC\_mcs51}
14280
14281 \end_inset 
14282
14283  or SDCC_ds390
14284 \begin_inset LatexCommand \index{SDCC\_ds390}
14285
14286 \end_inset 
14287
14288  or SDCC_z80
14289 \begin_inset LatexCommand \index{SDCC\_z80}
14290
14291 \end_inset 
14292
14293 , etc
14294 \end_inset 
14295 </cell>
14296 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14297 \begin_inset Text
14298
14299 \layout Standard
14300
14301 depending on the model used (e.g.: -mds390
14302 \end_inset 
14303 </cell>
14304 </row>
14305 <row topline="true">
14306 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14307 \begin_inset Text
14308
14309 \layout Standard
14310
14311 __mcs51
14312 \begin_inset LatexCommand \index{\_\_mcs51}
14313
14314 \end_inset 
14315
14316 , __ds390
14317 \begin_inset LatexCommand \index{\_\_ds390}
14318
14319 \end_inset 
14320
14321 , __hc08
14322 \begin_inset LatexCommand \index{\_\_hc08}
14323
14324 \end_inset 
14325
14326 , __z80
14327 \begin_inset LatexCommand \index{\_\_z80}
14328
14329 \end_inset 
14330
14331 , etc
14332 \end_inset 
14333 </cell>
14334 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14335 \begin_inset Text
14336
14337 \layout Standard
14338
14339 depending on the model used (e.g.
14340  -mz80)
14341 \end_inset 
14342 </cell>
14343 </row>
14344 <row topline="true">
14345 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14346 \begin_inset Text
14347
14348 \layout Standard
14349
14350 SDCC_STACK_AUTO
14351 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
14352
14353 \end_inset 
14354
14355
14356 \end_inset 
14357 </cell>
14358 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14359 \begin_inset Text
14360
14361 \layout Standard
14362
14363 when 
14364 \emph on 
14365 -
14366 \begin_inset ERT
14367 status Collapsed
14368
14369 \layout Standard
14370
14371 \backslash 
14372 /
14373 \end_inset 
14374
14375 -stack-auto
14376 \emph default 
14377  option is used
14378 \end_inset 
14379 </cell>
14380 </row>
14381 <row topline="true">
14382 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14383 \begin_inset Text
14384
14385 \layout Standard
14386
14387 SDCC_MODEL_SMALL
14388 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
14389
14390 \end_inset 
14391
14392
14393 \end_inset 
14394 </cell>
14395 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14396 \begin_inset Text
14397
14398 \layout Standard
14399
14400 when 
14401 \emph on 
14402 -
14403 \begin_inset ERT
14404 status Collapsed
14405
14406 \layout Standard
14407
14408 \backslash 
14409 /
14410 \end_inset 
14411
14412 -model-small
14413 \emph default 
14414  is used
14415 \end_inset 
14416 </cell>
14417 </row>
14418 <row topline="true">
14419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14420 \begin_inset Text
14421
14422 \layout Standard
14423
14424 SDCC_MODEL_LARGE
14425 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14426
14427 \end_inset 
14428
14429
14430 \end_inset 
14431 </cell>
14432 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14433 \begin_inset Text
14434
14435 \layout Standard
14436
14437 when 
14438 \emph on 
14439 -
14440 \begin_inset ERT
14441 status Collapsed
14442
14443 \layout Standard
14444
14445 \backslash 
14446 /
14447 \end_inset 
14448
14449 -model-large
14450 \emph default 
14451  is used
14452 \end_inset 
14453 </cell>
14454 </row>
14455 <row topline="true">
14456 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14457 \begin_inset Text
14458
14459 \layout Standard
14460
14461 SDCC_USE_XSTACK
14462 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14463
14464 \end_inset 
14465
14466
14467 \end_inset 
14468 </cell>
14469 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14470 \begin_inset Text
14471
14472 \layout Standard
14473
14474 when 
14475 \emph on 
14476 -
14477 \begin_inset ERT
14478 status Collapsed
14479
14480 \layout Standard
14481
14482 \backslash 
14483 /
14484 \end_inset 
14485
14486 -xstack
14487 \emph default 
14488  option is used
14489 \end_inset 
14490 </cell>
14491 </row>
14492 <row topline="true">
14493 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14494 \begin_inset Text
14495
14496 \layout Standard
14497
14498 SDCC_STACK_TENBIT
14499 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14500
14501 \end_inset 
14502
14503  
14504 \end_inset 
14505 </cell>
14506 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14507 \begin_inset Text
14508
14509 \layout Standard
14510
14511 when 
14512 \emph on 
14513 -mds390
14514 \emph default 
14515  is used
14516 \end_inset 
14517 </cell>
14518 </row>
14519 <row topline="true" bottomline="true">
14520 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14521 \begin_inset Text
14522
14523 \layout Standard
14524
14525 SDCC_MODEL_FLAT24
14526 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14527
14528 \end_inset 
14529
14530
14531 \end_inset 
14532 </cell>
14533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14534 \begin_inset Text
14535
14536 \layout Standard
14537
14538 when 
14539 \emph on 
14540 -mds390
14541 \emph default 
14542  is used
14543 \end_inset 
14544 </cell>
14545 </row>
14546 </lyxtabular>
14547
14548 \end_inset 
14549
14550
14551 \layout Chapter
14552
14553 Notes on supported Processors
14554 \layout Section
14555
14556 MCS51 variants
14557 \begin_inset LatexCommand \label{sub:MCS51-variants}
14558
14559 \end_inset 
14560
14561
14562 \begin_inset LatexCommand \index{MCS51 variants}
14563
14564 \end_inset 
14565
14566
14567 \layout Standard
14568
14569 MCS51 processors are available from many vendors and come in many different
14570  flavours.
14571  While they might differ considerably in respect to Special Function Registers
14572  the core MCS51 is usually not modified or is kept compatible.
14573  
14574 \layout Subsection
14575
14576 pdata access by SFR 
14577 \layout Standard
14578
14579 With the upcome of devices with internal xdata and flash memory devices
14580  using port P2
14581 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14582
14583 \end_inset 
14584
14585  as dedicated I/O port is becoming more popular.
14586  Switching the high byte for pdata
14587 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14588
14589 \end_inset 
14590
14591  access which was formerly done by port P2 is then achieved by a Special
14592  Function Register
14593 \begin_inset LatexCommand \index{sfr}
14594
14595 \end_inset 
14596
14597 .
14598  In well-established MCS51 tradition the address of this 
14599 \emph on 
14600 sfr
14601 \emph default 
14602  is where the chip designers decided to put it.
14603  Needless to say that they didn't agree on a common name either.
14604  So that the startup code can correctly initialize xdata variables, you
14605  should define an sfr with the name _XPAGE
14606 \family typewriter 
14607
14608 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
14609
14610 \end_inset 
14611
14612
14613 \family default 
14614  at the appropriate location if the default, port P2, is not used for this.
14615  Some examples are:
14616 \layout Verse
14617
14618
14619 \family typewriter 
14620 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
14621 \layout Verse
14622
14623
14624 \family typewriter 
14625 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
14626 \layout Verse
14627
14628
14629 \family typewriter 
14630 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
14631 \layout Standard
14632
14633 For more exotic implementations further customizations may be needed.
14634  See section 
14635 \begin_inset LatexCommand \ref{sub:Startup-Code}
14636
14637 \end_inset 
14638
14639  for other possibilities.
14640 \layout Subsection
14641
14642 Other Features available by SFR
14643 \layout Standard
14644
14645 Some MCS51 variants offer features like Double DPTR
14646 \begin_inset LatexCommand \index{DPTR}
14647
14648 \end_inset 
14649
14650 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14651  These are currently not used for the MCS51 port.
14652  If you absolutely need them you can fall back to inline assembly or submit
14653  a patch to SDCC.
14654 \layout Section
14655
14656 DS400 port
14657 \layout Standard
14658
14659 The DS80C400 microcontroller has a rich set of peripherals.
14660  In its built-in ROM library it includes functions to access some of the
14661  features, among them is a TCP stack with IP4 and IP6 support.
14662  Library headers (currently in beta status) and other files are provided
14663  at 
14664 \size footnotesize 
14665
14666 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
14667
14668 \end_inset 
14669
14670 .
14671  
14672 \layout Section
14673
14674 The Z80 and gbz80 port
14675 \layout Standard
14676
14677 SDCC can target both the Zilog 
14678 \begin_inset LatexCommand \index{Z80}
14679
14680 \end_inset 
14681
14682  and the Nintendo Gameboy's Z80-like gbz80
14683 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14684
14685 \end_inset 
14686
14687 .
14688  The Z80 port is passed through the same 
14689 \emph on 
14690 regressions tests
14691 \begin_inset LatexCommand \index{Regression test}
14692
14693 \end_inset 
14694
14695
14696 \emph default 
14697  as the MCS51 and DS390 ports, so floating point support, support for long
14698  variables and bitfield support is fine.
14699  See mailing lists and forums about interrupt routines.
14700 \layout Standard
14701
14702 As always, the code is the authoritative reference - see z80/ralloc.c and
14703  z80/gen.c.
14704  The stack
14705 \begin_inset LatexCommand \index{stack}
14706
14707 \end_inset 
14708
14709  frame is similar to that generated by the IAR Z80 compiler.
14710  IX is used as the base pointer, HL and IY are used as a temporary registers,
14711  and BC and DE are available for holding variables.
14712  Return values
14713 \begin_inset LatexCommand \index{return value}
14714
14715 \end_inset 
14716
14717  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
14718  bytes).
14719  The gbz80 port use the same set of registers for the return values, but
14720  in a different order of significance: E (one byte), DE (two bytes), or
14721  HLDE (four bytes).
14722 \layout Section
14723
14724 The HC08 port
14725 \layout Standard
14726
14727 The port to the Motorola HC08
14728 \begin_inset LatexCommand \index{HC08}
14729
14730 \end_inset 
14731
14732  family has been added in October 2003, and is still undergoing some basic
14733  development.
14734  The code generator is complete, but the register allocation is still quite
14735  unoptimized.
14736  Some of the SDCC's standard C library functions have embedded non-HC08
14737  inline assembly and so are not yet usable.
14738 \newline 
14739
14740 \newline 
14741
14742 \layout Section
14743
14744 The PIC14 port
14745 \layout Standard
14746
14747 The 14bit PIC
14748 \begin_inset LatexCommand \index{PIC14}
14749
14750 \end_inset 
14751
14752  port still requires a major effort from the development community.
14753  However it can work for very simple code.
14754 \layout Subsection
14755
14756 C code and 14bit PIC code page
14757 \begin_inset LatexCommand \index{code page (pic14)}
14758
14759 \end_inset 
14760
14761  and RAM banks
14762 \begin_inset LatexCommand \index{RAM bank (pic14)}
14763
14764 \end_inset 
14765
14766
14767 \layout Standard
14768
14769 The linker organizes allocation for the code page and RAM banks.
14770  It does not have intimate knowledge of the code flow.
14771  It will put all the code section of a single asm file into a single code
14772  page.
14773  In order to make use of multiple code pages, separate asm files must be
14774  used.
14775  The compiler treats all functions of a single C file as being in the same
14776  code page unless it is non static.
14777  The compiler treats all local variables of a single C file as being in
14778  the same RAM bank unless it is an extern.
14779 \newline 
14780
14781 \newline 
14782 To get the best follow these guide lines:
14783 \layout Enumerate
14784
14785 make local functions static, as non static functions require code page selection
14786  overhead.
14787 \layout Enumerate
14788
14789 Make local variables static as extern variables require RAM bank selection
14790  overhead.
14791 \layout Enumerate
14792
14793 For devices that have multiple code pages it is more efficient to use the
14794  same number of files as pages, i.e.
14795  for the 16F877 use 4 separate files and i.e.
14796  for the 16F874 use 2 separate files.
14797  This way the linker can put the code for each file into different code
14798  pages and the compiler can allocate reusable variables more efficiently
14799  and there's less page selection overhead.
14800  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
14801  instruction set) use 'unsigned char' whereever possible instead of 'int'.
14802 \layout Subsection
14803
14804 Creating a device include file 
14805 \layout Standard
14806
14807 For generating a device include file use the support perl script inc2h.pl
14808  kept in directory support/script.
14809 \layout Subsection
14810
14811 Interrupt code
14812 \layout Standard
14813
14814 For the interrupt function, use the keyword 'interrupt'
14815 \begin_inset LatexCommand \index{interrupt}
14816
14817 \end_inset 
14818
14819  with level number of 0 (PIC14 only has 1 interrupt so this number is only
14820  there to avoid a syntax error - it ought to be fixed).
14821  E.g.:
14822 \layout Verse
14823
14824
14825 \family typewriter 
14826 void Intr(void) interrupt 0
14827 \newline 
14828 {
14829 \newline 
14830 \SpecialChar ~
14831 \SpecialChar ~
14832 T0IF = 0; /* Clear timer interrupt */
14833 \newline 
14834 }
14835 \layout Subsection
14836
14837 Linking and assembling
14838 \layout Standard
14839
14840 For assembling you can use either GPUTILS'
14841 \begin_inset LatexCommand \index{gputils (pic tools)}
14842
14843 \end_inset 
14844
14845  gpasm.exe or MPLAB's mpasmwin.exe.
14846  GPUTILS is available from 
14847 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
14848
14849 \end_inset 
14850
14851 .
14852  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
14853  If you use MPLAB and an interrupt function then the linker script file
14854  vectors section will need to be enlarged to link with mplink.
14855 \newline 
14856
14857 \newline 
14858 Here is a 
14859 \family typewriter 
14860 Makefile
14861 \family default 
14862  using GPUTILS:
14863 \layout Verse
14864
14865
14866 \family typewriter 
14867 .c.o:
14868 \newline 
14869 \SpecialChar ~
14870 \SpecialChar ~
14871 \SpecialChar ~
14872 \SpecialChar ~
14873 \SpecialChar ~
14874 \SpecialChar ~
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 sdcc -S -V -mpic14 -p16F877 $< 
14878 \newline 
14879 \SpecialChar ~
14880 \SpecialChar ~
14881 \SpecialChar ~
14882 \SpecialChar ~
14883 \SpecialChar ~
14884 \SpecialChar ~
14885 \SpecialChar ~
14886 \SpecialChar ~
14887 gpasm -c $*.asm
14888 \newline 
14889
14890 \newline 
14891 $(PRJ).hex: $(OBJS) 
14892 \newline 
14893 \SpecialChar ~
14894 \SpecialChar ~
14895 \SpecialChar ~
14896 \SpecialChar ~
14897 \SpecialChar ~
14898 \SpecialChar ~
14899 \SpecialChar ~
14900 \SpecialChar ~
14901 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
14902 \layout Standard
14903
14904 Here is a 
14905 \family typewriter 
14906 Makefile
14907 \family default 
14908  using MPLAB:
14909 \layout Verse
14910
14911
14912 \family typewriter 
14913 .c.o: 
14914 \newline 
14915 \SpecialChar ~
14916 \SpecialChar ~
14917 \SpecialChar ~
14918 \SpecialChar ~
14919 \SpecialChar ~
14920 \SpecialChar ~
14921 \SpecialChar ~
14922 \SpecialChar ~
14923 sdcc -S -V -mpic14 -p16F877 $< 
14924 \newline 
14925 \SpecialChar ~
14926 \SpecialChar ~
14927 \SpecialChar ~
14928 \SpecialChar ~
14929 \SpecialChar ~
14930 \SpecialChar ~
14931 \SpecialChar ~
14932 \SpecialChar ~
14933 mpasmwin /q /o $*.asm
14934 \newline 
14935
14936 \newline 
14937 $(PRJ).hex: $(OBJS) 
14938 \newline 
14939 \SpecialChar ~
14940 \SpecialChar ~
14941 \SpecialChar ~
14942 \SpecialChar ~
14943 \SpecialChar ~
14944 \SpecialChar ~
14945 \SpecialChar ~
14946 \SpecialChar ~
14947 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
14948 \layout Standard
14949
14950 Please note that indentations within a
14951 \family typewriter 
14952  Makefile
14953 \family default 
14954  have to be done with a tabulator character.
14955 \layout Section
14956
14957 The PIC16
14958 \begin_inset LatexCommand \index{PIC16}
14959
14960 \end_inset 
14961
14962  port
14963 \layout Standard
14964
14965 The PIC16
14966 \begin_inset LatexCommand \index{PIC16}
14967
14968 \end_inset 
14969
14970  port is the portion of SDCC that is responsible to produce code for the
14971  Microchip
14972 \begin_inset LatexCommand \index{Microchip}
14973
14974 \end_inset 
14975
14976 (TM) microcontrollers with 16 bit core.
14977  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
14978 \layout Subsection
14979
14980 Global Options
14981 \layout Standard
14982
14983 PIC16 port supports the standard command line arguments as supposed, with
14984  the exception of certain cases that will be mentioned in the following
14985  list:
14986 \layout List
14987 \labelwidthstring 00.00.0000
14988
14989 -
14990 \begin_inset ERT
14991 status Collapsed
14992
14993 \layout Standard
14994
14995 \backslash 
14996 /
14997 \end_inset 
14998
14999 -stack-auto Auto variables that are function parameters, will be saved on
15000  stack by default.
15001  
15002 \emph on 
15003 There is no need to specify this in the command line.
15004 \layout List
15005 \labelwidthstring 00.00.0000
15006
15007 -
15008 \begin_inset ERT
15009 status Collapsed
15010
15011 \layout Standard
15012
15013 \backslash 
15014 /
15015 \end_inset 
15016
15017 -float-reent All floating point functions are reentrant by default.
15018  
15019 \emph on 
15020 There is no need to specifiy this in the command line.
15021 \layout List
15022 \labelwidthstring 00.00.0000
15023
15024 -
15025 \begin_inset ERT
15026 status Collapsed
15027
15028 \layout Standard
15029
15030 \backslash 
15031 /
15032 \end_inset 
15033
15034 -callee-saves See -
15035 \begin_inset ERT
15036 status Collapsed
15037
15038 \layout Standard
15039
15040 \backslash 
15041 /
15042 \end_inset 
15043
15044 -all-callee-saves
15045 \layout List
15046 \labelwidthstring 00.00.0000
15047
15048 -
15049 \begin_inset ERT
15050 status Collapsed
15051
15052 \layout Standard
15053
15054 \backslash 
15055 /
15056 \end_inset 
15057
15058 -all-callee-saves All function arguments are passed on stack by default.
15059  
15060 \emph on 
15061 There is no need to specify this in the command line.
15062 \layout List
15063 \labelwidthstring 00.00.0000
15064
15065 -
15066 \begin_inset ERT
15067 status Collapsed
15068
15069 \layout Standard
15070
15071 \backslash 
15072 /
15073 \end_inset 
15074
15075 -fommit-frame-pointer Frame pointer will be omitted when the function uses
15076  no local variables.
15077 \layout Subsection
15078
15079 Port Specific Options
15080 \begin_inset LatexCommand \index{Options PIC16}
15081
15082 \end_inset 
15083
15084
15085 \layout Standard
15086
15087 The port specific options appear after the global options in the sdcc --help
15088  output.
15089 \layout Subsubsection
15090
15091 General Options
15092 \layout Standard
15093
15094 General options enable certain port features and optimizations.
15095 \layout List
15096 \labelwidthstring 00.00.0000
15097
15098 -
15099 \begin_inset ERT
15100 status Collapsed
15101
15102 \layout Standard
15103
15104 \backslash 
15105 /
15106 \end_inset 
15107
15108 -pgen-bank Instructs the port to insert BANKSEL directives before instructions
15109  that use the Bank Select Register (BSR).
15110 \layout List
15111 \labelwidthstring 00.00.0000
15112
15113 -
15114 \begin_inset ERT
15115 status Collapsed
15116
15117 \layout Standard
15118
15119 \backslash 
15120 /
15121 \end_inset 
15122
15123 -pomit-config-words Instructs the port to omit the generation of the configurati
15124 on words.
15125 \layout List
15126 \labelwidthstring 00.00.0000
15127
15128 -
15129 \begin_inset ERT
15130 status Collapsed
15131
15132 \layout Standard
15133
15134 \backslash 
15135 /
15136 \end_inset 
15137
15138 -pomit-ivt Instructs the port to omit the generation of the interrupt vectors
15139 \layout List
15140 \labelwidthstring 00.00.0000
15141
15142 -
15143 \begin_inset ERT
15144 status Collapsed
15145
15146 \layout Standard
15147
15148 \backslash 
15149 /
15150 \end_inset 
15151
15152 -pleave-reset-vector Used in conjuction with the previous command, instructs
15153  the port NOT to omit the reset vector.
15154 \layout List
15155 \labelwidthstring 00.00.0000
15156
15157 -
15158 \begin_inset ERT
15159 status Collapsed
15160
15161 \layout Standard
15162
15163 \backslash 
15164 /
15165 \end_inset 
15166
15167 -stack-model=[model] Used in conjuction with the command above.
15168  Defines the stack model to be used, valid stack models are : 
15169 \begin_deeper 
15170 \layout List
15171 \labelwidthstring 00.00.0000
15172
15173
15174 \emph on 
15175 small
15176 \emph default 
15177  Selects small stack model.
15178  8 bit stack and frame pointers.
15179  Supports 256 bytes stack size.
15180 \layout List
15181 \labelwidthstring 00.00.0000
15182
15183
15184 \emph on 
15185 large
15186 \emph default 
15187  Selects large stack model.
15188  16 bit stack and frame pointers.
15189  Supports 65536 bytes stack size.
15190 \end_deeper 
15191 \layout List
15192 \labelwidthstring 00.00.0000
15193
15194 -
15195 \begin_inset ERT
15196 status Collapsed
15197
15198 \layout Standard
15199
15200 \backslash 
15201 /
15202 \end_inset 
15203
15204 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
15205  unitialized data variables with [kword].
15206  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
15207 \layout List
15208 \labelwidthstring 00.00.0000
15209
15210 -
15211 \begin_inset ERT
15212 status Collapsed
15213
15214 \layout Standard
15215
15216 \backslash 
15217 /
15218 \end_inset 
15219
15220 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
15221  Useful for bootloaders.
15222 \layout List
15223 \labelwidthstring 00.00.0000
15224
15225 -
15226 \begin_inset ERT
15227 status Collapsed
15228
15229 \layout Standard
15230
15231 \backslash 
15232 /
15233 \end_inset 
15234
15235 -asm= sets the full path and name of an external assembler to call.
15236 \layout List
15237 \labelwidthstring 00.00.0000
15238
15239 -
15240 \begin_inset ERT
15241 status Collapsed
15242
15243 \layout Standard
15244
15245 \backslash 
15246 /
15247 \end_inset 
15248
15249 -link= sets the full path and name of an external linker to call.
15250 \layout Subsubsection
15251
15252 Debugging Options
15253 \layout Standard
15254
15255 Debugging options enable extra debugging information in the output files.
15256 \layout List
15257 \labelwidthstring 00.00.0000
15258
15259 -
15260 \begin_inset ERT
15261 status Collapsed
15262
15263 \layout Standard
15264
15265 \backslash 
15266 /
15267 \end_inset 
15268
15269 -debug-xtra Similar to -
15270 \begin_inset ERT
15271 status Collapsed
15272
15273 \layout Standard
15274
15275 \backslash 
15276 /
15277 \end_inset 
15278
15279 -debug
15280 \begin_inset LatexCommand \index{-\/-debug}
15281
15282 \end_inset 
15283
15284 , but dumps more information.
15285 \layout List
15286 \labelwidthstring 00.00.0000
15287
15288 -
15289 \begin_inset ERT
15290 status Collapsed
15291
15292 \layout Standard
15293
15294 \backslash 
15295 /
15296 \end_inset 
15297
15298 -debug-ralloc Force register allocator to dump <source>.d file with debugging
15299  information.
15300  <source> is the name of the file compiled.
15301 \layout List
15302 \labelwidthstring 00.00.0000
15303
15304 -
15305 \begin_inset ERT
15306 status Collapsed
15307
15308 \layout Standard
15309
15310 \backslash 
15311 /
15312 \end_inset 
15313
15314 -pcode-verbose Enable pcode debugging information in translation.
15315 \layout Subsection
15316
15317 Preprocessor Macros
15318 \layout Standard
15319
15320 PIC16 port defines the following preprocessor macros while translating a
15321  source.
15322 \layout Standard
15323 \align center 
15324
15325 \begin_inset  Tabular
15326 <lyxtabular version="3" rows="2" columns="2">
15327 <features>
15328 <column alignment="center" valignment="top" leftline="true" width="0">
15329 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15330 <row topline="true" bottomline="true">
15331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15332 \begin_inset Text
15333
15334 \layout Standard
15335
15336 Macro
15337 \end_inset 
15338 </cell>
15339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15340 \begin_inset Text
15341
15342 \layout Standard
15343
15344 Description
15345 \end_inset 
15346 </cell>
15347 </row>
15348 <row topline="true" bottomline="true">
15349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15350 \begin_inset Text
15351
15352 \layout Standard
15353
15354 pic18fxxxx
15355 \end_inset 
15356 </cell>
15357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15358 \begin_inset Text
15359
15360 \layout Standard
15361
15362 MCU Identification.
15363  
15364 \emph on 
15365 xxxx
15366 \emph default 
15367  is the microcontrol identification number, i.e.
15368  452, 6620, etc
15369 \end_inset 
15370 </cell>
15371 </row>
15372 </lyxtabular>
15373
15374 \end_inset 
15375
15376
15377 \layout Subsection
15378
15379 Directories
15380 \layout Standard
15381
15382 PIC16
15383 \begin_inset LatexCommand \index{PIC16}
15384
15385 \end_inset 
15386
15387  port uses the following directories for searching header files and libraries.
15388 \layout Standard
15389 \align center 
15390
15391 \begin_inset  Tabular
15392 <lyxtabular version="3" rows="3" columns="4">
15393 <features>
15394 <column alignment="center" valignment="top" leftline="true" width="0">
15395 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15396 <column alignment="center" valignment="top" width="0">
15397 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15398 <row topline="true" bottomline="true">
15399 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15400 \begin_inset Text
15401
15402 \layout Standard
15403
15404 Directory
15405 \end_inset 
15406 </cell>
15407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15408 \begin_inset Text
15409
15410 \layout Standard
15411
15412 Description
15413 \end_inset 
15414 </cell>
15415 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15416 \begin_inset Text
15417
15418 \layout Standard
15419
15420 Target
15421 \end_inset 
15422 </cell>
15423 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15424 \begin_inset Text
15425
15426 \layout Standard
15427
15428 Command prefix
15429 \end_inset 
15430 </cell>
15431 </row>
15432 <row topline="true">
15433 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15434 \begin_inset Text
15435
15436 \layout Standard
15437
15438 PREFIX/sdcc/include/pic16
15439 \end_inset 
15440 </cell>
15441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15442 \begin_inset Text
15443
15444 \layout Standard
15445
15446 PIC16 specific headers
15447 \end_inset 
15448 </cell>
15449 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15450 \begin_inset Text
15451
15452 \layout Standard
15453
15454 Compiler
15455 \end_inset 
15456 </cell>
15457 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15458 \begin_inset Text
15459
15460 \layout Standard
15461
15462 -I
15463 \end_inset 
15464 </cell>
15465 </row>
15466 <row topline="true" bottomline="true">
15467 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15468 \begin_inset Text
15469
15470 \layout Standard
15471
15472 PREFIX/sdcc/lib/pic16
15473 \end_inset 
15474 </cell>
15475 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15476 \begin_inset Text
15477
15478 \layout Standard
15479
15480 PIC16 specific libraries
15481 \end_inset 
15482 </cell>
15483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15484 \begin_inset Text
15485
15486 \layout Standard
15487
15488 Linker
15489 \end_inset 
15490 </cell>
15491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15492 \begin_inset Text
15493
15494 \layout Standard
15495
15496 -L
15497 \end_inset 
15498 </cell>
15499 </row>
15500 </lyxtabular>
15501
15502 \end_inset 
15503
15504
15505 \layout Subsection
15506
15507 Pragmas
15508 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
15509
15510 \end_inset 
15511
15512
15513 \layout Standard
15514
15515 PIC16 port currently supports the following pragmas:
15516 \layout List
15517 \labelwidthstring 00.00.0000
15518
15519 stack pragma stack forces the code generator to initialize the stack & frame
15520  pointers at a specific address.
15521  This is an adhoc solution since gplink does not support yet stack.
15522  When the gplink issue is resolved the pragma will be deprecated
15523 \begin_inset Foot
15524 collapsed true
15525
15526 \layout Standard
15527
15528
15529 \emph on 
15530 It is important to initialize the stack, otherwise strange things can happen.
15531  Stack is not initialized by default because there are some sources that
15532  do not require it.
15533  (like library sources)
15534 \end_inset 
15535
15536 .
15537 \newline 
15538 The stack pragma should be used only once in a project.
15539  Multiple pragmas may result in indeterminate behaviour of the program.
15540 \layout LyX-Code
15541
15542 Example:
15543 \layout LyX-Code
15544
15545 \layout LyX-Code
15546
15547 /* initializes stack at RAM address 0x5ff */
15548 \layout LyX-Code
15549
15550 #pragma stack 0x5ff
15551 \layout List
15552 \labelwidthstring 00.00.0000
15553
15554 udata pragma udata instructs the compiler to emit code so that linker will
15555  place a variable at a specific memory bank
15556 \layout LyX-Code
15557
15558 Example:
15559 \layout LyX-Code
15560
15561 \layout LyX-Code
15562
15563 /* places variable foo at bank2 */
15564 \layout LyX-Code
15565
15566 #pragma udata bank2 foo
15567 \layout LyX-Code
15568
15569 char foo;
15570 \layout Standard
15571
15572 In order for this pragma to work there are some changes that must be made
15573  in the .lkr script used in link stage.
15574  In the following example a sample .lkr file is shown:
15575 \layout LyX-Code
15576
15577 \layout LyX-Code
15578
15579 // Sample linker script for the PIC18F452 processor
15580 \layout LyX-Code
15581
15582 LIBPATH .
15583 \layout LyX-Code
15584
15585 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
15586 \layout LyX-Code
15587
15588 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
15589 \layout LyX-Code
15590
15591 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
15592 \layout LyX-Code
15593
15594 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
15595 \layout LyX-Code
15596
15597 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
15598 \layout LyX-Code
15599
15600 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
15601 \layout LyX-Code
15602
15603 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
15604 \layout LyX-Code
15605
15606 \layout LyX-Code
15607
15608 DATABANK   NAME=gpr0       START=0x80           END=0xFF
15609 \layout LyX-Code
15610
15611 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
15612 \layout LyX-Code
15613
15614 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
15615 \layout LyX-Code
15616
15617 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
15618 \layout LyX-Code
15619
15620 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
15621 \layout LyX-Code
15622
15623 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
15624 \layout LyX-Code
15625
15626 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
15627 \layout LyX-Code
15628
15629 \layout LyX-Code
15630
15631 SECTION    NAME=CONFIG     ROM=config
15632 \layout LyX-Code
15633
15634 \layout LyX-Code
15635
15636 SECTION    NAME=bank0      RAM=gpr0
15637 \layout LyX-Code
15638
15639 SECTION    NAME=bank1      RAM=gpr1
15640 \layout LyX-Code
15641
15642 SECTION    NAME=bank2      RAM=gpr2
15643 \layout LyX-Code
15644
15645 SECTION    NAME=bank3      RAM=gpr3
15646 \layout LyX-Code
15647
15648 SECTION    NAME=bank4      RAM=gpr4
15649 \layout LyX-Code
15650
15651 SECTION    NAME=bank5      RAM=gpr5
15652 \layout Standard
15653
15654 The linker will recognise the section name set in the pragma statement and
15655  will position the variable at the memory bank set with the RAM field at
15656  the SECTION line in the linker script file.
15657 \layout Subsection
15658
15659 Header Files
15660 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
15661
15662 \end_inset 
15663
15664
15665 \layout Standard
15666
15667 There is one main header file that can be included to the source files using
15668  the pic16 port.
15669  That file is the 
15670 \series bold 
15671 pic18fregs.h
15672 \series default 
15673 .
15674  This header file contains the definitions for the processor special registers,
15675  so it is necessary if the source accesses them.
15676  It can be included by adding the following line in the beginning of the
15677  file:
15678 \layout LyX-Code
15679
15680 #include <pic18fregs.h>
15681 \layout Standard
15682
15683 The specific microcontroller is selected within the pic18fregs.h automatically,
15684  so the same source can be used with a variety of devices.
15685 \layout Subsection
15686
15687 Libraries
15688 \layout Standard
15689
15690 The libraries that PIC16
15691 \begin_inset LatexCommand \index{PIC16}
15692
15693 \end_inset 
15694
15695  port depends on are the microcontroller device libraries which contain
15696  the symbol definitions for the microcontroller special function registers.
15697  These libraries have the format pic18fxxxx.lib, where 
15698 \emph on 
15699 xxxx
15700 \emph default 
15701  is the microcontroller identification number.
15702  The specific library is selected automatically by the compiler at link
15703  stage according to the selected device.
15704 \layout Standard
15705
15706 Libraries are created with gplib which is part of the gputils package 
15707 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
15708
15709 \end_inset 
15710
15711 .
15712 \layout Subsection
15713
15714 Memory Models
15715 \layout Standard
15716
15717 The following memory models are supported by the PIC16 port:
15718 \layout Itemize
15719
15720 small model
15721 \layout Itemize
15722
15723 large model
15724 \layout Standard
15725
15726 Memory model affects the default size of pointers within the source.
15727  The sizes are shown in the next table:
15728 \layout Standard
15729 \align center 
15730
15731 \begin_inset  Tabular
15732 <lyxtabular version="3" rows="3" columns="3">
15733 <features>
15734 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15735 <column alignment="center" valignment="top" leftline="true" width="0">
15736 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15737 <row topline="true" bottomline="true">
15738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15739 \begin_inset Text
15740
15741 \layout Standard
15742
15743 Pointer sizes according to memory model
15744 \end_inset 
15745 </cell>
15746 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15747 \begin_inset Text
15748
15749 \layout Standard
15750
15751 small model
15752 \end_inset 
15753 </cell>
15754 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15755 \begin_inset Text
15756
15757 \layout Standard
15758
15759 large model
15760 \end_inset 
15761 </cell>
15762 </row>
15763 <row topline="true" bottomline="true">
15764 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15765 \begin_inset Text
15766
15767 \layout Standard
15768
15769 code pointers
15770 \end_inset 
15771 </cell>
15772 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15773 \begin_inset Text
15774
15775 \layout Standard
15776
15777 16-bits
15778 \end_inset 
15779 </cell>
15780 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15781 \begin_inset Text
15782
15783 \layout Standard
15784
15785 24-bits
15786 \end_inset 
15787 </cell>
15788 </row>
15789 <row topline="true" bottomline="true">
15790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15791 \begin_inset Text
15792
15793 \layout Standard
15794
15795 data pointers
15796 \end_inset 
15797 </cell>
15798 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
15799 \begin_inset Text
15800
15801 \layout Standard
15802
15803 16-bits
15804 \end_inset 
15805 </cell>
15806 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15807 \begin_inset Text
15808
15809 \layout Standard
15810
15811 16-bits
15812 \end_inset 
15813 </cell>
15814 </row>
15815 </lyxtabular>
15816
15817 \end_inset 
15818
15819
15820 \layout Standard
15821
15822 It is advisable that all sources within a project are compiled with the
15823  same memory model.
15824  If one wants to override the default memory model, this can be done by
15825  declaring a pointer as 
15826 \series bold 
15827 far
15828 \series default 
15829  or 
15830 \series bold 
15831 near
15832 \series default 
15833 .
15834  Far selects large memory model's pointers, while near selects small memory
15835  model's pointers.
15836 \layout Standard
15837
15838 The standard device libraries (see 
15839 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
15840
15841 \end_inset 
15842
15843 ) contain no reference to pointers, so they can be used with both memory
15844  models.
15845 \layout Subsection
15846
15847 Stack
15848 \layout Standard
15849
15850 The stack implementation for the PIC16 port uses two indirect registers,
15851  FSR1 and FSR2.
15852 \layout List
15853 \labelwidthstring 00.00.0000
15854
15855 FSR1 is assigned as stack pointer
15856 \layout List
15857 \labelwidthstring 00.00.0000
15858
15859 FSR2 is assigned as frame pointer
15860 \layout Standard
15861
15862 The following stack models are supported by the PIC16 port
15863 \layout Itemize
15864
15865 small model
15866 \layout Itemize
15867
15868 large model
15869 \layout Standard
15870
15871
15872 \noun on 
15873 Small
15874 \noun default 
15875  model means that only the FSRxL byte is used to access stack and frame,
15876  while 
15877 \emph on 
15878 \noun on 
15879 large
15880 \emph default 
15881 \noun default 
15882  uses both FSRxL and FSRxH registers.
15883  The following table shows the stack/frame pointers sizes according to stack
15884  model and the maximum space they can address:
15885 \layout Standard
15886 \align center 
15887
15888 \begin_inset  Tabular
15889 <lyxtabular version="3" rows="3" columns="3">
15890 <features>
15891 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15892 <column alignment="center" valignment="top" leftline="true" width="0">
15893 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15894 <row topline="true" bottomline="true">
15895 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15896 \begin_inset Text
15897
15898 \layout Standard
15899
15900 Stack & Frame pointer sizes according to stack model
15901 \end_inset 
15902 </cell>
15903 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15904 \begin_inset Text
15905
15906 \layout Standard
15907
15908 small
15909 \end_inset 
15910 </cell>
15911 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15912 \begin_inset Text
15913
15914 \layout Standard
15915
15916 large
15917 \end_inset 
15918 </cell>
15919 </row>
15920 <row topline="true">
15921 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15922 \begin_inset Text
15923
15924 \layout Standard
15925
15926 Stack pointer FSR1
15927 \end_inset 
15928 </cell>
15929 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15930 \begin_inset Text
15931
15932 \layout Standard
15933
15934 8-bits
15935 \end_inset 
15936 </cell>
15937 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15938 \begin_inset Text
15939
15940 \layout Standard
15941
15942 16-bits
15943 \end_inset 
15944 </cell>
15945 </row>
15946 <row topline="true" bottomline="true">
15947 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15948 \begin_inset Text
15949
15950 \layout Standard
15951
15952 Frame pointer FSR2
15953 \end_inset 
15954 </cell>
15955 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15956 \begin_inset Text
15957
15958 \layout Standard
15959
15960 8-bits
15961 \end_inset 
15962 </cell>
15963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15964 \begin_inset Text
15965
15966 \layout Standard
15967
15968 16-bits
15969 \end_inset 
15970 </cell>
15971 </row>
15972 </lyxtabular>
15973
15974 \end_inset 
15975
15976
15977 \layout Standard
15978
15979
15980 \series bold 
15981 Currently stack and frame pointers should be initialized explicit by the
15982  user at the desired Data RAM position (see 
15983 \begin_inset LatexCommand \ref{sub:PIC16_Pragmas}
15984
15985 \end_inset 
15986
15987  Pragma stack).
15988  Uninitialized stack and frame pointers can result in unexpected behavior
15989  of the resulting binary.
15990 \layout Subsection
15991
15992 Function return values
15993 \layout Standard
15994
15995 Return values from functions are placed to the appropriate registers following
15996  a modified Microchip policy optimized for SDCC.
15997  The following table shows these registers:
15998 \layout Standard
15999 \align center 
16000
16001 \begin_inset  Tabular
16002 <lyxtabular version="3" rows="6" columns="2">
16003 <features>
16004 <column alignment="center" valignment="top" leftline="true" width="0">
16005 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
16006 <row topline="true" bottomline="true">
16007 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16008 \begin_inset Text
16009
16010 \layout Standard
16011
16012 size
16013 \end_inset 
16014 </cell>
16015 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16016 \begin_inset Text
16017
16018 \layout Standard
16019
16020 destination register
16021 \end_inset 
16022 </cell>
16023 </row>
16024 <row topline="true">
16025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16026 \begin_inset Text
16027
16028 \layout Standard
16029
16030 8 bits
16031 \end_inset 
16032 </cell>
16033 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16034 \begin_inset Text
16035
16036 \layout Standard
16037
16038 WREG
16039 \end_inset 
16040 </cell>
16041 </row>
16042 <row topline="true">
16043 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16044 \begin_inset Text
16045
16046 \layout Standard
16047
16048 16 bits
16049 \end_inset 
16050 </cell>
16051 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16052 \begin_inset Text
16053
16054 \layout Standard
16055
16056 PRODL:WREG
16057 \end_inset 
16058 </cell>
16059 </row>
16060 <row topline="true">
16061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16062 \begin_inset Text
16063
16064 \layout Standard
16065
16066 24 bits
16067 \end_inset 
16068 </cell>
16069 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16070 \begin_inset Text
16071
16072 \layout Standard
16073
16074 PRODH:PRODL:WREG
16075 \end_inset 
16076 </cell>
16077 </row>
16078 <row topline="true">
16079 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16080 \begin_inset Text
16081
16082 \layout Standard
16083
16084 32 bits
16085 \end_inset 
16086 </cell>
16087 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16088 \begin_inset Text
16089
16090 \layout Standard
16091
16092 FSR0L:PRODH:PRODL:WREG
16093 \end_inset 
16094 </cell>
16095 </row>
16096 <row topline="true" bottomline="true">
16097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16098 \begin_inset Text
16099
16100 \layout Standard
16101
16102 >32 bits
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 on stack, FSR0 points to the beginning
16111 \end_inset 
16112 </cell>
16113 </row>
16114 </lyxtabular>
16115
16116 \end_inset 
16117
16118
16119 \layout Subsection
16120
16121 Interrupts
16122 \layout Standard
16123
16124 When entering an interrupt, currently the PIC16
16125 \begin_inset LatexCommand \index{PIC16}
16126
16127 \end_inset 
16128
16129  port automatically saves the following registers:
16130 \layout Itemize
16131
16132 WREG
16133 \layout Itemize
16134
16135 STATUS
16136 \layout Itemize
16137
16138 BSR
16139 \layout Itemize
16140
16141 PROD (PRODL and PRODH)
16142 \layout Itemize
16143
16144 FSR0 (FSR0L and FSR0H)
16145 \layout Standard
16146
16147 These registers are restored upon return from the interrupt routine.
16148  
16149 \layout Standard
16150
16151 When entering a high priority interrupt WREG, STATUS and BSR are not explicit
16152  saved by software.
16153  The hardware shadow registers for WREG, STATUS and BSR are used in these
16154  cases.
16155 \layout Standard
16156
16157
16158 \begin_inset Foot
16159 collapsed false
16160
16161 \layout Standard
16162
16163 NOTE that when the _naked attribute is specified for an interrupt routine,
16164  then NO registers are stored or restored.
16165 \end_inset 
16166
16167 .
16168 \layout Chapter
16169
16170 Debugging with SDCDB
16171 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
16172
16173 \end_inset 
16174
16175
16176 \begin_inset LatexCommand \index{sdcdb (debugger)}
16177
16178 \end_inset 
16179
16180  
16181 \layout Standard
16182
16183 SDCC is distributed with a source level debugger
16184 \begin_inset LatexCommand \index{Debugger}
16185
16186 \end_inset 
16187
16188 .
16189  The debugger uses a command line interface, the command repertoire of the
16190  debugger has been kept as close to gdb
16191 \begin_inset LatexCommand \index{gdb}
16192
16193 \end_inset 
16194
16195  (the GNU debugger) as possible.
16196  The configuration and build process is part of the standard compiler installati
16197 on, which also builds and installs the debugger in the target directory
16198  specified during configuration.
16199  The debugger allows you debug BOTH at the C source and at the ASM source
16200  level.
16201  Sdcdb is available on Unix platforms only.
16202 \layout Section
16203
16204 Compiling for Debugging
16205 \layout Standard
16206
16207 The -
16208 \begin_inset ERT
16209 status Collapsed
16210
16211 \layout Standard
16212
16213 \backslash 
16214 /
16215 \end_inset 
16216
16217 -debug
16218 \begin_inset LatexCommand \index{-\/-debug}
16219
16220 \end_inset 
16221
16222  option must be specified for all files for which debug information is to
16223  be generated.
16224  The complier generates a .adb file for each of these files.
16225  The linker creates the .cdb
16226 \begin_inset LatexCommand \index{<file>.cdb}
16227
16228 \end_inset 
16229
16230  file from the .adb
16231 \begin_inset LatexCommand \index{<file>.adb}
16232
16233 \end_inset 
16234
16235  files and the address information.
16236  This .cdb is used by the debugger.
16237 \layout Section
16238
16239 How the Debugger Works
16240 \layout Standard
16241
16242 When the -
16243 \begin_inset ERT
16244 status Collapsed
16245
16246 \layout Standard
16247
16248 \backslash 
16249 /
16250 \end_inset 
16251
16252 -debug option is specified the compiler generates extra symbol information
16253  some of which are put into the assembler source and some are put into the
16254  .adb file.
16255   Then the linker creates the .cdb file from the individual .adb files with
16256  the address information for the symbols.
16257  The debugger reads the symbolic information generated by the compiler &
16258  the address information generated by the linker.
16259  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
16260  execution is controlled by the debugger.
16261  When a command is issued for the debugger, it translates it into appropriate
16262  commands for the simulator.
16263 \layout Section
16264
16265 Starting the Debugger
16266 \layout Standard
16267
16268 The debugger can be started using the following command line.
16269  (Assume the file you are debugging has the file name foo).
16270 \newline 
16271
16272 \newline 
16273
16274 \family sans 
16275 \series bold 
16276 sdcdb foo
16277 \newline 
16278
16279 \family default 
16280 \series default 
16281
16282 \newline 
16283 The debugger will look for the following files.
16284 \layout Itemize
16285
16286 foo.c - the source file.
16287 \layout Itemize
16288
16289 foo.cdb - the debugger symbol information file.
16290 \layout Itemize
16291
16292 foo.ihx - the Intel hex format
16293 \begin_inset LatexCommand \index{Intel hex format}
16294
16295 \end_inset 
16296
16297  object file.
16298 \layout Section
16299
16300 Command Line Options.
16301 \layout Itemize
16302
16303 -
16304 \begin_inset ERT
16305 status Collapsed
16306
16307 \layout Standard
16308
16309 \backslash 
16310 /
16311 \end_inset 
16312
16313 -directory=<source file directory> this option can used to specify the directory
16314  search list.
16315  The debugger will look into the directory list specified for source, cdb
16316  & ihx files.
16317  The items in the directory list must be separated by ':', e.g.
16318  if the source files can be in the directories /home/src1 and /home/src2,
16319  the -
16320 \begin_inset ERT
16321 status Collapsed
16322
16323 \layout Standard
16324
16325 \backslash 
16326 /
16327 \end_inset 
16328
16329 -directory option should be -
16330 \begin_inset ERT
16331 status Collapsed
16332
16333 \layout Standard
16334
16335 \backslash 
16336 /
16337 \end_inset 
16338
16339 -directory=/home/src1:/home/src2.
16340  Note there can be no spaces in the option.
16341  
16342 \layout Itemize
16343
16344 -cd <directory> - change to the <directory>.
16345 \layout Itemize
16346
16347 -fullname - used by GUI front ends.
16348 \layout Itemize
16349
16350 -cpu <cpu-type> - this argument is passed to the simulator please see the
16351  simulator docs for details.
16352 \layout Itemize
16353
16354 -X <Clock frequency > this options is passed to the simulator please see
16355  the simulator docs for details.
16356 \layout Itemize
16357
16358 -s <serial port file> passed to simulator see the simulator docs for details.
16359 \layout Itemize
16360
16361 -S <serial in,out> passed to simulator see the simulator docs for details.
16362 \layout Itemize
16363
16364 -k <port number> passed to simulator see the simulator docs for details.
16365 \layout Section
16366
16367 Debugger Commands.
16368 \layout Standard
16369
16370 As mentioned earlier the command interface for the debugger has been deliberatel
16371 y kept as close the GNU debugger gdb, as possible.
16372  This will help the integration with existing graphical user interfaces
16373  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
16374  If you use a graphical user interface for the debugger you can skip the
16375  next sections.
16376 \layout Subsubsection*
16377
16378 break [line | file:line | function | file:function]
16379 \layout Standard
16380
16381 Set breakpoint at specified line or function:
16382 \newline 
16383
16384 \newline 
16385
16386 \family sans 
16387 \series bold 
16388 sdcdb>break 100 
16389 \newline 
16390 sdcdb>break foo.c:100
16391 \newline 
16392 sdcdb>break funcfoo
16393 \newline 
16394 sdcdb>break foo.c:funcfoo
16395 \layout Subsubsection*
16396
16397 clear [line | file:line | function | file:function ]
16398 \layout Standard
16399
16400 Clear breakpoint at specified line or function:
16401 \newline 
16402
16403 \newline 
16404
16405 \family sans 
16406 \series bold 
16407 sdcdb>clear 100
16408 \newline 
16409 sdcdb>clear foo.c:100
16410 \newline 
16411 sdcdb>clear funcfoo
16412 \newline 
16413 sdcdb>clear foo.c:funcfoo
16414 \layout Subsubsection*
16415
16416 continue
16417 \layout Standard
16418
16419 Continue program being debugged, after breakpoint.
16420 \layout Subsubsection*
16421
16422 finish
16423 \layout Standard
16424
16425 Execute till the end of the current function.
16426 \layout Subsubsection*
16427
16428 delete [n]
16429 \layout Standard
16430
16431 Delete breakpoint number 'n'.
16432  If used without any option clear ALL user defined break points.
16433 \layout Subsubsection*
16434
16435 info [break | stack | frame | registers ]
16436 \layout Itemize
16437
16438 info break - list all breakpoints
16439 \layout Itemize
16440
16441 info stack - show the function call stack.
16442 \layout Itemize
16443
16444 info frame - show information about the current execution frame.
16445 \layout Itemize
16446
16447 info registers - show content of all registers.
16448 \layout Subsubsection*
16449
16450 step
16451 \layout Standard
16452
16453 Step program until it reaches a different source line.
16454  Note: pressing <return> repeats the last command.
16455 \layout Subsubsection*
16456
16457 next
16458 \layout Standard
16459
16460 Step program, proceeding through subroutine calls.
16461 \layout Subsubsection*
16462
16463 run
16464 \layout Standard
16465
16466 Start debugged program.
16467 \layout Subsubsection*
16468
16469 ptype variable 
16470 \layout Standard
16471
16472 Print type information of the variable.
16473 \layout Subsubsection*
16474
16475 print variable
16476 \layout Standard
16477
16478 print value of variable.
16479 \layout Subsubsection*
16480
16481 file filename
16482 \layout Standard
16483
16484 load the given file name.
16485  Note this is an alternate method of loading file for debugging.
16486 \layout Subsubsection*
16487
16488 frame
16489 \layout Standard
16490
16491 print information about current frame.
16492 \layout Subsubsection*
16493
16494 set srcmode
16495 \layout Standard
16496
16497 Toggle between C source & assembly source.
16498 \layout Subsubsection*
16499
16500 ! simulator command
16501 \layout Standard
16502
16503 Send the string following '!' to the simulator, the simulator response is
16504  displayed.
16505  Note the debugger does not interpret the command being sent to the simulator,
16506  so if a command like 'go' is sent the debugger can loose its execution
16507  context and may display incorrect values.
16508 \layout Subsubsection*
16509
16510 quit
16511 \layout Standard
16512
16513 "Watch me now.
16514  Iam going Down.
16515  My name is Bobby Brown"
16516 \layout Section
16517
16518 Interfacing with XEmacs
16519 \begin_inset LatexCommand \index{XEmacs}
16520
16521 \end_inset 
16522
16523
16524 \begin_inset LatexCommand \index{Emacs}
16525
16526 \end_inset 
16527
16528 .
16529 \layout Standard
16530
16531 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
16532  sdcdb.el and sdcdbsrc.el.
16533  These two files can be found in the $(prefix)/bin directory after the installat
16534 ion is complete.
16535  These files need to be loaded into XEmacs for the interface to work.
16536  This can be done at XEmacs startup time by inserting the following into
16537  your '.xemacs' file (which can be found in your HOME directory): 
16538 \newline 
16539
16540 \newline 
16541
16542 \family typewriter 
16543 (load-file sdcdbsrc.el) 
16544 \family default 
16545
16546 \newline 
16547
16548 \newline 
16549 .xemacs is a lisp file so the () around the command is REQUIRED.
16550  The files can also be loaded dynamically while XEmacs is running, set the
16551  environment variable 'EMACSLOADPATH' to the installation bin directory
16552  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
16553  To start the interface enter the following command: 
16554 \newline 
16555
16556 \newline 
16557
16558 \family sans 
16559 \series bold 
16560 ESC-x sdcdbsrc
16561 \family default 
16562 \series default 
16563
16564 \newline 
16565
16566 \newline 
16567 You will prompted to enter the file name to be debugged.
16568  
16569 \newline 
16570
16571 \newline 
16572 The command line options that are passed to the simulator directly are bound
16573  to default values in the file sdcdbsrc.el.
16574  The variables are listed below, these values maybe changed as required.
16575 \layout Itemize
16576
16577 sdcdbsrc-cpu-type '51
16578 \layout Itemize
16579
16580 sdcdbsrc-frequency '11059200
16581 \layout Itemize
16582
16583 sdcdbsrc-serial nil
16584 \layout Standard
16585
16586 The following is a list of key mapping for the debugger interface.
16587 \layout Standard
16588
16589 \SpecialChar ~
16590
16591 \family typewriter 
16592
16593 \newline 
16594 ;;\SpecialChar ~
16595 Current Listing :: 
16596 \newline 
16597 ;;key\SpecialChar ~
16598 \SpecialChar ~
16599 \SpecialChar ~
16600 \SpecialChar ~
16601 \SpecialChar ~
16602 \SpecialChar ~
16603 \SpecialChar ~
16604 \SpecialChar ~
16605 \SpecialChar ~
16606 \SpecialChar ~
16607 \SpecialChar ~
16608 \SpecialChar ~
16609 \SpecialChar ~
16610 \SpecialChar ~
16611 binding\SpecialChar ~
16612 \SpecialChar ~
16613 \SpecialChar ~
16614 \SpecialChar ~
16615 \SpecialChar ~
16616 \SpecialChar ~
16617 \SpecialChar ~
16618 \SpecialChar ~
16619 \SpecialChar ~
16620 \SpecialChar ~
16621 \SpecialChar ~
16622 \SpecialChar ~
16623 \SpecialChar ~
16624 \SpecialChar ~
16625 \SpecialChar ~
16626 \SpecialChar ~
16627 \SpecialChar ~
16628 \SpecialChar ~
16629 \SpecialChar ~
16630 \SpecialChar ~
16631 \SpecialChar ~
16632 \SpecialChar ~
16633 Comment 
16634 \newline 
16635 ;;---\SpecialChar ~
16636 \SpecialChar ~
16637 \SpecialChar ~
16638 \SpecialChar ~
16639 \SpecialChar ~
16640 \SpecialChar ~
16641 \SpecialChar ~
16642 \SpecialChar ~
16643 \SpecialChar ~
16644 \SpecialChar ~
16645 \SpecialChar ~
16646 \SpecialChar ~
16647 \SpecialChar ~
16648 \SpecialChar ~
16649 -------\SpecialChar ~
16650 \SpecialChar ~
16651 \SpecialChar ~
16652 \SpecialChar ~
16653 \SpecialChar ~
16654 \SpecialChar ~
16655 \SpecialChar ~
16656 \SpecialChar ~
16657 \SpecialChar ~
16658 \SpecialChar ~
16659 \SpecialChar ~
16660 \SpecialChar ~
16661 \SpecialChar ~
16662 \SpecialChar ~
16663 \SpecialChar ~
16664 \SpecialChar ~
16665 \SpecialChar ~
16666 \SpecialChar ~
16667 \SpecialChar ~
16668 \SpecialChar ~
16669 \SpecialChar ~
16670 \SpecialChar ~
16671 -------
16672 \newline 
16673 ;; 
16674 \newline 
16675 ;;\SpecialChar ~
16676 n\SpecialChar ~
16677 \SpecialChar ~
16678 \SpecialChar ~
16679 \SpecialChar ~
16680 \SpecialChar ~
16681 \SpecialChar ~
16682 \SpecialChar ~
16683 \SpecialChar ~
16684 \SpecialChar ~
16685 \SpecialChar ~
16686 \SpecialChar ~
16687 \SpecialChar ~
16688 \SpecialChar ~
16689 \SpecialChar ~
16690 \SpecialChar ~
16691 sdcdb-next-from-src\SpecialChar ~
16692 \SpecialChar ~
16693 \SpecialChar ~
16694 \SpecialChar ~
16695 \SpecialChar ~
16696 \SpecialChar ~
16697 \SpecialChar ~
16698 \SpecialChar ~
16699 \SpecialChar ~
16700 \SpecialChar ~
16701 SDCDB next command 
16702 \newline 
16703 ;;\SpecialChar ~
16704 b\SpecialChar ~
16705 \SpecialChar ~
16706 \SpecialChar ~
16707 \SpecialChar ~
16708 \SpecialChar ~
16709 \SpecialChar ~
16710 \SpecialChar ~
16711 \SpecialChar ~
16712 \SpecialChar ~
16713 \SpecialChar ~
16714 \SpecialChar ~
16715 \SpecialChar ~
16716 \SpecialChar ~
16717 \SpecialChar ~
16718 \SpecialChar ~
16719 sdcdb-back-from-src\SpecialChar ~
16720 \SpecialChar ~
16721 \SpecialChar ~
16722 \SpecialChar ~
16723 \SpecialChar ~
16724 \SpecialChar ~
16725 \SpecialChar ~
16726 \SpecialChar ~
16727 \SpecialChar ~
16728 \SpecialChar ~
16729 SDCDB back command 
16730 \newline 
16731 ;;\SpecialChar ~
16732 c\SpecialChar ~
16733 \SpecialChar ~
16734 \SpecialChar ~
16735 \SpecialChar ~
16736 \SpecialChar ~
16737 \SpecialChar ~
16738 \SpecialChar ~
16739 \SpecialChar ~
16740 \SpecialChar ~
16741 \SpecialChar ~
16742 \SpecialChar ~
16743 \SpecialChar ~
16744 \SpecialChar ~
16745 \SpecialChar ~
16746 \SpecialChar ~
16747 sdcdb-cont-from-src\SpecialChar ~
16748 \SpecialChar ~
16749 \SpecialChar ~
16750 \SpecialChar ~
16751 \SpecialChar ~
16752 \SpecialChar ~
16753 \SpecialChar ~
16754 \SpecialChar ~
16755 \SpecialChar ~
16756 \SpecialChar ~
16757 SDCDB continue command
16758 \newline 
16759 ;;\SpecialChar ~
16760 s\SpecialChar ~
16761 \SpecialChar ~
16762 \SpecialChar ~
16763 \SpecialChar ~
16764 \SpecialChar ~
16765 \SpecialChar ~
16766 \SpecialChar ~
16767 \SpecialChar ~
16768 \SpecialChar ~
16769 \SpecialChar ~
16770 \SpecialChar ~
16771 \SpecialChar ~
16772 \SpecialChar ~
16773 \SpecialChar ~
16774 \SpecialChar ~
16775 sdcdb-step-from-src\SpecialChar ~
16776 \SpecialChar ~
16777 \SpecialChar ~
16778 \SpecialChar ~
16779 \SpecialChar ~
16780 \SpecialChar ~
16781 \SpecialChar ~
16782 \SpecialChar ~
16783 \SpecialChar ~
16784 \SpecialChar ~
16785 SDCDB step command 
16786 \newline 
16787 ;;\SpecialChar ~
16788 ?\SpecialChar ~
16789 \SpecialChar ~
16790 \SpecialChar ~
16791 \SpecialChar ~
16792 \SpecialChar ~
16793 \SpecialChar ~
16794 \SpecialChar ~
16795 \SpecialChar ~
16796 \SpecialChar ~
16797 \SpecialChar ~
16798 \SpecialChar ~
16799 \SpecialChar ~
16800 \SpecialChar ~
16801 \SpecialChar ~
16802 \SpecialChar ~
16803 sdcdb-whatis-c-sexp\SpecialChar ~
16804 \SpecialChar ~
16805 \SpecialChar ~
16806 \SpecialChar ~
16807 \SpecialChar ~
16808 \SpecialChar ~
16809 \SpecialChar ~
16810 \SpecialChar ~
16811 \SpecialChar ~
16812 \SpecialChar ~
16813 SDCDB ptypecommand for data at 
16814 \newline 
16815 ;;\SpecialChar ~
16816 \SpecialChar ~
16817 \SpecialChar ~
16818 \SpecialChar ~
16819 \SpecialChar ~
16820 \SpecialChar ~
16821 \SpecialChar ~
16822 \SpecialChar ~
16823 \SpecialChar ~
16824 \SpecialChar ~
16825 \SpecialChar ~
16826 \SpecialChar ~
16827 \SpecialChar ~
16828 \SpecialChar ~
16829 \SpecialChar ~
16830 \SpecialChar ~
16831 \SpecialChar ~
16832 \SpecialChar ~
16833 \SpecialChar ~
16834 \SpecialChar ~
16835 \SpecialChar ~
16836 \SpecialChar ~
16837 \SpecialChar ~
16838 \SpecialChar ~
16839 \SpecialChar ~
16840 \SpecialChar ~
16841 \SpecialChar ~
16842 \SpecialChar ~
16843 \SpecialChar ~
16844 \SpecialChar ~
16845 \SpecialChar ~
16846 \SpecialChar ~
16847 \SpecialChar ~
16848 \SpecialChar ~
16849 \SpecialChar ~
16850 \SpecialChar ~
16851 \SpecialChar ~
16852 \SpecialChar ~
16853 \SpecialChar ~
16854 \SpecialChar ~
16855 \SpecialChar ~
16856 \SpecialChar ~
16857 \SpecialChar ~
16858 \SpecialChar ~
16859 \SpecialChar ~
16860 \SpecialChar ~
16861 \SpecialChar ~
16862 buffer point 
16863 \newline 
16864 ;;\SpecialChar ~
16865 x\SpecialChar ~
16866 \SpecialChar ~
16867 \SpecialChar ~
16868 \SpecialChar ~
16869 \SpecialChar ~
16870 \SpecialChar ~
16871 \SpecialChar ~
16872 \SpecialChar ~
16873 \SpecialChar ~
16874 \SpecialChar ~
16875 \SpecialChar ~
16876 \SpecialChar ~
16877 \SpecialChar ~
16878 \SpecialChar ~
16879 \SpecialChar ~
16880 sdcdbsrc-delete\SpecialChar ~
16881 \SpecialChar ~
16882 \SpecialChar ~
16883 \SpecialChar ~
16884 \SpecialChar ~
16885 \SpecialChar ~
16886 \SpecialChar ~
16887 \SpecialChar ~
16888 \SpecialChar ~
16889 \SpecialChar ~
16890 \SpecialChar ~
16891 \SpecialChar ~
16892 \SpecialChar ~
16893 \SpecialChar ~
16894 SDCDB Delete all breakpoints if no arg 
16895 \newline 
16896 ;;\SpecialChar ~
16897 \SpecialChar ~
16898 \SpecialChar ~
16899 \SpecialChar ~
16900 \SpecialChar ~
16901 \SpecialChar ~
16902 \SpecialChar ~
16903 \SpecialChar ~
16904 \SpecialChar ~
16905 \SpecialChar ~
16906 \SpecialChar ~
16907 \SpecialChar ~
16908 \SpecialChar ~
16909 \SpecialChar ~
16910 \SpecialChar ~
16911 \SpecialChar ~
16912 \SpecialChar ~
16913 \SpecialChar ~
16914 \SpecialChar ~
16915 \SpecialChar ~
16916 \SpecialChar ~
16917 \SpecialChar ~
16918 \SpecialChar ~
16919 \SpecialChar ~
16920 \SpecialChar ~
16921 \SpecialChar ~
16922 \SpecialChar ~
16923 \SpecialChar ~
16924 \SpecialChar ~
16925 \SpecialChar ~
16926 \SpecialChar ~
16927 \SpecialChar ~
16928 \SpecialChar ~
16929 \SpecialChar ~
16930 \SpecialChar ~
16931 \SpecialChar ~
16932 \SpecialChar ~
16933 \SpecialChar ~
16934 \SpecialChar ~
16935 \SpecialChar ~
16936 \SpecialChar ~
16937 \SpecialChar ~
16938 \SpecialChar ~
16939 \SpecialChar ~
16940 \SpecialChar ~
16941 \SpecialChar ~
16942 \SpecialChar ~
16943 given or delete arg (C-u arg x) 
16944 \newline 
16945 ;;\SpecialChar ~
16946 m\SpecialChar ~
16947 \SpecialChar ~
16948 \SpecialChar ~
16949 \SpecialChar ~
16950 \SpecialChar ~
16951 \SpecialChar ~
16952 \SpecialChar ~
16953 \SpecialChar ~
16954 \SpecialChar ~
16955 \SpecialChar ~
16956 \SpecialChar ~
16957 \SpecialChar ~
16958 \SpecialChar ~
16959 \SpecialChar ~
16960 \SpecialChar ~
16961 sdcdbsrc-frame\SpecialChar ~
16962 \SpecialChar ~
16963 \SpecialChar ~
16964 \SpecialChar ~
16965 \SpecialChar ~
16966 \SpecialChar ~
16967 \SpecialChar ~
16968 \SpecialChar ~
16969 \SpecialChar ~
16970 \SpecialChar ~
16971 \SpecialChar ~
16972 \SpecialChar ~
16973 \SpecialChar ~
16974 \SpecialChar ~
16975 \SpecialChar ~
16976 SDCDB Display current frame if no arg, 
16977 \newline 
16978 ;;\SpecialChar ~
16979 \SpecialChar ~
16980 \SpecialChar ~
16981 \SpecialChar ~
16982 \SpecialChar ~
16983 \SpecialChar ~
16984 \SpecialChar ~
16985 \SpecialChar ~
16986 \SpecialChar ~
16987 \SpecialChar ~
16988 \SpecialChar ~
16989 \SpecialChar ~
16990 \SpecialChar ~
16991 \SpecialChar ~
16992 \SpecialChar ~
16993 \SpecialChar ~
16994 \SpecialChar ~
16995 \SpecialChar ~
16996 \SpecialChar ~
16997 \SpecialChar ~
16998 \SpecialChar ~
16999 \SpecialChar ~
17000 \SpecialChar ~
17001 \SpecialChar ~
17002 \SpecialChar ~
17003 \SpecialChar ~
17004 \SpecialChar ~
17005 \SpecialChar ~
17006 \SpecialChar ~
17007 \SpecialChar ~
17008 \SpecialChar ~
17009 \SpecialChar ~
17010 \SpecialChar ~
17011 \SpecialChar ~
17012 \SpecialChar ~
17013 \SpecialChar ~
17014 \SpecialChar ~
17015 \SpecialChar ~
17016 \SpecialChar ~
17017 \SpecialChar ~
17018 \SpecialChar ~
17019 \SpecialChar ~
17020 \SpecialChar ~
17021 \SpecialChar ~
17022 \SpecialChar ~
17023 \SpecialChar ~
17024 \SpecialChar ~
17025 given or display frame arg 
17026 \newline 
17027 ;;\SpecialChar ~
17028 \SpecialChar ~
17029 \SpecialChar ~
17030 \SpecialChar ~
17031 \SpecialChar ~
17032 \SpecialChar ~
17033 \SpecialChar ~
17034 \SpecialChar ~
17035 \SpecialChar ~
17036 \SpecialChar ~
17037 \SpecialChar ~
17038 \SpecialChar ~
17039 \SpecialChar ~
17040 \SpecialChar ~
17041 \SpecialChar ~
17042 \SpecialChar ~
17043 \SpecialChar ~
17044 \SpecialChar ~
17045 \SpecialChar ~
17046 \SpecialChar ~
17047 \SpecialChar ~
17048 \SpecialChar ~
17049 \SpecialChar ~
17050 \SpecialChar ~
17051 \SpecialChar ~
17052 \SpecialChar ~
17053 \SpecialChar ~
17054 \SpecialChar ~
17055 \SpecialChar ~
17056 \SpecialChar ~
17057 \SpecialChar ~
17058 \SpecialChar ~
17059 \SpecialChar ~
17060 \SpecialChar ~
17061 \SpecialChar ~
17062 \SpecialChar ~
17063 \SpecialChar ~
17064 \SpecialChar ~
17065 \SpecialChar ~
17066 \SpecialChar ~
17067 \SpecialChar ~
17068 \SpecialChar ~
17069 \SpecialChar ~
17070 \SpecialChar ~
17071 \SpecialChar ~
17072 \SpecialChar ~
17073 \SpecialChar ~
17074 buffer point 
17075 \newline 
17076 ;;\SpecialChar ~
17077 !\SpecialChar ~
17078 \SpecialChar ~
17079 \SpecialChar ~
17080 \SpecialChar ~
17081 \SpecialChar ~
17082 \SpecialChar ~
17083 \SpecialChar ~
17084 \SpecialChar ~
17085 \SpecialChar ~
17086 \SpecialChar ~
17087 \SpecialChar ~
17088 \SpecialChar ~
17089 \SpecialChar ~
17090 \SpecialChar ~
17091 \SpecialChar ~
17092 sdcdbsrc-goto-sdcdb\SpecialChar ~
17093 \SpecialChar ~
17094 \SpecialChar ~
17095 \SpecialChar ~
17096 \SpecialChar ~
17097 \SpecialChar ~
17098 \SpecialChar ~
17099 \SpecialChar ~
17100 \SpecialChar ~
17101 \SpecialChar ~
17102 Goto the SDCDB output buffer 
17103 \newline 
17104 ;;\SpecialChar ~
17105 p\SpecialChar ~
17106 \SpecialChar ~
17107 \SpecialChar ~
17108 \SpecialChar ~
17109 \SpecialChar ~
17110 \SpecialChar ~
17111 \SpecialChar ~
17112 \SpecialChar ~
17113 \SpecialChar ~
17114 \SpecialChar ~
17115 \SpecialChar ~
17116 \SpecialChar ~
17117 \SpecialChar ~
17118 \SpecialChar ~
17119 \SpecialChar ~
17120 sdcdb-print-c-sexp\SpecialChar ~
17121 \SpecialChar ~
17122 \SpecialChar ~
17123 \SpecialChar ~
17124 \SpecialChar ~
17125 \SpecialChar ~
17126 \SpecialChar ~
17127 \SpecialChar ~
17128 \SpecialChar ~
17129 \SpecialChar ~
17130 \SpecialChar ~
17131 SDCDB print command for data at 
17132 \newline 
17133 ;;\SpecialChar ~
17134 \SpecialChar ~
17135 \SpecialChar ~
17136 \SpecialChar ~
17137 \SpecialChar ~
17138 \SpecialChar ~
17139 \SpecialChar ~
17140 \SpecialChar ~
17141 \SpecialChar ~
17142 \SpecialChar ~
17143 \SpecialChar ~
17144 \SpecialChar ~
17145 \SpecialChar ~
17146 \SpecialChar ~
17147 \SpecialChar ~
17148 \SpecialChar ~
17149 \SpecialChar ~
17150 \SpecialChar ~
17151 \SpecialChar ~
17152 \SpecialChar ~
17153 \SpecialChar ~
17154 \SpecialChar ~
17155 \SpecialChar ~
17156 \SpecialChar ~
17157 \SpecialChar ~
17158 \SpecialChar ~
17159 \SpecialChar ~
17160 \SpecialChar ~
17161 \SpecialChar ~
17162 \SpecialChar ~
17163 \SpecialChar ~
17164 \SpecialChar ~
17165 \SpecialChar ~
17166 \SpecialChar ~
17167 \SpecialChar ~
17168 \SpecialChar ~
17169 \SpecialChar ~
17170 \SpecialChar ~
17171 \SpecialChar ~
17172 \SpecialChar ~
17173 \SpecialChar ~
17174 \SpecialChar ~
17175 \SpecialChar ~
17176 \SpecialChar ~
17177 \SpecialChar ~
17178 \SpecialChar ~
17179 \SpecialChar ~
17180 buffer point 
17181 \newline 
17182 ;;\SpecialChar ~
17183 g\SpecialChar ~
17184 \SpecialChar ~
17185 \SpecialChar ~
17186 \SpecialChar ~
17187 \SpecialChar ~
17188 \SpecialChar ~
17189 \SpecialChar ~
17190 \SpecialChar ~
17191 \SpecialChar ~
17192 \SpecialChar ~
17193 \SpecialChar ~
17194 \SpecialChar ~
17195 \SpecialChar ~
17196 \SpecialChar ~
17197 \SpecialChar ~
17198 sdcdbsrc-goto-sdcdb\SpecialChar ~
17199 \SpecialChar ~
17200 \SpecialChar ~
17201 \SpecialChar ~
17202 \SpecialChar ~
17203 \SpecialChar ~
17204 \SpecialChar ~
17205 \SpecialChar ~
17206 \SpecialChar ~
17207 \SpecialChar ~
17208 Goto the SDCDB output buffer 
17209 \newline 
17210 ;;\SpecialChar ~
17211 t\SpecialChar ~
17212 \SpecialChar ~
17213 \SpecialChar ~
17214 \SpecialChar ~
17215 \SpecialChar ~
17216 \SpecialChar ~
17217 \SpecialChar ~
17218 \SpecialChar ~
17219 \SpecialChar ~
17220 \SpecialChar ~
17221 \SpecialChar ~
17222 \SpecialChar ~
17223 \SpecialChar ~
17224 \SpecialChar ~
17225 \SpecialChar ~
17226 sdcdbsrc-mode\SpecialChar ~
17227 \SpecialChar ~
17228 \SpecialChar ~
17229 \SpecialChar ~
17230 \SpecialChar ~
17231 \SpecialChar ~
17232 \SpecialChar ~
17233 \SpecialChar ~
17234 \SpecialChar ~
17235 \SpecialChar ~
17236 \SpecialChar ~
17237 \SpecialChar ~
17238 \SpecialChar ~
17239 \SpecialChar ~
17240 \SpecialChar ~
17241 \SpecialChar ~
17242 Toggles Sdcdbsrc mode (turns it off) 
17243 \newline 
17244 ;; 
17245 \newline 
17246 ;;\SpecialChar ~
17247 C-c\SpecialChar ~
17248 C-f\SpecialChar ~
17249 \SpecialChar ~
17250 \SpecialChar ~
17251 \SpecialChar ~
17252 \SpecialChar ~
17253 \SpecialChar ~
17254 \SpecialChar ~
17255 \SpecialChar ~
17256 \SpecialChar ~
17257 sdcdb-finish-from-src\SpecialChar ~
17258 \SpecialChar ~
17259 \SpecialChar ~
17260 \SpecialChar ~
17261 \SpecialChar ~
17262 \SpecialChar ~
17263 \SpecialChar ~
17264 \SpecialChar ~
17265 SDCDB finish command 
17266 \newline 
17267 ;; 
17268 \newline 
17269 ;;\SpecialChar ~
17270 C-x\SpecialChar ~
17271 SPC\SpecialChar ~
17272 \SpecialChar ~
17273 \SpecialChar ~
17274 \SpecialChar ~
17275 \SpecialChar ~
17276 \SpecialChar ~
17277 \SpecialChar ~
17278 \SpecialChar ~
17279 \SpecialChar ~
17280 sdcdb-break\SpecialChar ~
17281 \SpecialChar ~
17282 \SpecialChar ~
17283 \SpecialChar ~
17284 \SpecialChar ~
17285 \SpecialChar ~
17286 \SpecialChar ~
17287 \SpecialChar ~
17288 \SpecialChar ~
17289 \SpecialChar ~
17290 \SpecialChar ~
17291 \SpecialChar ~
17292 \SpecialChar ~
17293 \SpecialChar ~
17294 \SpecialChar ~
17295 \SpecialChar ~
17296 \SpecialChar ~
17297 \SpecialChar ~
17298 Set break for line with point 
17299 \newline 
17300 ;;\SpecialChar ~
17301 ESC\SpecialChar ~
17302 t\SpecialChar ~
17303 \SpecialChar ~
17304 \SpecialChar ~
17305 \SpecialChar ~
17306 \SpecialChar ~
17307 \SpecialChar ~
17308 \SpecialChar ~
17309 \SpecialChar ~
17310 \SpecialChar ~
17311 \SpecialChar ~
17312 \SpecialChar ~
17313 sdcdbsrc-mode\SpecialChar ~
17314 \SpecialChar ~
17315 \SpecialChar ~
17316 \SpecialChar ~
17317 \SpecialChar ~
17318 \SpecialChar ~
17319 \SpecialChar ~
17320 \SpecialChar ~
17321 \SpecialChar ~
17322 \SpecialChar ~
17323 \SpecialChar ~
17324 \SpecialChar ~
17325 \SpecialChar ~
17326 \SpecialChar ~
17327 \SpecialChar ~
17328 \SpecialChar ~
17329 Toggle Sdcdbsrc mode 
17330 \newline 
17331 ;;\SpecialChar ~
17332 ESC\SpecialChar ~
17333 m\SpecialChar ~
17334 \SpecialChar ~
17335 \SpecialChar ~
17336 \SpecialChar ~
17337 \SpecialChar ~
17338 \SpecialChar ~
17339 \SpecialChar ~
17340 \SpecialChar ~
17341 \SpecialChar ~
17342 \SpecialChar ~
17343 \SpecialChar ~
17344 sdcdbsrc-srcmode\SpecialChar ~
17345 \SpecialChar ~
17346 \SpecialChar ~
17347 \SpecialChar ~
17348 \SpecialChar ~
17349 \SpecialChar ~
17350 \SpecialChar ~
17351 \SpecialChar ~
17352 \SpecialChar ~
17353 \SpecialChar ~
17354 \SpecialChar ~
17355 \SpecialChar ~
17356 \SpecialChar ~
17357 Toggle list mode 
17358 \newline 
17359 ;; 
17360 \newline 
17361
17362 \layout Chapter
17363 \pagebreak_top 
17364 TIPS
17365 \layout Standard
17366
17367 Here are a few guidelines that will help the compiler generate more efficient
17368  code, some of the tips are specific to this compiler others are generally
17369  good programming practice.
17370 \layout Itemize
17371
17372 Use the smallest data type to represent your data-value.
17373  If it is known in advance that the value is going to be less than 256 then
17374  use an 'unsigned char' instead of a 'short' or 'int'.
17375  Please note, that ANSI C requires both signed and unsigned chars to be
17376  promoted to 'signed int' before doing any operation.
17377  This promotion can be omitted, if the result is the same.
17378  The effect of the promotion rules together with the sign-extension is often
17379  surprising:
17380 \begin_deeper 
17381 \layout Verse
17382
17383
17384 \family typewriter 
17385 unsigned char uc = 0xfe;
17386 \newline 
17387 if (uc * uc < 0) /* this is true! */
17388 \newline 
17389 {
17390 \newline 
17391 \SpecialChar ~
17392 \SpecialChar ~
17393 \SpecialChar ~
17394 \SpecialChar ~
17395 ....
17396 \newline 
17397 }
17398 \layout Standard
17399
17400
17401 \family typewriter 
17402 uc * uc
17403 \family default 
17404  is evaluated as 
17405 \family typewriter 
17406 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
17407 \family default 
17408 .
17409  
17410 \newline 
17411 Another one:
17412 \layout Verse
17413
17414
17415 \family typewriter 
17416 (unsigned char) -12 / (signed char) -3 = ...
17417 \layout Standard
17418
17419 No, the result is not 4:
17420 \layout Verse
17421
17422
17423 \family typewriter 
17424 (int) (unsigned char) -12 / (int) (signed char) -3 =
17425 \newline 
17426 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
17427 \newline 
17428 (int) 0x00f4 / (int) 0xfffd =
17429 \newline 
17430 (int) 0x00f4 / (int) 0xfffd =
17431 \newline 
17432 (int) 244 / (int) -3 =
17433 \newline 
17434 (int) -81 = (int) 0xffaf;
17435 \layout Standard
17436
17437 Don't complain, that gcc gives you a different result.
17438  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
17439  Therefore the results are different.
17440 \newline 
17441 From 
17442 \begin_inset Quotes sld
17443 \end_inset 
17444
17445 comp.lang.c FAQ
17446 \begin_inset Quotes srd
17447 \end_inset 
17448
17449 :
17450 \layout Quote
17451
17452 If well-defined overflow characteristics are important and negative values
17453  are not, or if you want to steer clear of sign-extension problems when
17454  manipulating bits or bytes, use one of the corresponding unsigned types.
17455  (Beware when mixing signed and unsigned values in expressions, though.)
17456 \newline 
17457 Although character types (especially unsigned char) can be used as "tiny"
17458  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
17459 ble sign extension and increased code size.
17460 \end_deeper 
17461 \layout Itemize
17462
17463 Use unsigned when it is known in advance that the value is not going to
17464  be negative.
17465  This helps especially if you are doing division or multiplication, bit-shifting
17466  or are using an array index.
17467 \layout Itemize
17468
17469 NEVER jump into a LOOP.
17470 \layout Itemize
17471
17472 Declare the variables to be local
17473 \begin_inset LatexCommand \index{local variables}
17474
17475 \end_inset 
17476
17477  whenever possible, especially loop control variables (induction).
17478 \layout Itemize
17479
17480 Since the compiler does not always do implicit integral promotion, the programme
17481 r should do an explicit cast when integral promotion is required.
17482 \layout Itemize
17483
17484 Reducing the size of division, multiplication & modulus operations can reduce
17485  code size substantially.
17486  Take the following code for example.
17487 \begin_deeper 
17488 \layout Verse
17489
17490
17491 \family typewriter 
17492 foobar(unsigned int p1, unsigned char ch)
17493 \newline 
17494 {
17495 \newline 
17496 \SpecialChar ~
17497 \SpecialChar ~
17498 \SpecialChar ~
17499 \SpecialChar ~
17500 unsigned char ch1 = p1 % ch ;
17501 \newline 
17502 \SpecialChar ~
17503 \SpecialChar ~
17504 \SpecialChar ~
17505 \SpecialChar ~
17506 ....
17507 \newline 
17508 }
17509 \layout Standard
17510
17511 For the modulus operation the variable ch will be promoted to unsigned int
17512  first then the modulus operation will be performed (this will lead to a
17513  call to support routine _moduint()), and the result will be casted to a
17514  char.
17515  If the code is changed to 
17516 \layout Verse
17517
17518
17519 \family typewriter 
17520 foobar(unsigned int p1, unsigned char ch)
17521 \newline 
17522 {
17523 \newline 
17524 \SpecialChar ~
17525 \SpecialChar ~
17526 \SpecialChar ~
17527 \SpecialChar ~
17528 unsigned char ch1 = (unsigned char)p1 % ch ;
17529 \newline 
17530 \SpecialChar ~
17531 \SpecialChar ~
17532 \SpecialChar ~
17533 \SpecialChar ~
17534 ....
17535 \newline 
17536 }
17537 \layout Standard
17538
17539 It would substantially reduce the code generated (future versions of the
17540  compiler will be smart enough to detect such optimization opportunities).
17541 \end_deeper 
17542 \layout Itemize
17543
17544 Have a look at the assembly listing to get a 
17545 \begin_inset Quotes sld
17546 \end_inset 
17547
17548 feeling
17549 \begin_inset Quotes srd
17550 \end_inset 
17551
17552  for the code generation.
17553 \layout Section
17554
17555 Tools
17556 \begin_inset LatexCommand \index{Tools}
17557
17558 \end_inset 
17559
17560  included in the distribution
17561 \layout Standard
17562 \align center 
17563
17564 \begin_inset  Tabular
17565 <lyxtabular version="3" rows="12" columns="3">
17566 <features>
17567 <column alignment="center" valignment="top" leftline="true" width="0pt">
17568 <column alignment="center" valignment="top" leftline="true" width="0pt">
17569 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
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 Name
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 Purpose
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 Directory
17593 \end_inset 
17594 </cell>
17595 </row>
17596 <row topline="true">
17597 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17598 \begin_inset Text
17599
17600 \layout Standard
17601
17602 uCsim
17603 \end_inset 
17604 </cell>
17605 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17606 \begin_inset Text
17607
17608 \layout Standard
17609
17610 Simulator for various architectures
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 sdcc/sim/ucsim
17619 \end_inset 
17620 </cell>
17621 </row>
17622 <row topline="true">
17623 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17624 \begin_inset Text
17625
17626 \layout Standard
17627
17628 keil2sdcc.pl
17629 \end_inset 
17630 </cell>
17631 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17632 \begin_inset Text
17633
17634 \layout Standard
17635
17636 header file conversion
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 sdcc/support/scripts
17645 \end_inset 
17646 </cell>
17647 </row>
17648 <row topline="true">
17649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17650 \begin_inset Text
17651
17652 \layout Standard
17653
17654 mh2h.c
17655 \end_inset 
17656 </cell>
17657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17658 \begin_inset Text
17659
17660 \layout Standard
17661
17662 header file conversion
17663 \end_inset 
17664 </cell>
17665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17666 \begin_inset Text
17667
17668 \layout Standard
17669
17670 sdcc/support/scripts
17671 \end_inset 
17672 </cell>
17673 </row>
17674 <row topline="true">
17675 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17676 \begin_inset Text
17677
17678 \layout Standard
17679
17680 as-gbz80
17681 \end_inset 
17682 </cell>
17683 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17684 \begin_inset Text
17685
17686 \layout Standard
17687
17688 Assembler
17689 \end_inset 
17690 </cell>
17691 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17692 \begin_inset Text
17693
17694 \layout Standard
17695
17696
17697 \family roman 
17698 \series medium 
17699 \shape up 
17700 \size normal 
17701 \emph off 
17702 \bar no 
17703 \noun off 
17704 \color none
17705 sdcc/bin
17706 \end_inset 
17707 </cell>
17708 </row>
17709 <row topline="true">
17710 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17711 \begin_inset Text
17712
17713 \layout Standard
17714
17715 as-z80
17716 \end_inset 
17717 </cell>
17718 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17719 \begin_inset Text
17720
17721 \layout Standard
17722
17723 Assembler
17724 \end_inset 
17725 </cell>
17726 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17727 \begin_inset Text
17728
17729 \layout Standard
17730
17731
17732 \family roman 
17733 \series medium 
17734 \shape up 
17735 \size normal 
17736 \emph off 
17737 \bar no 
17738 \noun off 
17739 \color none
17740 sdcc/bin
17741 \end_inset 
17742 </cell>
17743 </row>
17744 <row topline="true">
17745 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17746 \begin_inset Text
17747
17748 \layout Standard
17749
17750 asx8051
17751 \end_inset 
17752 </cell>
17753 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17754 \begin_inset Text
17755
17756 \layout Standard
17757
17758 Assembler
17759 \end_inset 
17760 </cell>
17761 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17762 \begin_inset Text
17763
17764 \layout Standard
17765
17766
17767 \family roman 
17768 \series medium 
17769 \shape up 
17770 \size normal 
17771 \emph off 
17772 \bar no 
17773 \noun off 
17774 \color none
17775 sdcc/bin
17776 \end_inset 
17777 </cell>
17778 </row>
17779 <row topline="true">
17780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17781 \begin_inset Text
17782
17783 \layout Standard
17784
17785 sdcdb
17786 \end_inset 
17787 </cell>
17788 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17789 \begin_inset Text
17790
17791 \layout Standard
17792
17793 Simulator
17794 \end_inset 
17795 </cell>
17796 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17797 \begin_inset Text
17798
17799 \layout Standard
17800
17801
17802 \family roman 
17803 \series medium 
17804 \shape up 
17805 \size normal 
17806 \emph off 
17807 \bar no 
17808 \noun off 
17809 \color none
17810 sdcc/bin
17811 \end_inset 
17812 </cell>
17813 </row>
17814 <row topline="true">
17815 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17816 \begin_inset Text
17817
17818 \layout Standard
17819
17820 aslink
17821 \end_inset 
17822 </cell>
17823 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17824 \begin_inset Text
17825
17826 \layout Standard
17827
17828 Linker
17829 \end_inset 
17830 </cell>
17831 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17832 \begin_inset Text
17833
17834 \layout Standard
17835
17836
17837 \family roman 
17838 \series medium 
17839 \shape up 
17840 \size normal 
17841 \emph off 
17842 \bar no 
17843 \noun off 
17844 \color none
17845 sdcc/bin
17846 \end_inset 
17847 </cell>
17848 </row>
17849 <row topline="true">
17850 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17851 \begin_inset Text
17852
17853 \layout Standard
17854
17855 link-z80
17856 \end_inset 
17857 </cell>
17858 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17859 \begin_inset Text
17860
17861 \layout Standard
17862
17863 Linker
17864 \end_inset 
17865 </cell>
17866 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17867 \begin_inset Text
17868
17869 \layout Standard
17870
17871
17872 \family roman 
17873 \series medium 
17874 \shape up 
17875 \size normal 
17876 \emph off 
17877 \bar no 
17878 \noun off 
17879 \color none
17880 sdcc/bin
17881 \end_inset 
17882 </cell>
17883 </row>
17884 <row topline="true">
17885 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17886 \begin_inset Text
17887
17888 \layout Standard
17889
17890 link-gbz80
17891 \end_inset 
17892 </cell>
17893 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17894 \begin_inset Text
17895
17896 \layout Standard
17897
17898 Linker
17899 \end_inset 
17900 </cell>
17901 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17902 \begin_inset Text
17903
17904 \layout Standard
17905
17906
17907 \family roman 
17908 \series medium 
17909 \shape up 
17910 \size normal 
17911 \emph off 
17912 \bar no 
17913 \noun off 
17914 \color none
17915 sdcc/bin
17916 \end_inset 
17917 </cell>
17918 </row>
17919 <row topline="true" bottomline="true">
17920 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17921 \begin_inset Text
17922
17923 \layout Standard
17924
17925 packihx
17926 \end_inset 
17927 </cell>
17928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17929 \begin_inset Text
17930
17931 \layout Standard
17932
17933 ihx packer
17934 \end_inset 
17935 </cell>
17936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17937 \begin_inset Text
17938
17939 \layout Standard
17940
17941
17942 \family roman 
17943 \series medium 
17944 \shape up 
17945 \size normal 
17946 \emph off 
17947 \bar no 
17948 \noun off 
17949 \color none
17950 sdcc/bin
17951 \end_inset 
17952 </cell>
17953 </row>
17954 </lyxtabular>
17955
17956 \end_inset 
17957
17958
17959 \newline 
17960
17961 \layout Section
17962
17963 Documentation
17964 \begin_inset LatexCommand \index{Documentation}
17965
17966 \end_inset 
17967
17968  included in the distribution
17969 \layout Standard
17970 \align center 
17971
17972 \begin_inset  Tabular
17973 <lyxtabular version="3" rows="10" columns="2">
17974 <features>
17975 <column alignment="left" valignment="top" leftline="true" width="0">
17976 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
17977 <row topline="true" bottomline="true">
17978 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17979 \begin_inset Text
17980
17981 \layout Standard
17982
17983 Subject / Title
17984 \end_inset 
17985 </cell>
17986 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17987 \begin_inset Text
17988
17989 \layout Standard
17990
17991 Where to get / filename
17992 \end_inset 
17993 </cell>
17994 </row>
17995 <row topline="true">
17996 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17997 \begin_inset Text
17998
17999 \layout Standard
18000
18001 SDCC Compiler User Guide
18002 \end_inset 
18003 </cell>
18004 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18005 \begin_inset Text
18006
18007 \layout Standard
18008
18009 You're reading it right now
18010 \end_inset 
18011 </cell>
18012 </row>
18013 <row topline="true">
18014 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18015 \begin_inset Text
18016
18017 \layout Standard
18018
18019 Changelog of SDCC
18020 \end_inset 
18021 </cell>
18022 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18023 \begin_inset Text
18024
18025 \layout Standard
18026
18027 sdcc/Changelog
18028 \end_inset 
18029 </cell>
18030 </row>
18031 <row topline="true">
18032 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18033 \begin_inset Text
18034
18035 \layout Standard
18036
18037 ASXXXX Assemblers and ASLINK Relocating Linker
18038 \end_inset 
18039 </cell>
18040 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18041 \begin_inset Text
18042
18043 \layout Standard
18044
18045 sdcc/as/doc/asxhtm.html
18046 \end_inset 
18047 </cell>
18048 </row>
18049 <row topline="true">
18050 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18051 \begin_inset Text
18052
18053 \layout Standard
18054
18055 SDCC regression test
18056 \begin_inset LatexCommand \index{Regression test}
18057
18058 \end_inset 
18059
18060
18061 \end_inset 
18062 </cell>
18063 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18064 \begin_inset Text
18065
18066 \layout Standard
18067
18068 sdcc/doc/test_suite_spec.pdf
18069 \end_inset 
18070 </cell>
18071 </row>
18072 <row topline="true">
18073 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18074 \begin_inset Text
18075
18076 \layout Standard
18077
18078 Various notes
18079 \end_inset 
18080 </cell>
18081 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18082 \begin_inset Text
18083
18084 \layout Standard
18085
18086 sdcc/doc/*
18087 \end_inset 
18088 </cell>
18089 </row>
18090 <row topline="true">
18091 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18092 \begin_inset Text
18093
18094 \layout Standard
18095
18096 Notes on debugging with sdcdb
18097 \begin_inset LatexCommand \index{sdcdb (debugger)}
18098
18099 \end_inset 
18100
18101
18102 \end_inset 
18103 </cell>
18104 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18105 \begin_inset Text
18106
18107 \layout Standard
18108
18109 sdcc/debugger/README
18110 \end_inset 
18111 </cell>
18112 </row>
18113 <row topline="true">
18114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18115 \begin_inset Text
18116
18117 \layout Standard
18118
18119 Software simulator for microcontrollers
18120 \end_inset 
18121 </cell>
18122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18123 \begin_inset Text
18124
18125 \layout Standard
18126
18127
18128 \family roman 
18129 \series medium 
18130 \shape up 
18131 \size normal 
18132 \emph off 
18133 \bar no 
18134 \noun off 
18135 \color none
18136 sdcc/sim/ucsim/doc
18137 \family default 
18138 \series default 
18139 \shape default 
18140 \size default 
18141 \emph default 
18142 \bar default 
18143 \noun default 
18144 \color default
18145 /index.html
18146 \end_inset 
18147 </cell>
18148 </row>
18149 <row topline="true">
18150 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18151 \begin_inset Text
18152
18153 \layout Standard
18154
18155 Temporary notes on the pic16
18156 \begin_inset LatexCommand \index{PIC16}
18157
18158 \end_inset 
18159
18160  port
18161 \end_inset 
18162 </cell>
18163 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18164 \begin_inset Text
18165
18166 \layout Standard
18167
18168 sdcc/src/pic16/NOTES
18169 \end_inset 
18170 </cell>
18171 </row>
18172 <row topline="true" bottomline="true">
18173 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18174 \begin_inset Text
18175
18176 \layout Standard
18177
18178 SDCC internal documentation (debugging file format)
18179 \end_inset 
18180 </cell>
18181 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18182 \begin_inset Text
18183
18184 \layout Standard
18185
18186 sdcc/doc/
18187 \family roman 
18188 \series medium 
18189 \shape up 
18190 \size normal 
18191 \emph off 
18192 \bar no 
18193 \noun off 
18194 \color none
18195 cdbfileformat.pd
18196 \family default 
18197 \series default 
18198 \shape default 
18199 \size default 
18200 \emph default 
18201 \bar default 
18202 \noun default 
18203 \color default
18204 f
18205 \end_inset 
18206 </cell>
18207 </row>
18208 </lyxtabular>
18209
18210 \end_inset 
18211
18212
18213 \newline 
18214
18215 \layout Section
18216
18217 Related open source tools
18218 \begin_inset LatexCommand \index{Related tools}
18219
18220 \end_inset 
18221
18222
18223 \layout Standard
18224 \align center 
18225
18226 \begin_inset  Tabular
18227 <lyxtabular version="3" rows="11" columns="3">
18228 <features>
18229 <column alignment="center" valignment="top" leftline="true" width="0pt">
18230 <column alignment="block" valignment="top" leftline="true" width="30line%">
18231 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18232 <row topline="true" bottomline="true">
18233 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18234 \begin_inset Text
18235
18236 \layout Standard
18237
18238 Name
18239 \end_inset 
18240 </cell>
18241 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18242 \begin_inset Text
18243
18244 \layout Standard
18245
18246 Purpose
18247 \end_inset 
18248 </cell>
18249 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18250 \begin_inset Text
18251
18252 \layout Standard
18253
18254 Where to get
18255 \end_inset 
18256 </cell>
18257 </row>
18258 <row topline="true">
18259 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18260 \begin_inset Text
18261
18262 \layout Standard
18263
18264 gpsim
18265 \begin_inset LatexCommand \index{gpsim (pic simulator)}
18266
18267 \end_inset 
18268
18269
18270 \end_inset 
18271 </cell>
18272 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18273 \begin_inset Text
18274
18275 \layout Standard
18276
18277 PIC simulator
18278 \end_inset 
18279 </cell>
18280 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18281 \begin_inset Text
18282
18283 \layout Standard
18284
18285
18286 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
18287
18288 \end_inset 
18289
18290
18291 \end_inset 
18292 </cell>
18293 </row>
18294 <row topline="true">
18295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18296 \begin_inset Text
18297
18298 \layout Standard
18299
18300 gputils
18301 \begin_inset LatexCommand \index{gputils (pic tools)}
18302
18303 \end_inset 
18304
18305
18306 \end_inset 
18307 </cell>
18308 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18309 \begin_inset Text
18310
18311 \layout Standard
18312
18313 GNU PIC utilities
18314 \end_inset 
18315 </cell>
18316 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18317 \begin_inset Text
18318
18319 \layout Standard
18320
18321
18322 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
18323
18324 \end_inset 
18325
18326
18327 \end_inset 
18328 </cell>
18329 </row>
18330 <row topline="true">
18331 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18332 \begin_inset Text
18333
18334 \layout Standard
18335
18336 flP5
18337 \end_inset 
18338 </cell>
18339 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18340 \begin_inset Text
18341
18342 \layout Standard
18343
18344 PIC programmer
18345 \end_inset 
18346 </cell>
18347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18348 \begin_inset Text
18349
18350 \layout Standard
18351
18352
18353 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
18354
18355 \end_inset 
18356
18357
18358 \end_inset 
18359 </cell>
18360 </row>
18361 <row topline="true">
18362 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18363 \begin_inset Text
18364
18365 \layout Standard
18366
18367 indent
18368 \begin_inset LatexCommand \index{indent (source formatting tool)}
18369
18370 \end_inset 
18371
18372
18373 \end_inset 
18374 </cell>
18375 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18376 \begin_inset Text
18377
18378 \layout Standard
18379
18380 Formats C source - Master of the white spaces
18381 \end_inset 
18382 </cell>
18383 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18384 \begin_inset Text
18385
18386 \layout Standard
18387
18388
18389 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
18390
18391 \end_inset 
18392
18393
18394 \end_inset 
18395 </cell>
18396 </row>
18397 <row topline="true">
18398 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18399 \begin_inset Text
18400
18401 \layout Standard
18402
18403 srecord
18404 \begin_inset LatexCommand \index{srecord (tool)}
18405
18406 \end_inset 
18407
18408
18409 \end_inset 
18410 </cell>
18411 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18412 \begin_inset Text
18413
18414 \layout Standard
18415
18416 Object file conversion, checksumming, ...
18417 \end_inset 
18418 </cell>
18419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18420 \begin_inset Text
18421
18422 \layout Standard
18423
18424
18425 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
18426
18427 \end_inset 
18428
18429
18430 \end_inset 
18431 </cell>
18432 </row>
18433 <row topline="true">
18434 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18435 \begin_inset Text
18436
18437 \layout Standard
18438
18439 objdump
18440 \begin_inset LatexCommand \index{objdump (tool)}
18441
18442 \end_inset 
18443
18444
18445 \end_inset 
18446 </cell>
18447 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18448 \begin_inset Text
18449
18450 \layout Standard
18451
18452 Object file conversion, ...
18453 \end_inset 
18454 </cell>
18455 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18456 \begin_inset Text
18457
18458 \layout Standard
18459
18460 Part of binutils (should be there anyway)
18461 \end_inset 
18462 </cell>
18463 </row>
18464 <row topline="true">
18465 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18466 \begin_inset Text
18467
18468 \layout Standard
18469
18470 doxygen
18471 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
18472
18473 \end_inset 
18474
18475
18476 \end_inset 
18477 </cell>
18478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18479 \begin_inset Text
18480
18481 \layout Standard
18482
18483 Source code documentation system
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 \begin_inset LatexCommand \url{http://www.doxygen.org}
18493
18494 \end_inset 
18495
18496
18497 \end_inset 
18498 </cell>
18499 </row>
18500 <row topline="true">
18501 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18502 \begin_inset Text
18503
18504 \layout Standard
18505
18506 kdevelop
18507 \end_inset 
18508 </cell>
18509 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18510 \begin_inset Text
18511
18512 \layout Standard
18513
18514 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
18515 \end_inset 
18516 </cell>
18517 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18518 \begin_inset Text
18519
18520 \layout Standard
18521
18522
18523 \begin_inset LatexCommand \url{http://www.kdevelop.org}
18524
18525 \end_inset 
18526
18527
18528 \end_inset 
18529 </cell>
18530 </row>
18531 <row topline="true">
18532 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18533 \begin_inset Text
18534
18535 \layout Standard
18536
18537 splint
18538 \begin_inset LatexCommand \index{splint (syntax checking tool)}
18539
18540 \end_inset 
18541
18542
18543 \end_inset 
18544 </cell>
18545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18546 \begin_inset Text
18547
18548 \layout Standard
18549
18550 Statically checks c sources (has anyone adapted splint for SDCC?)
18551 \end_inset 
18552 </cell>
18553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18554 \begin_inset Text
18555
18556 \layout Standard
18557
18558
18559 \begin_inset LatexCommand \url{http://www.splint.org}
18560
18561 \end_inset 
18562
18563
18564 \end_inset 
18565 </cell>
18566 </row>
18567 <row topline="true" bottomline="true">
18568 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18569 \begin_inset Text
18570
18571 \layout Standard
18572
18573 ddd
18574 \begin_inset LatexCommand \index{ddd (debugger)}
18575
18576 \end_inset 
18577
18578
18579 \end_inset 
18580 </cell>
18581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18582 \begin_inset Text
18583
18584 \layout Standard
18585
18586 Debugger, serves nicely as GUI to sdcdb
18587 \begin_inset LatexCommand \index{sdcdb (debugger)}
18588
18589 \end_inset 
18590
18591  (Unix only)
18592 \end_inset 
18593 </cell>
18594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18595 \begin_inset Text
18596
18597 \layout Standard
18598
18599
18600 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
18601
18602 \end_inset 
18603
18604
18605 \end_inset 
18606 </cell>
18607 </row>
18608 </lyxtabular>
18609
18610 \end_inset 
18611
18612
18613 \newline 
18614
18615 \layout Section
18616
18617 Related documentation / recommended reading
18618 \layout Standard
18619 \align center 
18620
18621 \begin_inset  Tabular
18622 <lyxtabular version="3" rows="6" columns="3">
18623 <features>
18624 <column alignment="center" valignment="top" leftline="true" width="0pt">
18625 <column alignment="block" valignment="top" leftline="true" width="30line%">
18626 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18627 <row topline="true" bottomline="true">
18628 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18629 \begin_inset Text
18630
18631 \layout Standard
18632
18633 Name
18634 \end_inset 
18635 </cell>
18636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18637 \begin_inset Text
18638
18639 \layout Standard
18640
18641 Subject / Title
18642 \end_inset 
18643 </cell>
18644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18645 \begin_inset Text
18646
18647 \layout Standard
18648
18649 Where to get
18650 \end_inset 
18651 </cell>
18652 </row>
18653 <row topline="true">
18654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18655 \begin_inset Text
18656
18657 \layout Standard
18658
18659
18660 \family roman 
18661 \series medium 
18662 \shape up 
18663 \size normal 
18664 \emph off 
18665 \bar no 
18666 \noun off 
18667 \color none
18668 c-refcard.pdf
18669 \end_inset 
18670 </cell>
18671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18672 \begin_inset Text
18673
18674 \layout Standard
18675
18676 C Reference Card
18677 \begin_inset LatexCommand \index{C Reference card}
18678
18679 \end_inset 
18680
18681 , 2 pages
18682 \end_inset 
18683 </cell>
18684 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18685 \begin_inset Text
18686
18687 \layout Standard
18688
18689
18690 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
18691
18692 \end_inset 
18693
18694
18695 \end_inset 
18696 </cell>
18697 </row>
18698 <row topline="true">
18699 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18700 \begin_inset Text
18701
18702 \layout Standard
18703
18704 c-faq
18705 \end_inset 
18706 </cell>
18707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18708 \begin_inset Text
18709
18710 \layout Standard
18711
18712 C-FAQ-list
18713 \end_inset 
18714 </cell>
18715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18716 \begin_inset Text
18717
18718 \layout Standard
18719
18720
18721 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
18722
18723 \end_inset 
18724
18725
18726 \end_inset 
18727 </cell>
18728 </row>
18729 <row topline="true">
18730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18731 \begin_inset Text
18732
18733 \layout Standard
18734
18735 \end_inset 
18736 </cell>
18737 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18738 \begin_inset Text
18739
18740 \layout Standard
18741
18742 Latest datasheet of the target CPU
18743 \end_inset 
18744 </cell>
18745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18746 \begin_inset Text
18747
18748 \layout Standard
18749
18750 vendor
18751 \end_inset 
18752 </cell>
18753 </row>
18754 <row topline="true">
18755 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18756 \begin_inset Text
18757
18758 \layout Standard
18759
18760 \end_inset 
18761 </cell>
18762 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18763 \begin_inset Text
18764
18765 \layout Standard
18766
18767 Revision history of datasheet
18768 \end_inset 
18769 </cell>
18770 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18771 \begin_inset Text
18772
18773 \layout Standard
18774
18775 vendor
18776 \end_inset 
18777 </cell>
18778 </row>
18779 <row topline="true" bottomline="true">
18780 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18781 \begin_inset Text
18782
18783 \layout Standard
18784
18785 S.
18786  S.
18787  Muchnick
18788 \end_inset 
18789 </cell>
18790 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18791 \begin_inset Text
18792
18793 \layout Standard
18794
18795 Advanced Compiler Design and Implementation
18796 \end_inset 
18797 </cell>
18798 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18799 \begin_inset Text
18800
18801 \layout Standard
18802
18803 bookstore (very dedicated, probably read other books first)
18804 \end_inset 
18805 </cell>
18806 </row>
18807 </lyxtabular>
18808
18809 \end_inset 
18810
18811
18812 \newline 
18813
18814 \layout Section
18815
18816 Some Questions
18817 \layout Standard
18818
18819 Some questions answered, some pointers given - it might be time to in turn
18820  ask 
18821 \emph on 
18822 you
18823 \emph default 
18824  some questions: 
18825 \layout Itemize
18826
18827 can you solve your project with the selected microcontroller? Would you
18828  find out early or rather late that your target is too small/slow/whatever?
18829  Can you switch to a slightly better device if it doesn't fit?
18830 \layout Itemize
18831
18832 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
18833  and/or another programming language be more adequate? Would an operating
18834  system on the target device help?
18835 \layout Itemize
18836
18837 if you solved the problem, will the marketing department be happy?
18838 \layout Itemize
18839
18840 if the marketing department is happy, will customers be happy?
18841 \layout Itemize
18842
18843 if you're the project manager, marketing department and maybe even the customer
18844  in one person, have you tried to see the project from the outside?
18845 \layout Itemize
18846
18847 is the project done if you think it is done? Or is just that other interface/pro
18848 tocol/feature/configuration/option missing? How about website, manual(s),
18849  internationali(z|s)ation, packaging, labels, 2nd source for components,
18850  electromagnetic compatability/interference, documentation for production,
18851  production test software, update mechanism, patent issues?
18852 \layout Itemize
18853
18854 is your project adequately positioned in that magic triangle: fame, fortune,
18855  fun?
18856 \layout Standard
18857
18858 Maybe not all answers to these questions are known and some answers may
18859  even be 
18860 \emph on 
18861 no
18862 \emph default 
18863 , nevertheless knowing these questions may help you to avoid burnout
18864 \begin_inset Foot
18865 collapsed false
18866
18867 \layout Standard
18868
18869 burnout is bad for electronic devices, programmers and motorcycle tyres
18870 \end_inset 
18871
18872 .
18873  Chances are you didn't want to hear some of them...
18874 \layout Chapter
18875
18876 Support
18877 \begin_inset LatexCommand \index{Support}
18878
18879 \end_inset 
18880
18881
18882 \layout Standard
18883
18884 SDCC has grown to be a large project.
18885  The compiler alone (without the preprocessor, assembler and linker) is
18886  well over 100,000 lines of code (blank stripped).
18887  The open source nature of this project is a key to its continued growth
18888  and support.
18889  You gain the benefit and support of many active software developers and
18890  end users.
18891  Is SDCC perfect? No, that's why we need your help.
18892  The developers take pride in fixing reported bugs.
18893  You can help by reporting the bugs and helping other SDCC users.
18894  There are lots of ways to contribute, and we encourage you to take part
18895  in making SDCC a great software package.
18896  
18897 \layout Standard
18898
18899 The SDCC project is hosted on the SDCC sourceforge site at 
18900 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
18901
18902 \end_inset 
18903
18904 .
18905  You'll find the complete set of mailing lists
18906 \begin_inset LatexCommand \index{Mailing list(s)}
18907
18908 \end_inset 
18909
18910 , forums, bug reporting system, patch submission
18911 \begin_inset LatexCommand \index{Patch submission}
18912
18913 \end_inset 
18914
18915  system, download
18916 \begin_inset LatexCommand \index{download}
18917
18918 \end_inset 
18919
18920  area and cvs code repository
18921 \begin_inset LatexCommand \index{cvs code repository}
18922
18923 \end_inset 
18924
18925  there.
18926 \layout Section
18927
18928 Reporting Bugs
18929 \begin_inset LatexCommand \index{Bug reporting}
18930
18931 \end_inset 
18932
18933
18934 \begin_inset LatexCommand \index{Reporting bugs}
18935
18936 \end_inset 
18937
18938
18939 \layout Standard
18940
18941 The recommended way of reporting bugs is using the infrastructure of the
18942  sourceforge site.
18943  You can follow the status of bug reports there and have an overview about
18944  the known bugs.
18945 \layout Standard
18946
18947 Bug reports are automatically forwarded to the developer mailing list and
18948  will be fixed ASAP.
18949  When reporting a bug, it is very useful to include a small test program
18950  (the smaller the better) which reproduces the problem.
18951  If you can isolate the problem by looking at the generated assembly code,
18952  this can be very helpful.
18953  Compiling your program with the -
18954 \begin_inset ERT
18955 status Collapsed
18956
18957 \layout Standard
18958
18959 \backslash 
18960 /
18961 \end_inset 
18962
18963 -dumpall
18964 \begin_inset LatexCommand \index{-\/-dumpall}
18965
18966 \end_inset 
18967
18968  option can sometimes be useful in locating optimization problems.
18969  When reporting a bug please maker sure you:
18970 \layout Enumerate
18971
18972 Attach the code you are compiling with SDCC.
18973  
18974 \layout Enumerate
18975
18976 Specify the exact command you use to run SDCC, or attach your Makefile.
18977  
18978 \layout Enumerate
18979
18980 Specify the SDCC version (type "
18981 \family sans 
18982 \series bold 
18983 sdcc -v
18984 \family default 
18985 \series default 
18986 "), your platform, and operating system.
18987  
18988 \layout Enumerate
18989
18990 Provide an exact copy of any error message or incorrect output.
18991  
18992 \layout Enumerate
18993
18994 Put something meaningful in the subject of your message.
18995 \layout Standard
18996
18997 Please attempt to include these 5 important parts, as applicable, in all
18998  requests for support or when reporting any problems or bugs with SDCC.
18999  Though this will make your message lengthy, it will greatly improve your
19000  chance that SDCC users and developers will be able to help you.
19001  Some SDCC developers are frustrated by bug reports without code provided
19002  that they can use to reproduce and ultimately fix the problem, so please
19003  be sure to provide sample code if you are reporting a bug! 
19004 \layout Standard
19005
19006 Please have a short check that you are using a recent version of SDCC and
19007  the bug is not yet known.
19008  This is the link for reporting bugs: 
19009 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
19010
19011 \end_inset 
19012
19013 .
19014 \layout Section
19015
19016 Requesting Features
19017 \begin_inset LatexCommand \label{sub:Requesting-Features}
19018
19019 \end_inset 
19020
19021
19022 \begin_inset LatexCommand \index{Feature request}
19023
19024 \end_inset 
19025
19026
19027 \begin_inset LatexCommand \index{Requesting features}
19028
19029 \end_inset 
19030
19031
19032 \layout Standard
19033
19034 Like bug reports feature requests are forwarded to the developer mailing
19035  list.
19036  This is the link for requesting features: 
19037 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
19038
19039 \end_inset 
19040
19041 .
19042 \layout Section
19043
19044 Submitting patches
19045 \layout Standard
19046
19047 Like bug reports contributed patches are forwarded to the developer mailing
19048  list.
19049  This is the link for submitting patches
19050 \begin_inset LatexCommand \index{Patch submission}
19051
19052 \end_inset 
19053
19054
19055 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
19056
19057 \end_inset 
19058
19059 .
19060 \layout Standard
19061
19062 You need to specify some parameters to the 
19063 \family typewriter 
19064 diff
19065 \family default 
19066  command for the patches to be useful.
19067  If you modified more than one file a patch created f.e.
19068  with 
19069 \family sans 
19070 \series bold 
19071
19072 \begin_inset Quotes sld
19073 \end_inset 
19074
19075 diff -Naur unmodified_directory modified_directory >my_changes.patch
19076 \begin_inset Quotes srd
19077 \end_inset 
19078
19079
19080 \family default 
19081 \series default 
19082  will be fine, otherwise 
19083 \family sans 
19084 \series bold 
19085
19086 \begin_inset Quotes sld
19087 \end_inset 
19088
19089 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
19090 \begin_inset Quotes srd
19091 \end_inset 
19092
19093
19094 \series default 
19095  
19096 \family default 
19097 will do.
19098 \layout Section
19099
19100 Getting Help
19101 \layout Standard
19102
19103 These links should take you directly to the 
19104 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
19105
19106 \end_inset 
19107
19108
19109 \begin_inset Foot
19110 collapsed false
19111
19112 \layout Standard
19113
19114 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
19115  automated messages (mid 2003)
19116 \end_inset 
19117
19118  and the 
19119 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
19120
19121 \end_inset 
19122
19123 , lists
19124 \begin_inset LatexCommand \index{Mailing list(s)}
19125
19126 \end_inset 
19127
19128  and forums are archived and searchable so if you are lucky someone already
19129  had a similar problem.
19130  While mails to the lists themselves are delivered promptly their web front
19131  end on sourceforge sometimes shows a severe time lag (up to several weeks),
19132  if you're seriously using SDCC please consider subscribing to the lists.
19133 \layout Section
19134
19135 ChangeLog
19136 \layout Standard
19137
19138 You can follow the status of the cvs version
19139 \begin_inset LatexCommand \index{version}
19140
19141 \end_inset 
19142
19143  of SDCC by watching the Changelog
19144 \begin_inset LatexCommand \index{Changelog}
19145
19146 \end_inset 
19147
19148  in the cvs-repository
19149 \newline 
19150
19151 \size footnotesize 
19152
19153 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
19154
19155 \end_inset 
19156
19157 .
19158 \layout Section
19159
19160 Release policy
19161 \begin_inset LatexCommand \index{Release policy}
19162
19163 \end_inset 
19164
19165
19166 \layout Standard
19167
19168 Historically there often were long delays between official releases and
19169  the sourceforge download area tends to get not updated at all.
19170  Excuses in the past might have referred to problems with live range analysis,
19171  but as this was fixed a while ago, the current problem is that another
19172  excuse has to be found.
19173  Kidding aside, we have to get better there! On the other hand there are
19174  daily snapshots available at 
19175 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
19176
19177 \end_inset 
19178
19179 , and you can always build the very last version (hopefully with many bugs
19180  fixed, and features added) from the source code available at 
19181 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
19182
19183 \end_inset 
19184
19185 .
19186 \layout Section
19187
19188 Examples
19189 \begin_inset LatexCommand \index{Examples}
19190
19191 \end_inset 
19192
19193
19194 \layout Standard
19195
19196 You'll find some small examples in the directory 
19197 \emph on 
19198 sdcc/device/examples/.
19199  
19200 \emph default 
19201 More examples and libraries are available at
19202 \emph on 
19203  The SDCC Open Knowledge Resource 
19204 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
19205
19206 \end_inset 
19207
19208  
19209 \emph default 
19210 web site or at 
19211 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
19212
19213 \end_inset 
19214
19215 .
19216 \layout Comment
19217
19218 I did insert a reference to Paul's web site here although it seems rather
19219  dedicated to a specific 8032 board (I think it's okay because it f.e.
19220  shows LCD/Harddisc interface and has a free 8051 monitor.
19221  Independent 8032 board vendors face hard competition of heavily subsidized
19222  development boards anyway).
19223 \layout Comment
19224
19225 Maybe we should include some links to real world applications.
19226  Preferably pointer to pointers (one for each architecture) so this stays
19227  manageable here?
19228 \layout Section
19229
19230 Quality control
19231 \begin_inset LatexCommand \index{Quality control}
19232
19233 \end_inset 
19234
19235
19236 \layout Standard
19237
19238 The compiler is passed through nightly compile and build checks.
19239  The so called 
19240 \shape italic 
19241 regression tests
19242 \shape default 
19243
19244 \begin_inset LatexCommand \index{Regression test}
19245
19246 \end_inset 
19247
19248  check that SDCC itself compiles flawlessly on several platforms and checks
19249  the quality of the code generated by SDCC by running the code through simulator
19250 s.
19251  There is a separate document 
19252 \shape italic 
19253 test_suite.pdf
19254 \begin_inset LatexCommand \index{Test suite}
19255
19256 \end_inset 
19257
19258
19259 \shape default 
19260  about this.
19261 \layout Standard
19262
19263 You'll find the test code in the directory 
19264 \shape italic 
19265 sdcc/support/regression
19266 \shape default 
19267 .
19268  You can run these tests manually by running 
19269 \family sans 
19270 make
19271 \family default 
19272  in this directory (or f.e.
19273  
19274 \family sans 
19275 \series bold 
19276
19277 \begin_inset Quotes sld
19278 \end_inset 
19279
19280 make test-mcs51
19281 \begin_inset Quotes srd
19282 \end_inset 
19283
19284
19285 \family default 
19286 \series default 
19287  if you don't want to run the complete tests).
19288  The test code might also be interesting if you want to look for examples
19289 \begin_inset LatexCommand \index{Examples}
19290
19291 \end_inset 
19292
19293  checking corner cases of SDCC or if you plan to submit patches
19294 \begin_inset LatexCommand \index{Patch submission}
19295
19296 \end_inset 
19297
19298 .
19299 \layout Standard
19300
19301 The pic port uses a different set of regression tests, you'll find them
19302  in the directory 
19303 \shape italic 
19304 sdcc/src/regression
19305 \shape default 
19306 .
19307 \layout Chapter
19308 \pagebreak_top 
19309 SDCC Technical Data
19310 \layout Section
19311
19312 Optimizations
19313 \begin_inset LatexCommand \index{Optimizations}
19314
19315 \end_inset 
19316
19317
19318 \layout Standard
19319
19320 SDCC performs a host of standard optimizations in addition to some MCU specific
19321  optimizations.
19322  
19323 \layout Subsection
19324
19325 Sub-expression Elimination
19326 \begin_inset LatexCommand \index{Subexpression elimination}
19327
19328 \end_inset 
19329
19330
19331 \layout Standard
19332
19333 The compiler does local and 
19334 \emph on 
19335 g
19336 \emph default 
19337 lobal 
19338 \emph on 
19339 c
19340 \emph default 
19341 ommon 
19342 \emph on 
19343 s
19344 \emph default 
19345 ubexpression 
19346 \emph on 
19347 e
19348 \emph default 
19349 limination, e.g.: 
19350 \layout Verse
19351
19352
19353 \family typewriter 
19354 i = x + y + 1; 
19355 \newline 
19356 j = x + y;
19357 \layout Standard
19358
19359 will be translated to
19360 \layout Verse
19361
19362
19363 \family typewriter 
19364 iTemp = x + y; 
19365 \newline 
19366 i = iTemp + 1; 
19367 \newline 
19368 j = iTemp;
19369 \layout Standard
19370
19371 Some subexpressions are not as obvious as the above example, e.g.:
19372 \layout Verse
19373
19374
19375 \family typewriter 
19376 a->b[i].c = 10; 
19377 \newline 
19378 a->b[i].d = 11;
19379 \layout Standard
19380
19381 In this case the address arithmetic a->b[i] will be computed only once;
19382  the equivalent code in C would be.
19383 \layout Verse
19384
19385
19386 \family typewriter 
19387 iTemp = a->b[i]; 
19388 \newline 
19389 iTemp.c = 10; 
19390 \newline 
19391 iTemp.d = 11;
19392 \layout Standard
19393
19394 The compiler will try to keep these temporary variables in registers.
19395 \layout Subsection
19396
19397 Dead-Code Elimination
19398 \begin_inset LatexCommand \index{Dead-code elimination}
19399
19400 \end_inset 
19401
19402
19403 \layout Verse
19404
19405
19406 \family typewriter 
19407 int global;
19408 \newline 
19409
19410 \newline 
19411 void f () { 
19412 \newline 
19413 \SpecialChar ~
19414 \SpecialChar ~
19415 int i; 
19416 \newline 
19417 \SpecialChar ~
19418 \SpecialChar ~
19419 i = 1; \SpecialChar ~
19420 \SpecialChar ~
19421 \SpecialChar ~
19422 \SpecialChar ~
19423 \SpecialChar ~
19424 /* dead store */ 
19425 \newline 
19426 \SpecialChar ~
19427 \SpecialChar ~
19428 global = 1;\SpecialChar ~
19429 /* dead store */ 
19430 \newline 
19431 \SpecialChar ~
19432 \SpecialChar ~
19433 global = 2; 
19434 \newline 
19435 \SpecialChar ~
19436 \SpecialChar ~
19437 return; 
19438 \newline 
19439 \SpecialChar ~
19440 \SpecialChar ~
19441 global = 3;\SpecialChar ~
19442 /* unreachable */ 
19443 \newline 
19444 }
19445 \layout Standard
19446
19447 will be changed to
19448 \layout Verse
19449
19450
19451 \family typewriter 
19452 int global;
19453 \newline 
19454
19455 \newline 
19456 void f () {
19457 \newline 
19458 \SpecialChar ~
19459 \SpecialChar ~
19460 global = 2; 
19461 \newline 
19462 \SpecialChar ~
19463 \SpecialChar ~
19464 return; 
19465 \newline 
19466 }
19467 \layout Subsection
19468
19469 Copy-Propagation
19470 \begin_inset LatexCommand \index{Copy propagation}
19471
19472 \end_inset 
19473
19474
19475 \layout Verse
19476
19477
19478 \family typewriter 
19479 int f() { 
19480 \newline 
19481 \SpecialChar ~
19482 \SpecialChar ~
19483 int i, j; 
19484 \newline 
19485 \SpecialChar ~
19486 \SpecialChar ~
19487 i = 10; 
19488 \newline 
19489 \SpecialChar ~
19490 \SpecialChar ~
19491 j = i; 
19492 \newline 
19493 \SpecialChar ~
19494 \SpecialChar ~
19495 return j; 
19496 \newline 
19497 }
19498 \layout Standard
19499
19500 will be changed to 
19501 \layout Verse
19502
19503
19504 \family typewriter 
19505 int f() { 
19506 \newline 
19507 \SpecialChar ~
19508 \SpecialChar ~
19509 int i, j; 
19510 \newline 
19511 \SpecialChar ~
19512 \SpecialChar ~
19513 i = 10; 
19514 \newline 
19515 \SpecialChar ~
19516 \SpecialChar ~
19517 j = 10; 
19518 \newline 
19519 \SpecialChar ~
19520 \SpecialChar ~
19521 return 10; 
19522 \newline 
19523 }
19524 \layout Standard
19525
19526 Note: the dead stores created by this copy propagation will be eliminated
19527  by dead-code elimination.
19528 \layout Subsection
19529
19530 Loop Optimizations
19531 \begin_inset LatexCommand \index{Loop optimization}
19532
19533 \end_inset 
19534
19535
19536 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
19537
19538 \end_inset 
19539
19540
19541 \layout Standard
19542
19543 Two types of loop optimizations are done by SDCC 
19544 \emph on 
19545 loop invariant
19546 \emph default 
19547  lifting and
19548 \emph on 
19549  strength reduction
19550 \emph default 
19551  of loop induction variables.
19552  In addition to the strength reduction the optimizer marks the induction
19553  variables and the register allocator tries to keep the induction variables
19554  in registers for the duration of the loop.
19555  Because of this preference of the register allocator
19556 \begin_inset LatexCommand \index{Register allocation}
19557
19558 \end_inset 
19559
19560 , loop induction optimization causes an increase in register pressure, which
19561  may cause unwanted spilling of other temporary variables into the stack
19562 \begin_inset LatexCommand \index{stack}
19563
19564 \end_inset 
19565
19566  / data space.
19567  The compiler will generate a warning message when it is forced to allocate
19568  extra space either on the stack or data space.
19569  If this extra space allocation is undesirable then induction optimization
19570  can be eliminated either for the entire source file (with -
19571 \begin_inset ERT
19572 status Collapsed
19573
19574 \layout Standard
19575
19576 \backslash 
19577 /
19578 \end_inset 
19579
19580 -noinduction option) or for a given function only using #pragma\SpecialChar ~
19581 noinduction
19582 \begin_inset LatexCommand \index{\#pragma noinduction}
19583
19584 \end_inset 
19585
19586 .
19587 \newline 
19588
19589 \newline 
19590 Loop Invariant:
19591 \layout Verse
19592
19593
19594 \family typewriter 
19595 for (i = 0 ; i < 100 ; i ++) 
19596 \newline 
19597 \SpecialChar ~
19598 \SpecialChar ~
19599 \SpecialChar ~
19600 \SpecialChar ~
19601 f += k + l;
19602 \layout Standard
19603
19604 changed to
19605 \layout Verse
19606
19607
19608 \family typewriter 
19609 itemp = k + l; 
19610 \newline 
19611 for (i = 0; i < 100; i++) 
19612 \newline 
19613 \SpecialChar ~
19614 \SpecialChar ~
19615 \SpecialChar ~
19616 \SpecialChar ~
19617 f += itemp;
19618 \layout Standard
19619
19620 As mentioned previously some loop invariants are not as apparent, all static
19621  address computations are also moved out of the loop.
19622 \newline 
19623
19624 \newline 
19625 Strength Reduction
19626 \begin_inset LatexCommand \index{Strength reduction}
19627
19628 \end_inset 
19629
19630 , this optimization substitutes an expression by a cheaper expression:
19631 \layout Verse
19632
19633
19634 \family typewriter 
19635 for (i=0;i < 100; i++)
19636 \newline 
19637 \SpecialChar ~
19638 \SpecialChar ~
19639 \SpecialChar ~
19640 \SpecialChar ~
19641 ar[i*5] = i*3;
19642 \layout Standard
19643
19644 changed to
19645 \layout Verse
19646
19647
19648 \family typewriter 
19649 itemp1 = 0; 
19650 \newline 
19651 itemp2 = 0; 
19652 \newline 
19653 for (i=0;i< 100;i++) { 
19654 \newline 
19655 \SpecialChar ~
19656 \SpecialChar ~
19657 \SpecialChar ~
19658 \SpecialChar ~
19659 ar[itemp1] = itemp2; 
19660 \newline 
19661 \SpecialChar ~
19662 \SpecialChar ~
19663 \SpecialChar ~
19664 \SpecialChar ~
19665 itemp1 += 5; 
19666 \newline 
19667 \SpecialChar ~
19668 \SpecialChar ~
19669 \SpecialChar ~
19670 \SpecialChar ~
19671 itemp2 += 3; 
19672 \newline 
19673 }
19674 \layout Standard
19675
19676 The more expensive multiplication
19677 \begin_inset LatexCommand \index{Multiplication}
19678
19679 \end_inset 
19680
19681  is changed to a less expensive addition.
19682 \layout Subsection
19683
19684 Loop Reversing
19685 \begin_inset LatexCommand \index{Loop reversing}
19686
19687 \end_inset 
19688
19689
19690 \layout Standard
19691
19692 This optimization is done to reduce the overhead of checking loop boundaries
19693  for every iteration.
19694  Some simple loops can be reversed and implemented using a 
19695 \begin_inset Quotes eld
19696 \end_inset 
19697
19698 decrement and jump if not zero
19699 \begin_inset Quotes erd
19700 \end_inset 
19701
19702  instruction.
19703  SDCC checks for the following criterion to determine if a loop is reversible
19704  (note: more sophisticated compilers use data-dependency analysis to make
19705  this determination, SDCC uses a more simple minded analysis).
19706 \layout Itemize
19707
19708 The 'for' loop is of the form 
19709 \newline 
19710
19711 \newline 
19712
19713 \family typewriter 
19714 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
19715  += 1])
19716 \newline 
19717 \SpecialChar ~
19718 \SpecialChar ~
19719 \SpecialChar ~
19720 \SpecialChar ~
19721 <for body>
19722 \layout Itemize
19723
19724 The <for body> does not contain 
19725 \begin_inset Quotes eld
19726 \end_inset 
19727
19728 continue
19729 \begin_inset Quotes erd
19730 \end_inset 
19731
19732  or 'break
19733 \begin_inset Quotes erd
19734 \end_inset 
19735
19736 .
19737 \layout Itemize
19738
19739 All goto's are contained within the loop.
19740 \layout Itemize
19741
19742 No function calls within the loop.
19743 \layout Itemize
19744
19745 The loop control variable <sym> is not assigned any value within the loop
19746 \layout Itemize
19747
19748 The loop control variable does NOT participate in any arithmetic operation
19749  within the loop.
19750 \layout Itemize
19751
19752 There are NO switch statements in the loop.
19753 \layout Subsection
19754
19755 Algebraic Simplifications
19756 \layout Standard
19757
19758 SDCC does numerous algebraic simplifications, the following is a small sub-set
19759  of these optimizations.
19760 \layout Verse
19761
19762
19763 \family typewriter 
19764 i = j + 0;\SpecialChar ~
19765 \SpecialChar ~
19766 \SpecialChar ~
19767 \SpecialChar ~
19768  /* changed to: */\SpecialChar ~
19769 \SpecialChar ~
19770 \SpecialChar ~
19771 \SpecialChar ~
19772  i = j; 
19773 \newline 
19774 i /= 2;\SpecialChar ~
19775 \SpecialChar ~
19776 \SpecialChar ~
19777 \SpecialChar ~
19778 \SpecialChar ~
19779 \SpecialChar ~
19780 \SpecialChar ~
19781  /* changed to: */\SpecialChar ~
19782 \SpecialChar ~
19783 \SpecialChar ~
19784 \SpecialChar ~
19785  i >>= 1; 
19786 \newline 
19787 i = j - j;\SpecialChar ~
19788 \SpecialChar ~
19789 \SpecialChar ~
19790 \SpecialChar ~
19791  /* changed to: */\SpecialChar ~
19792 \SpecialChar ~
19793 \SpecialChar ~
19794 \SpecialChar ~
19795  i = 0; 
19796 \newline 
19797 i = j / 1;\SpecialChar ~
19798 \SpecialChar ~
19799 \SpecialChar ~
19800 \SpecialChar ~
19801  /* changed to: */\SpecialChar ~
19802 \SpecialChar ~
19803 \SpecialChar ~
19804 \SpecialChar ~
19805  i = j;
19806 \layout Standard
19807
19808 Note the subexpressions
19809 \begin_inset LatexCommand \index{Subexpression}
19810
19811 \end_inset 
19812
19813  given above are generally introduced by macro expansions or as a result
19814  of copy/constant propagation.
19815 \layout Subsection
19816
19817 'switch' Statements
19818 \begin_inset LatexCommand \label{sub:'switch'-Statements}
19819
19820 \end_inset 
19821
19822
19823 \begin_inset LatexCommand \index{switch statement}
19824
19825 \end_inset 
19826
19827
19828 \layout Standard
19829
19830 SDCC changes switch statements to jump tables
19831 \begin_inset LatexCommand \index{jump tables}
19832
19833 \end_inset 
19834
19835  when the following conditions are true.
19836  
19837 \layout Itemize
19838
19839 The case labels are in numerical sequence, the labels need not be in order,
19840  and the starting number need not be one or zero.
19841 \begin_deeper 
19842 \layout Verse
19843
19844
19845 \family typewriter 
19846 switch(i) {\SpecialChar ~
19847 \SpecialChar ~
19848 \SpecialChar ~
19849 \SpecialChar ~
19850 \SpecialChar ~
19851 \SpecialChar ~
19852 \SpecialChar ~
19853 \SpecialChar ~
19854 \SpecialChar ~
19855 \SpecialChar ~
19856 \SpecialChar ~
19857 \SpecialChar ~
19858 \SpecialChar ~
19859 \SpecialChar ~
19860 \SpecialChar ~
19861 \SpecialChar ~
19862 \SpecialChar ~
19863 \SpecialChar ~
19864 \SpecialChar ~
19865 \SpecialChar ~
19866 \SpecialChar ~
19867 \SpecialChar ~
19868 \SpecialChar ~
19869 \SpecialChar ~
19870 \SpecialChar ~
19871 \SpecialChar ~
19872 switch (i) { 
19873 \newline 
19874 \SpecialChar ~
19875 \SpecialChar ~
19876 \SpecialChar ~
19877 case 4: ...\SpecialChar ~
19878 \SpecialChar ~
19879 \SpecialChar ~
19880 \SpecialChar ~
19881 \SpecialChar ~
19882 \SpecialChar ~
19883 \SpecialChar ~
19884 \SpecialChar ~
19885 \SpecialChar ~
19886 \SpecialChar ~
19887 \SpecialChar ~
19888 \SpecialChar ~
19889 \SpecialChar ~
19890 \SpecialChar ~
19891 \SpecialChar ~
19892 \SpecialChar ~
19893 \SpecialChar ~
19894 \SpecialChar ~
19895 \SpecialChar ~
19896 \SpecialChar ~
19897 \SpecialChar ~
19898 \SpecialChar ~
19899 \SpecialChar ~
19900 \SpecialChar ~
19901 \SpecialChar ~
19902 \SpecialChar ~
19903 case 0: ...
19904  
19905 \newline 
19906 \SpecialChar ~
19907 \SpecialChar ~
19908 \SpecialChar ~
19909 case 5: ...\SpecialChar ~
19910 \SpecialChar ~
19911 \SpecialChar ~
19912 \SpecialChar ~
19913 \SpecialChar ~
19914 \SpecialChar ~
19915 \SpecialChar ~
19916 \SpecialChar ~
19917 \SpecialChar ~
19918 \SpecialChar ~
19919 \SpecialChar ~
19920 \SpecialChar ~
19921 \SpecialChar ~
19922 \SpecialChar ~
19923 \SpecialChar ~
19924 \SpecialChar ~
19925 \SpecialChar ~
19926 \SpecialChar ~
19927 \SpecialChar ~
19928 \SpecialChar ~
19929 \SpecialChar ~
19930 \SpecialChar ~
19931 \SpecialChar ~
19932 \SpecialChar ~
19933 \SpecialChar ~
19934 \SpecialChar ~
19935 case 1: ...
19936  
19937 \newline 
19938 \SpecialChar ~
19939 \SpecialChar ~
19940 \SpecialChar ~
19941 case 3: ...\SpecialChar ~
19942 \SpecialChar ~
19943 \SpecialChar ~
19944 \SpecialChar ~
19945 \SpecialChar ~
19946 \SpecialChar ~
19947 \SpecialChar ~
19948 \SpecialChar ~
19949 \SpecialChar ~
19950 \SpecialChar ~
19951 \SpecialChar ~
19952 \SpecialChar ~
19953 \SpecialChar ~
19954 \SpecialChar ~
19955 \SpecialChar ~
19956 \SpecialChar ~
19957 \SpecialChar ~
19958 \SpecialChar ~
19959 \SpecialChar ~
19960 \SpecialChar ~
19961 \SpecialChar ~
19962 \SpecialChar ~
19963 \SpecialChar ~
19964 \SpecialChar ~
19965 \SpecialChar ~
19966 \SpecialChar ~
19967 case 2: ...
19968  
19969 \newline 
19970 \SpecialChar ~
19971 \SpecialChar ~
19972 \SpecialChar ~
19973 case 6: ...\SpecialChar ~
19974 \SpecialChar ~
19975 \SpecialChar ~
19976 \SpecialChar ~
19977 \SpecialChar ~
19978 \SpecialChar ~
19979 \SpecialChar ~
19980 \SpecialChar ~
19981 \SpecialChar ~
19982 \SpecialChar ~
19983 \SpecialChar ~
19984 \SpecialChar ~
19985 \SpecialChar ~
19986 \SpecialChar ~
19987 \SpecialChar ~
19988 \SpecialChar ~
19989 \SpecialChar ~
19990 \SpecialChar ~
19991 \SpecialChar ~
19992 \SpecialChar ~
19993 \SpecialChar ~
19994 \SpecialChar ~
19995 \SpecialChar ~
19996 \SpecialChar ~
19997 \SpecialChar ~
19998 \SpecialChar ~
19999 case 3: ...
20000  
20001 \newline 
20002 }\SpecialChar ~
20003 \SpecialChar ~
20004 \SpecialChar ~
20005 \SpecialChar ~
20006 \SpecialChar ~
20007 \SpecialChar ~
20008 \SpecialChar ~
20009 \SpecialChar ~
20010 \SpecialChar ~
20011 \SpecialChar ~
20012 \SpecialChar ~
20013 \SpecialChar ~
20014 \SpecialChar ~
20015 \SpecialChar ~
20016 \SpecialChar ~
20017 \SpecialChar ~
20018 \SpecialChar ~
20019 \SpecialChar ~
20020 \SpecialChar ~
20021 \SpecialChar ~
20022 \SpecialChar ~
20023 \SpecialChar ~
20024 \SpecialChar ~
20025 \SpecialChar ~
20026 \SpecialChar ~
20027 \SpecialChar ~
20028 \SpecialChar ~
20029 \SpecialChar ~
20030 \SpecialChar ~
20031 \SpecialChar ~
20032 \SpecialChar ~
20033 \SpecialChar ~
20034 \SpecialChar ~
20035 \SpecialChar ~
20036 \SpecialChar ~
20037 \SpecialChar ~
20038 }
20039 \layout Standard
20040
20041 Both the above switch statements will be implemented using a jump-table.
20042  The example to the right side is slightly more efficient as the check for
20043  the lower boundary of the jump-table is not needed.
20044 \end_deeper 
20045 \layout Itemize
20046
20047 The number of case labels is at least three, since it takes two conditional
20048  statements to handle the boundary conditions.
20049 \layout Itemize
20050
20051 The number of case labels is less than 84, since each label takes 3 bytes
20052  and a jump-table can be utmost 256 bytes long.
20053 \layout Standard
20054
20055 Switch statements which have gaps in the numeric sequence or those that
20056  have more that 84 case labels can be split into more than one switch statement
20057  for efficient code generation, e.g.:
20058 \layout Verse
20059
20060
20061 \family typewriter 
20062 switch (i) { 
20063 \newline 
20064 \SpecialChar ~
20065 \SpecialChar ~
20066 case 1: ...
20067  
20068 \newline 
20069 \SpecialChar ~
20070 \SpecialChar ~
20071 case 2: ...
20072  
20073 \newline 
20074 \SpecialChar ~
20075 \SpecialChar ~
20076 case 3: ...
20077  
20078 \newline 
20079 \SpecialChar ~
20080 \SpecialChar ~
20081 case 4: ...
20082  
20083 \newline 
20084 \SpecialChar ~
20085 \SpecialChar ~
20086 case 9: ...
20087  
20088 \newline 
20089 \SpecialChar ~
20090 \SpecialChar ~
20091 case 10: ...
20092  
20093 \newline 
20094 \SpecialChar ~
20095 \SpecialChar ~
20096 case 11: ...
20097  
20098 \newline 
20099 \SpecialChar ~
20100 \SpecialChar ~
20101 case 12: ...
20102  
20103 \newline 
20104 }
20105 \layout Standard
20106
20107 If the above switch statement is broken down into two switch statements
20108 \layout Verse
20109
20110
20111 \family typewriter 
20112 switch (i) { 
20113 \newline 
20114 \SpecialChar ~
20115 \SpecialChar ~
20116 case 1: ...
20117  
20118 \newline 
20119 \SpecialChar ~
20120 \SpecialChar ~
20121 case 2: ...
20122  
20123 \newline 
20124 \SpecialChar ~
20125 \SpecialChar ~
20126 case 3: ...
20127  
20128 \newline 
20129 \SpecialChar ~
20130 \SpecialChar ~
20131 case 4: ...
20132  
20133 \newline 
20134 }
20135 \layout Standard
20136
20137 and
20138 \layout Verse
20139
20140
20141 \family typewriter 
20142 switch (i) { 
20143 \newline 
20144 \SpecialChar ~
20145 \SpecialChar ~
20146 case 9:\SpecialChar ~
20147 \SpecialChar ~
20148 ...
20149  
20150 \newline 
20151 \SpecialChar ~
20152 \SpecialChar ~
20153 case 10:\SpecialChar ~
20154 ...
20155  
20156 \newline 
20157 \SpecialChar ~
20158 \SpecialChar ~
20159 case 11:\SpecialChar ~
20160 ...
20161  
20162 \newline 
20163 \SpecialChar ~
20164 \SpecialChar ~
20165 case 12:\SpecialChar ~
20166 ...
20167  
20168 \newline 
20169 }
20170 \layout Standard
20171
20172 then both the switch statements will be implemented using jump-tables whereas
20173  the unmodified switch statement will not be.
20174  You might also consider inserting dummy cases 0 and 5 to 8 in this example.
20175  
20176 \newline 
20177 The pragma nojtbound
20178 \begin_inset LatexCommand \index{\#pragma nojtbound}
20179
20180 \end_inset 
20181
20182  can be used to turn off checking the 
20183 \emph on 
20184 j
20185 \emph default 
20186 ump 
20187 \emph on 
20188 t
20189 \emph default 
20190 able 
20191 \emph on 
20192 bound
20193 \emph default 
20194 aries.
20195  It has no effect if a default label is supplied.
20196  Use of this pragma is dangerous: if the switch argument is not matched
20197  by a case statement the processor will happily jump into Nirvana.
20198 \layout Subsection
20199
20200 Bit-shifting Operations
20201 \begin_inset LatexCommand \index{Bit shifting}
20202
20203 \end_inset 
20204
20205 .
20206 \layout Standard
20207
20208 Bit shifting is one of the most frequently used operation in embedded programmin
20209 g.
20210  SDCC tries to implement bit-shift operations in the most efficient way
20211  possible, e.g.:
20212 \layout Verse
20213
20214
20215 \family typewriter 
20216 unsigned char i;
20217 \newline 
20218 ...
20219  
20220 \newline 
20221 i >>= 4; 
20222 \newline 
20223 ...
20224 \layout Standard
20225
20226 generates the following code:
20227 \layout Verse
20228
20229
20230 \family typewriter 
20231 mov\SpecialChar ~
20232  a,_i 
20233 \newline 
20234 swap a 
20235 \newline 
20236 anl\SpecialChar ~
20237  a,#0x0f 
20238 \newline 
20239 mov\SpecialChar ~
20240  _i,a
20241 \layout Standard
20242
20243 In general SDCC will never setup a loop if the shift count is known.
20244  Another example:
20245 \layout Verse
20246
20247
20248 \family typewriter 
20249 unsigned int i; 
20250 \newline 
20251 ...
20252  
20253 \newline 
20254 i >>= 9; 
20255 \newline 
20256 ...
20257 \layout Standard
20258
20259 will generate:
20260 \layout Verse
20261
20262
20263 \family typewriter 
20264 mov\SpecialChar ~
20265 \SpecialChar ~
20266 a,(_i + 1) 
20267 \newline 
20268 mov\SpecialChar ~
20269 \SpecialChar ~
20270 (_i + 1),#0x00 
20271 \newline 
20272 clr\SpecialChar ~
20273 \SpecialChar ~
20274
20275 \newline 
20276 rrc\SpecialChar ~
20277 \SpecialChar ~
20278
20279 \newline 
20280 mov\SpecialChar ~
20281 \SpecialChar ~
20282 _i,a
20283 \layout Subsection
20284
20285 Bit-rotation
20286 \begin_inset LatexCommand \index{Bit rotation}
20287
20288 \end_inset 
20289
20290
20291 \layout Standard
20292
20293 A special case of the bit-shift operation is bit rotation
20294 \begin_inset LatexCommand \index{rotating bits}
20295
20296 \end_inset 
20297
20298 , SDCC recognizes the following expression to be a left bit-rotation:
20299 \layout Verse
20300
20301
20302 \family typewriter 
20303 \series bold 
20304 unsigned
20305 \series default 
20306 \SpecialChar ~
20307 \SpecialChar ~
20308 char i;\SpecialChar ~
20309 \SpecialChar ~
20310 \SpecialChar ~
20311 \SpecialChar ~
20312 \SpecialChar ~
20313 \SpecialChar ~
20314 \SpecialChar ~
20315 \SpecialChar ~
20316 \SpecialChar ~
20317 \SpecialChar ~
20318 \SpecialChar ~
20319 /* unsigned is needed for rotation */ 
20320 \newline 
20321 ...
20322  
20323 \newline 
20324 i = ((i << 1) | (i >> 7)); 
20325 \family default 
20326
20327 \newline 
20328
20329 \family typewriter 
20330 ...
20331 \layout Standard
20332
20333 will generate the following code:
20334 \layout Verse
20335
20336
20337 \family typewriter 
20338 mov\SpecialChar ~
20339 \SpecialChar ~
20340 a,_i 
20341 \newline 
20342 rl\SpecialChar ~
20343 \SpecialChar ~
20344 \SpecialChar ~
20345
20346 \newline 
20347 mov\SpecialChar ~
20348 \SpecialChar ~
20349 _i,a
20350 \layout Standard
20351
20352 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
20353 ns of this case will also be recognized as bit-rotation, i.e.: 
20354 \layout Verse
20355
20356
20357 \family typewriter 
20358 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
20359 \layout Subsection
20360
20361 Nibble and Byte Swapping
20362 \layout Standard
20363
20364 Other special cases of the bit-shift operations are nibble or byte swapping
20365 \begin_inset LatexCommand \index{swapping nibbles/bytes}
20366
20367 \end_inset 
20368
20369 , SDCC recognizes the following expressions:
20370 \layout Verse
20371
20372
20373 \family typewriter 
20374 \series bold 
20375 unsigned
20376 \series default 
20377 \SpecialChar ~
20378 \SpecialChar ~
20379 char i; 
20380 \newline 
20381
20382 \series bold 
20383 unsigned
20384 \series default 
20385 \SpecialChar ~
20386 \SpecialChar ~
20387 int j; 
20388 \newline 
20389 ...
20390  
20391 \newline 
20392 i = ((i << 4) | (i >> 4)); 
20393 \family default 
20394
20395 \newline 
20396
20397 \family typewriter 
20398 j = ((j << 8) | (j >> 8)); 
20399 \layout Standard
20400
20401 and generates a swap instruction for the nibble swapping
20402 \begin_inset LatexCommand \index{Nibble swapping}
20403
20404 \end_inset 
20405
20406  or move instructions for the byte swapping
20407 \begin_inset LatexCommand \index{Byte swapping}
20408
20409 \end_inset 
20410
20411 .
20412  The 
20413 \begin_inset Quotes sld
20414 \end_inset 
20415
20416 j
20417 \begin_inset Quotes srd
20418 \end_inset 
20419
20420  example can be used to convert from little to big-endian or vice versa.
20421  If you want to change the endianness of a 
20422 \emph on 
20423 signed
20424 \emph default 
20425  integer you have to cast to 
20426 \family typewriter 
20427 (unsigned int)
20428 \family default 
20429  first.
20430 \layout Standard
20431
20432 Note that SDCC stores numbers in little-endian
20433 \begin_inset Foot
20434 collapsed false
20435
20436 \layout Standard
20437
20438 Usually 8-bit processors don't care much about endianness.
20439  This is not the case for the standard 8051 which only has an instruction
20440  to increment its 
20441 \emph on 
20442 dptr
20443 \emph default 
20444
20445 \begin_inset LatexCommand \index{DPTR}
20446
20447 \end_inset 
20448
20449 -datapointer
20450 \emph on 
20451  
20452 \emph default 
20453 so little-endian is the more efficient byte order.
20454 \end_inset 
20455
20456
20457 \begin_inset LatexCommand \index{little-endian}
20458
20459 \end_inset 
20460
20461
20462 \begin_inset LatexCommand \index{Endianness}
20463
20464 \end_inset 
20465
20466  format (i.e.
20467  lowest order first).
20468 \layout Subsection
20469
20470 Highest Order Bit
20471 \begin_inset LatexCommand \index{Highest Order Bit}
20472
20473 \end_inset 
20474
20475
20476 \layout Standard
20477
20478 It is frequently required to obtain the highest order bit of an integral
20479  type (long, int, short or char types).
20480  SDCC recognizes the following expression to yield the highest order bit
20481  and generates optimized code for it, e.g.:
20482 \layout Verse
20483
20484
20485 \family typewriter 
20486 unsigned int gint; 
20487 \newline 
20488
20489 \newline 
20490 foo () { 
20491 \newline 
20492 \SpecialChar ~
20493 \SpecialChar ~
20494 unsigned char hob; 
20495 \newline 
20496 \SpecialChar ~
20497 \SpecialChar ~
20498 ...
20499  
20500 \newline 
20501 \SpecialChar ~
20502 \SpecialChar ~
20503 hob = (gint >> 15) & 1; 
20504 \newline 
20505 \SpecialChar ~
20506 \SpecialChar ~
20507 ..
20508  
20509 \newline 
20510 }
20511 \layout Standard
20512
20513 will generate the following code:
20514 \layout Verse
20515
20516
20517 \family typewriter 
20518 \SpecialChar ~
20519 \SpecialChar ~
20520 \SpecialChar ~
20521 \SpecialChar ~
20522 \SpecialChar ~
20523 \SpecialChar ~
20524 \SpecialChar ~
20525 \SpecialChar ~
20526 \SpecialChar ~
20527 \SpecialChar ~
20528 \SpecialChar ~
20529 \SpecialChar ~
20530 \SpecialChar ~
20531 \SpecialChar ~
20532 \SpecialChar ~
20533 \SpecialChar ~
20534 \SpecialChar ~
20535 \SpecialChar ~
20536 \SpecialChar ~
20537 \SpecialChar ~
20538 \SpecialChar ~
20539 \SpecialChar ~
20540 \SpecialChar ~
20541 \SpecialChar ~
20542 \SpecialChar ~
20543  61 ;\SpecialChar ~
20544  hob.c 7 
20545 \newline 
20546 000A E5*01\SpecialChar ~
20547 \SpecialChar ~
20548 \SpecialChar ~
20549 \SpecialChar ~
20550 \SpecialChar ~
20551 \SpecialChar ~
20552 \SpecialChar ~
20553 \SpecialChar ~
20554 \SpecialChar ~
20555 \SpecialChar ~
20556 \SpecialChar ~
20557 \SpecialChar ~
20558 \SpecialChar ~
20559 \SpecialChar ~
20560 \SpecialChar ~
20561  62\SpecialChar ~
20562 \SpecialChar ~
20563 \SpecialChar ~
20564 \SpecialChar ~
20565 \SpecialChar ~
20566 \SpecialChar ~
20567 \SpecialChar ~
20568 \SpecialChar ~
20569  mov\SpecialChar ~
20570 \SpecialChar ~
20571  a,(_gint + 1) 
20572 \newline 
20573 000C 23\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  63\SpecialChar ~
20592 \SpecialChar ~
20593 \SpecialChar ~
20594 \SpecialChar ~
20595 \SpecialChar ~
20596 \SpecialChar ~
20597 \SpecialChar ~
20598 \SpecialChar ~
20599  rl\SpecialChar ~
20600 \SpecialChar ~
20601 \SpecialChar ~
20602  a 
20603 \newline 
20604 000D 54 01\SpecialChar ~
20605 \SpecialChar ~
20606 \SpecialChar ~
20607 \SpecialChar ~
20608 \SpecialChar ~
20609 \SpecialChar ~
20610 \SpecialChar ~
20611 \SpecialChar ~
20612 \SpecialChar ~
20613 \SpecialChar ~
20614 \SpecialChar ~
20615 \SpecialChar ~
20616 \SpecialChar ~
20617 \SpecialChar ~
20618 \SpecialChar ~
20619  64\SpecialChar ~
20620 \SpecialChar ~
20621 \SpecialChar ~
20622 \SpecialChar ~
20623 \SpecialChar ~
20624 \SpecialChar ~
20625 \SpecialChar ~
20626 \SpecialChar ~
20627  anl\SpecialChar ~
20628 \SpecialChar ~
20629  a,#0x01 
20630 \newline 
20631 000F F5*02\SpecialChar ~
20632 \SpecialChar ~
20633 \SpecialChar ~
20634 \SpecialChar ~
20635 \SpecialChar ~
20636 \SpecialChar ~
20637 \SpecialChar ~
20638 \SpecialChar ~
20639 \SpecialChar ~
20640 \SpecialChar ~
20641 \SpecialChar ~
20642 \SpecialChar ~
20643 \SpecialChar ~
20644 \SpecialChar ~
20645 \SpecialChar ~
20646  65\SpecialChar ~
20647 \SpecialChar ~
20648 \SpecialChar ~
20649 \SpecialChar ~
20650 \SpecialChar ~
20651 \SpecialChar ~
20652 \SpecialChar ~
20653 \SpecialChar ~
20654  mov\SpecialChar ~
20655 \SpecialChar ~
20656  _foo_hob_1_1,a
20657 \layout Standard
20658
20659 Variations of this case however will 
20660 \emph on 
20661 not
20662 \emph default 
20663  be recognized.
20664  It is a standard C expression, so I heartily recommend this be the only
20665  way to get the highest order bit, (it is portable).
20666  Of course it will be recognized even if it is embedded in other expressions,
20667  e.g.:
20668 \layout Verse
20669
20670
20671 \family typewriter 
20672 xyz = gint + ((gint >> 15) & 1);
20673 \layout Standard
20674
20675 will still be recognized.
20676 \layout Subsection
20677
20678 Peephole Optimizer
20679 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
20680
20681 \end_inset 
20682
20683
20684 \begin_inset LatexCommand \index{Peephole optimizer}
20685
20686 \end_inset 
20687
20688
20689 \layout Standard
20690
20691 The compiler uses a rule based, pattern matching and re-writing mechanism
20692  for peep-hole optimization.
20693  It is inspired by 
20694 \emph on 
20695 copt
20696 \emph default 
20697  a peep-hole optimizer by Christopher W.
20698  Fraser (cwfraser@microsoft.com).
20699  A default set of rules are compiled into the compiler, additional rules
20700  may be added with the 
20701 \emph on 
20702 -
20703 \begin_inset ERT
20704 status Collapsed
20705
20706 \layout Standard
20707
20708 \backslash 
20709 /
20710 \end_inset 
20711
20712 -peep-file
20713 \begin_inset LatexCommand \index{-\/-peep-file}
20714
20715 \end_inset 
20716
20717  <filename>
20718 \emph default 
20719  option.
20720  The rule language is best illustrated with examples.
20721 \layout Verse
20722
20723
20724 \family typewriter 
20725 replace { 
20726 \newline 
20727 \SpecialChar ~
20728 \SpecialChar ~
20729 mov %1,a 
20730 \newline 
20731 \SpecialChar ~
20732 \SpecialChar ~
20733 mov a,%1
20734 \newline 
20735 } by {
20736 \newline 
20737 \SpecialChar ~
20738 \SpecialChar ~
20739 mov %1,a
20740 \newline 
20741 }
20742 \layout Standard
20743
20744 The above rule will change the following assembly
20745 \begin_inset LatexCommand \index{Assembler routines}
20746
20747 \end_inset 
20748
20749  sequence:
20750 \layout Verse
20751
20752
20753 \family typewriter 
20754 mov r1,a 
20755 \newline 
20756 mov a,r1
20757 \layout Standard
20758
20759 to
20760 \layout Verse
20761
20762
20763 \family typewriter 
20764 mov r1,a
20765 \layout Standard
20766
20767 Note: All occurrences of a 
20768 \emph on 
20769 %n
20770 \emph default 
20771  (pattern variable) must denote the same string.
20772  With the above rule, the assembly sequence:
20773 \layout Verse
20774
20775
20776 \family typewriter 
20777 mov r1,a 
20778 \newline 
20779 mov a,r2
20780 \layout Standard
20781
20782 will remain unmodified.
20783 \newline 
20784
20785 \newline 
20786 Other special case optimizations may be added by the user (via 
20787 \emph on 
20788 -
20789 \begin_inset ERT
20790 status Collapsed
20791
20792 \layout Standard
20793
20794 \backslash 
20795 /
20796 \end_inset 
20797
20798 -peep-file option
20799 \emph default 
20800 ).
20801  E.g.
20802  some variants of the 8051 MCU
20803 \begin_inset LatexCommand \index{MCS51 variants}
20804
20805 \end_inset 
20806
20807  allow only 
20808 \family typewriter 
20809 ajmp
20810 \family default 
20811  and 
20812 \family typewriter 
20813 acall
20814 \family default 
20815 .
20816  The following two rules will change all 
20817 \family typewriter 
20818 ljmp
20819 \family default 
20820  and 
20821 \family typewriter 
20822 lcall
20823 \family default 
20824  to 
20825 \family typewriter 
20826 ajmp
20827 \family default 
20828  and 
20829 \family typewriter 
20830 acall
20831 \layout Verse
20832
20833
20834 \family typewriter 
20835 replace { lcall %1 } by { acall %1 } 
20836 \newline 
20837 replace { ljmp %1 } by { ajmp %1 }
20838 \layout Standard
20839
20840 The 
20841 \emph on 
20842 inline-assembler code
20843 \emph default 
20844  is also passed through the peep hole optimizer, thus the peephole optimizer
20845  can also be used as an assembly level macro expander.
20846  The rules themselves are MCU dependent whereas the rule language infra-structur
20847 e is MCU independent.
20848  Peephole optimization rules for other MCU can be easily programmed using
20849  the rule language.
20850 \newline 
20851
20852 \newline 
20853 The syntax for a rule is as follows:
20854 \layout Verse
20855
20856
20857 \family typewriter 
20858 rule := replace [ restart ] '{' <assembly sequence> '
20859 \backslash 
20860 n' 
20861 \newline 
20862 \SpecialChar ~
20863  \SpecialChar ~
20864  \SpecialChar ~
20865  \SpecialChar ~
20866  \SpecialChar ~
20867  \SpecialChar ~
20868  \SpecialChar ~
20869  \SpecialChar ~
20870  \SpecialChar ~
20871  \SpecialChar ~
20872  \SpecialChar ~
20873  \SpecialChar ~
20874  \SpecialChar ~
20875  \SpecialChar ~
20876  '}' by '{' '
20877 \backslash 
20878 n' 
20879 \newline 
20880 \SpecialChar ~
20881  \SpecialChar ~
20882  \SpecialChar ~
20883  \SpecialChar ~
20884  \SpecialChar ~
20885  \SpecialChar ~
20886  \SpecialChar ~
20887  \SpecialChar ~
20888  \SpecialChar ~
20889  \SpecialChar ~
20890  \SpecialChar ~
20891  \SpecialChar ~
20892  \SpecialChar ~
20893  \SpecialChar ~
20894  \SpecialChar ~
20895  \SpecialChar ~
20896  <assembly sequence> '
20897 \backslash 
20898 n' 
20899 \newline 
20900 \SpecialChar ~
20901  \SpecialChar ~
20902  \SpecialChar ~
20903  \SpecialChar ~
20904  \SpecialChar ~
20905  \SpecialChar ~
20906  \SpecialChar ~
20907  \SpecialChar ~
20908  \SpecialChar ~
20909  \SpecialChar ~
20910  \SpecialChar ~
20911  \SpecialChar ~
20912  \SpecialChar ~
20913  \SpecialChar ~
20914  '}' [if <functionName> ] '
20915 \backslash 
20916 n' 
20917 \layout Standard
20918
20919 <assembly sequence> := assembly instruction (each instruction including
20920  labels must be on a separate line).
20921 \newline 
20922
20923 \newline 
20924 The optimizer will apply to the rules one by one from the top in the sequence
20925  of their appearance, it will terminate when all rules are exhausted.
20926  If the 'restart' option is specified, then the optimizer will start matching
20927  the rules again from the top, this option for a rule is expensive (performance)
20928 , it is intended to be used in situations where a transformation will trigger
20929  the same rule again.
20930  An example of this (not a good one, it has side effects) is the following
20931  rule:
20932 \layout Verse
20933
20934
20935 \family typewriter 
20936 replace restart { 
20937 \newline 
20938 \SpecialChar ~
20939 \SpecialChar ~
20940 pop %1 
20941 \newline 
20942 \SpecialChar ~
20943 \SpecialChar ~
20944 push %1 } by { 
20945 \newline 
20946 \SpecialChar ~
20947 \SpecialChar ~
20948 ; nop 
20949 \newline 
20950 }
20951 \layout Standard
20952
20953 Note that the replace pattern cannot be a blank, but can be a comment line.
20954  Without the 'restart' option only the innermost 'pop' 'push' pair would
20955  be eliminated, i.e.:
20956 \layout Verse
20957
20958
20959 \family typewriter 
20960 pop ar1 
20961 \newline 
20962 pop ar2 
20963 \newline 
20964 push ar2 
20965 \newline 
20966 push ar1
20967 \layout Standard
20968
20969 would result in:
20970 \layout Verse
20971
20972
20973 \family typewriter 
20974 pop ar1 
20975 \newline 
20976 ; nop 
20977 \newline 
20978 push ar1
20979 \layout Standard
20980
20981
20982 \emph on 
20983 with
20984 \emph default 
20985  the restart option the rule will be applied again to the resulting code
20986  and then all the pop-push pairs will be eliminated to yield:
20987 \layout Verse
20988
20989
20990 \family typewriter 
20991 ; nop 
20992 \newline 
20993 ; nop
20994 \layout Standard
20995
20996 A conditional function can be attached to a rule.
20997  Attaching rules are somewhat more involved, let me illustrate this with
20998  an example.
20999 \layout Verse
21000
21001
21002 \family typewriter 
21003 replace { 
21004 \newline 
21005 \SpecialChar ~
21006  \SpecialChar ~
21007  \SpecialChar ~
21008 ljmp %5 
21009 \newline 
21010 %2:
21011 \newline 
21012 } by { 
21013 \newline 
21014 \SpecialChar ~
21015  \SpecialChar ~
21016  \SpecialChar ~
21017 sjmp %5 
21018 \newline 
21019 %2:
21020 \newline 
21021 } if labelInRange
21022 \layout Standard
21023
21024 The optimizer does a look-up of a function name table defined in function
21025  
21026 \emph on 
21027 callFuncByName
21028 \emph default 
21029  in the source file SDCCpeeph.c, with the name 
21030 \emph on 
21031 labelInRange
21032 \emph default 
21033 .
21034  If it finds a corresponding entry the function is called.
21035  Note there can be no parameters specified for these functions, in this
21036  case the use of 
21037 \emph on 
21038 %5
21039 \emph default 
21040  is crucial, since the function 
21041 \emph on 
21042 labelInRange
21043 \emph default 
21044  expects to find the label in that particular variable (the hash table containin
21045 g the variable bindings is passed as a parameter).
21046  If you want to code more such functions, take a close look at the function
21047  labelInRange and the calling mechanism in source file SDCCpeeph.c.
21048  Currently implemented are 
21049 \emph on 
21050 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
21051  24bitMode, portIsDS390, 24bitModeAndPortDS390 
21052 \emph default 
21053 and
21054 \emph on 
21055  notVolatile
21056 \emph default 
21057 .
21058 \layout Standard
21059
21060 I know this whole thing is a little kludgey, but maybe some day we will
21061  have some better means.
21062  If you are looking at this file, you will see the default rules that are
21063  compiled into the compiler, you can add your own rules in the default set
21064  there if you get tired of specifying the -
21065 \begin_inset ERT
21066 status Collapsed
21067
21068 \layout Standard
21069
21070 \backslash 
21071 /
21072 \end_inset 
21073
21074 -peep-file option.
21075 \layout Section
21076
21077 ANSI-Compliance
21078 \begin_inset LatexCommand \index{ANSI-compliance}
21079
21080 \end_inset 
21081
21082
21083 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
21084
21085 \end_inset 
21086
21087
21088 \layout Standard
21089
21090 Deviations from the compliance:
21091 \layout Itemize
21092
21093 functions are not always reentrant
21094 \begin_inset LatexCommand \index{reentrant}
21095
21096 \end_inset 
21097
21098 .
21099 \layout Itemize
21100
21101 structures cannot be assigned values directly, cannot be passed as function
21102  parameters or assigned to each other and cannot be a return value from
21103  a function, e.g.:
21104 \begin_deeper 
21105 \layout Verse
21106
21107
21108 \family typewriter 
21109 struct s { ...
21110  }; 
21111 \newline 
21112 struct s s1, s2; 
21113 \newline 
21114 foo() 
21115 \newline 
21116
21117 \newline 
21118 \SpecialChar ~
21119 \SpecialChar ~
21120 \SpecialChar ~
21121 \SpecialChar ~
21122 ...
21123  
21124 \newline 
21125 \SpecialChar ~
21126 \SpecialChar ~
21127 \SpecialChar ~
21128 \SpecialChar ~
21129 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
21130 \newline 
21131 \SpecialChar ~
21132 \SpecialChar ~
21133 \SpecialChar ~
21134 \SpecialChar ~
21135 ...
21136  
21137 \newline 
21138 }
21139 \newline 
21140 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
21141  */
21142 \newline 
21143
21144 \newline 
21145 \SpecialChar ~
21146 \SpecialChar ~
21147 \SpecialChar ~
21148 \SpecialChar ~
21149 struct s rets; 
21150 \newline 
21151 \SpecialChar ~
21152 \SpecialChar ~
21153 \SpecialChar ~
21154 \SpecialChar ~
21155 ...
21156  
21157 \newline 
21158 \SpecialChar ~
21159 \SpecialChar ~
21160 \SpecialChar ~
21161 \SpecialChar ~
21162 return rets;/* is invalid in SDCC although allowed in ANSI */ 
21163 \newline 
21164 }
21165 \end_deeper 
21166 \layout Itemize
21167
21168 'long long
21169 \begin_inset LatexCommand \index{long long (not supported)}
21170
21171 \end_inset 
21172
21173 ' (64 bit integers
21174 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
21175
21176 \end_inset 
21177
21178 ) not supported.
21179 \layout Itemize
21180
21181 'double
21182 \begin_inset LatexCommand \index{double (not supported)}
21183
21184 \end_inset 
21185
21186 ' precision floating point 
21187 \begin_inset LatexCommand \index{Floating point support}
21188
21189 \end_inset 
21190
21191 not supported.
21192 \layout Itemize
21193
21194 No support for setjmp
21195 \begin_inset LatexCommand \index{setjmp (not supported)}
21196
21197 \end_inset 
21198
21199  and longjmp
21200 \begin_inset LatexCommand \index{longjmp (not supported)}
21201
21202 \end_inset 
21203
21204  (for now).
21205 \layout Itemize
21206
21207 Old K&R style
21208 \begin_inset LatexCommand \index{K\&R style}
21209
21210 \end_inset 
21211
21212  function declarations are NOT allowed.
21213 \begin_deeper 
21214 \layout Verse
21215
21216
21217 \family typewriter 
21218 foo(i,j) /* this old style of function declarations */ 
21219 \newline 
21220 int i,j; /* are valid in ANSI but not valid in SDCC */ 
21221 \newline 
21222
21223 \newline 
21224 \SpecialChar ~
21225 \SpecialChar ~
21226 \SpecialChar ~
21227 \SpecialChar ~
21228 ...
21229  
21230 \newline 
21231 }
21232 \end_deeper 
21233 \layout Section
21234
21235 Cyclomatic Complexity
21236 \begin_inset LatexCommand \index{Cyclomatic complexity}
21237
21238 \end_inset 
21239
21240
21241 \layout Standard
21242
21243 Cyclomatic complexity of a function is defined as the number of independent
21244  paths the program can take during execution of the function.
21245  This is an important number since it defines the number test cases you
21246  have to generate to validate the function.
21247  The accepted industry standard for complexity number is 10, if the cyclomatic
21248  complexity reported by SDCC exceeds 10 you should think about simplification
21249  of the function logic.
21250  Note that the complexity level is not related to the number of lines of
21251  code in a function.
21252  Large functions can have low complexity, and small functions can have large
21253  complexity levels.
21254  
21255 \newline 
21256
21257 \newline 
21258 SDCC uses the following formula to compute the complexity:
21259 \newline 
21260
21261 \layout Standard
21262
21263 complexity = (number of edges in control flow graph) - (number of nodes
21264  in control flow graph) + 2;
21265 \newline 
21266
21267 \newline 
21268 Having said that the industry standard is 10, you should be aware that in
21269  some cases it be may unavoidable to have a complexity level of less than
21270  10.
21271  For example if you have switch statement with more than 10 case labels,
21272  each case label adds one to the complexity level.
21273  The complexity level is by no means an absolute measure of the algorithmic
21274  complexity of the function, it does however provide a good starting point
21275  for which functions you might look at for further optimization.
21276 \layout Section
21277
21278 Retargetting for other Processors
21279 \layout Standard
21280
21281 The issues for retargetting the compiler are far too numerous to be covered
21282  by this document.
21283  What follows is a brief description of each of the seven phases of the
21284  compiler and its MCU dependency.
21285 \layout Itemize
21286
21287 Parsing the source and building the annotated parse tree.
21288  This phase is largely MCU independent (except for the language extensions).
21289  Syntax & semantic checks are also done in this phase, along with some initial
21290  optimizations like back patching labels and the pattern matching optimizations
21291  like bit-rotation etc.
21292 \layout Itemize
21293
21294 The second phase involves generating an intermediate code which can be easy
21295  manipulated during the later phases.
21296  This phase is entirely MCU independent.
21297  The intermediate code generation assumes the target machine has unlimited
21298  number of registers, and designates them with the name iTemp.
21299  The compiler can be made to dump a human readable form of the code generated
21300  by using the -
21301 \begin_inset ERT
21302 status Collapsed
21303
21304 \layout Standard
21305
21306 \backslash 
21307 /
21308 \end_inset 
21309
21310 -dumpraw option.
21311 \layout Itemize
21312
21313 This phase does the bulk of the standard optimizations and is also MCU independe
21314 nt.
21315  This phase can be broken down into several sub-phases:
21316 \newline 
21317
21318 \newline 
21319 Break down intermediate code (iCode) into basic blocks.
21320 \newline 
21321 Do control flow & data flow analysis on the basic blocks.
21322 \newline 
21323 Do local common subexpression elimination, then global subexpression elimination
21324 \newline 
21325 Dead code elimination
21326 \newline 
21327 Loop optimizations
21328 \newline 
21329 If loop optimizations caused any changes then do 'global subexpression eliminati
21330 on' and 'dead code elimination' again.
21331 \layout Itemize
21332
21333 This phase determines the live-ranges; by live range I mean those iTemp
21334  variables defined by the compiler that still survive after all the optimization
21335 s.
21336  Live range analysis
21337 \begin_inset LatexCommand \index{Live range analysis}
21338
21339 \end_inset 
21340
21341  is essential for register allocation, since these computation determines
21342  which of these iTemps will be assigned to registers, and for how long.
21343 \layout Itemize
21344
21345 Phase five is register allocation.
21346  There are two parts to this process.
21347 \newline 
21348
21349 \newline 
21350 The first part I call 'register packing' (for lack of a better term).
21351  In this case several MCU specific expression folding is done to reduce
21352  register pressure.
21353 \newline 
21354
21355 \newline 
21356 The second part is more MCU independent and deals with allocating registers
21357  to the remaining live ranges.
21358  A lot of MCU specific code does creep into this phase because of the limited
21359  number of index registers available in the 8051.
21360 \layout Itemize
21361
21362 The Code generation phase is (unhappily), entirely MCU dependent and very
21363  little (if any at all) of this code can be reused for other MCU.
21364  However the scheme for allocating a homogenized assembler operand for each
21365  iCode operand may be reused.
21366 \layout Itemize
21367
21368 As mentioned in the optimization section the peep-hole optimizer is rule
21369  based system, which can reprogrammed for other MCUs.
21370 \layout Chapter
21371
21372 Compiler internals
21373 \begin_inset LatexCommand \index{Compiler internals}
21374
21375 \end_inset 
21376
21377
21378 \layout Section
21379
21380 The anatomy of the compiler
21381 \begin_inset LatexCommand \label{sub:The-anatomy-of}
21382
21383 \end_inset 
21384
21385
21386 \layout Standard
21387
21388
21389 \shape italic 
21390 This is an excerpt from an article published in Circuit Cellar Magazine
21391  in august 2000.
21392  It's a little outdated (the compiler is much more efficient now and user/develo
21393 per friendly), but pretty well exposes the guts of it all.
21394 \shape default 
21395
21396 \newline 
21397
21398 \newline 
21399 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
21400  It is fairly easy to retarget for other 8-bit MCU.
21401  Here we take a look at some of the internals of the compiler.
21402  
21403 \layout Paragraph*
21404
21405 Parsing
21406 \begin_inset LatexCommand \index{Parsing}
21407
21408 \end_inset 
21409
21410  
21411 \layout Standard
21412
21413 Parsing the input source file and creating an AST (Annotated Syntax Tree
21414 \begin_inset LatexCommand \index{Annotated syntax tree}
21415
21416 \end_inset 
21417
21418 ).
21419  This phase also involves propagating types (annotating each node of the
21420  parse tree with type information) and semantic analysis.
21421  There are some MCU specific parsing rules.
21422  For example the storage classes, the extended storage classes are MCU specific
21423  while there may be a xdata storage class for 8051 there is no such storage
21424  class for z80 or Atmel AVR.
21425  SDCC allows MCU specific storage class extensions, i.e.
21426  xdata will be treated as a storage class specifier when parsing 8051 C
21427  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
21428  C code.
21429 \layout Paragraph*
21430
21431 Generating iCode
21432 \begin_inset LatexCommand \index{iCode}
21433
21434 \end_inset 
21435
21436
21437 \layout Standard
21438
21439 Intermediate code generation.
21440  In this phase the AST is broken down into three-operand form (iCode).
21441  These three operand forms are represented as doubly linked lists.
21442  ICode is the term given to the intermediate form generated by the compiler.
21443  ICode example section shows some examples of iCode generated for some simple
21444  C source functions.
21445 \layout Paragraph*
21446
21447 Optimizations
21448 \begin_inset LatexCommand \index{Optimizations}
21449
21450 \end_inset 
21451
21452 .
21453 \layout Standard
21454
21455 Bulk of the target independent optimizations is performed in this phase.
21456  The optimizations include constant propagation, common sub-expression eliminati
21457 on, loop invariant code movement, strength reduction of loop induction variables
21458  and dead-code elimination.
21459 \layout Paragraph*
21460
21461 Live range analysis
21462 \begin_inset LatexCommand \index{Live range analysis}
21463
21464 \end_inset 
21465
21466
21467 \layout Standard
21468
21469 During intermediate code generation phase, the compiler assumes the target
21470  machine has infinite number of registers and generates a lot of temporary
21471  variables.
21472  The live range computation determines the lifetime of each of these compiler-ge
21473 nerated temporaries.
21474  A picture speaks a thousand words.
21475  ICode example sections show the live range annotations for each of the
21476  operand.
21477  It is important to note here, each iCode is assigned a number in the order
21478  of its execution in the function.
21479  The live ranges are computed in terms of these numbers.
21480  The from number is the number of the iCode which first defines the operand
21481  and the to number signifies the iCode which uses this operand last.
21482 \layout Paragraph*
21483
21484 Register Allocation
21485 \begin_inset LatexCommand \index{Register allocation}
21486
21487 \end_inset 
21488
21489
21490 \layout Standard
21491
21492 The register allocation determines the type and number of registers needed
21493  by each operand.
21494  In most MCUs only a few registers can be used for indirect addressing.
21495  In case of 8051 for example the registers R0 & R1 can be used to indirectly
21496  address the internal ram and DPTR to indirectly address the external ram.
21497  The compiler will try to allocate the appropriate register to pointer variables
21498  if it can.
21499  ICode example section shows the operands annotated with the registers assigned
21500  to them.
21501  The compiler will try to keep operands in registers as much as possible;
21502  there are several schemes the compiler uses to do achieve this.
21503  When the compiler runs out of registers the compiler will check to see
21504  if there are any live operands which is not used or defined in the current
21505  basic block being processed, if there are any found then it will push that
21506  operand and use the registers in this block, the operand will then be popped
21507  at the end of the basic block.
21508  
21509 \layout Standard
21510
21511 There are other MCU specific considerations in this phase.
21512  Some MCUs have an accumulator; very short-lived operands could be assigned
21513  to the accumulator instead of a general-purpose register.
21514 \layout Paragraph*
21515
21516 Code generation
21517 \layout Standard
21518
21519 Figure II gives a table of iCode operations supported by the compiler.
21520  The code generation involves translating these operations into corresponding
21521  assembly code for the processor.
21522  This sounds overly simple but that is the essence of code generation.
21523  Some of the iCode operations are generated on a MCU specific manner for
21524  example, the z80 port does not use registers to pass parameters so the
21525  SEND and RECV iCode operations will not be generated, and it also does
21526  not support JUMPTABLES.
21527  
21528 \newline 
21529
21530 \series bold 
21531 \shape italic 
21532 \color red
21533 <Where is Figure II ?>
21534 \layout Paragraph*
21535
21536 ICode Example
21537 \begin_inset LatexCommand \index{iCode}
21538
21539 \end_inset 
21540
21541
21542 \layout Standard
21543
21544 This section shows some details of iCode.
21545  The example C code does not do anything useful; it is used as an example
21546  to illustrate the intermediate code generated by the compiler.
21547 \layout Verse
21548
21549
21550 \family typewriter 
21551 1.\SpecialChar ~
21552 xdata int * p;
21553 \newline 
21554 2.\SpecialChar ~
21555 int gint;
21556 \newline 
21557 3.\SpecialChar ~
21558 /* This function does nothing useful.
21559  It is used
21560 \newline 
21561 4.\SpecialChar ~
21562 \SpecialChar ~
21563 \SpecialChar ~
21564 \SpecialChar ~
21565 for the purpose of explaining iCode */
21566 \newline 
21567 5.\SpecialChar ~
21568 short function (data int *x)
21569 \newline 
21570 6.\SpecialChar ~
21571 {
21572 \newline 
21573 7.\SpecialChar ~
21574 \SpecialChar ~
21575 \SpecialChar ~
21576 short i=10; \SpecialChar ~
21577 \SpecialChar ~
21578 /* dead initialization eliminated */
21579 \newline 
21580 8.\SpecialChar ~
21581 \SpecialChar ~
21582 \SpecialChar ~
21583 short sum=10; /* dead initialization eliminated */
21584 \newline 
21585 9.\SpecialChar ~
21586 \SpecialChar ~
21587 \SpecialChar ~
21588 short mul;
21589 \newline 
21590 10.\SpecialChar ~
21591 \SpecialChar ~
21592 int j ;
21593 \newline 
21594 11.\SpecialChar ~
21595 \SpecialChar ~
21596 while (*x) *x++ = *p++; 
21597 \newline 
21598 12.\SpecialChar ~
21599 \SpecialChar ~
21600 \SpecialChar ~
21601 \SpecialChar ~
21602 sum = 0 ; 
21603 \newline 
21604 13.\SpecialChar ~
21605 \SpecialChar ~
21606 mul = 0;
21607 \newline 
21608 14.\SpecialChar ~
21609 \SpecialChar ~
21610 /* compiler detects i,j to be induction variables */
21611 \newline 
21612 15.\SpecialChar ~
21613 \SpecialChar ~
21614 for (i = 0, j = 10 ; i < 10 ; i++, j
21615 \family default 
21616 -
21617 \begin_inset ERT
21618 status Collapsed
21619
21620 \layout Standard
21621
21622 \backslash 
21623 /
21624 \end_inset 
21625
21626 -
21627 \family typewriter 
21628 ) {
21629 \newline 
21630 16.\SpecialChar ~
21631 \SpecialChar ~
21632 \SpecialChar ~
21633 \SpecialChar ~
21634 sum += i;
21635 \newline 
21636 17.\SpecialChar ~
21637 \SpecialChar ~
21638 \SpecialChar ~
21639 \SpecialChar ~
21640 mul += i * 3; \SpecialChar ~
21641 \SpecialChar ~
21642 /* this multiplication remains */
21643 \newline 
21644 18.\SpecialChar ~
21645 \SpecialChar ~
21646 \SpecialChar ~
21647 \SpecialChar ~
21648 gint += j * 3;\SpecialChar ~
21649 \SpecialChar ~
21650 /* this multiplication changed to addition */
21651 \newline 
21652 19.\SpecialChar ~
21653 \SpecialChar ~
21654 }
21655 \newline 
21656 20.\SpecialChar ~
21657 \SpecialChar ~
21658 return sum+mul;
21659 \newline 
21660 21.\SpecialChar ~
21661 }
21662 \layout Standard
21663
21664 In addition to the operands each iCode contains information about the filename
21665  and line it corresponds to in the source file.
21666  The first field in the listing should be interpreted as follows:
21667 \newline 
21668
21669 \shape italic 
21670 \size footnotesize 
21671 Filename(linenumber: iCode Execution sequence number : ICode hash table
21672  key : loop depth of the iCode).
21673 \shape default 
21674 \size default 
21675
21676 \newline 
21677 Then follows the human readable form of the ICode operation.
21678  Each operand of this triplet form can be of three basic types a) compiler
21679  generated temporary b) user defined variable c) a constant value.
21680  Note that local variables and parameters are replaced by compiler generated
21681  temporaries.
21682  Live ranges
21683 \begin_inset LatexCommand \index{Live range analysis}
21684
21685 \end_inset 
21686
21687  are computed only for temporaries (i.e.
21688  live ranges are not computed for global variables).
21689  Registers
21690 \begin_inset LatexCommand \index{Register allocation}
21691
21692 \end_inset 
21693
21694  are allocated for temporaries only.
21695  Operands are formatted in the following manner:
21696 \newline 
21697
21698 \shape italic 
21699 \size footnotesize 
21700 Operand Name [lr live-from : live-to ] { type information } [ registers
21701  allocated ].
21702 \shape default 
21703 \size default 
21704
21705 \newline 
21706 As mentioned earlier the live ranges are computed in terms of the execution
21707  sequence number of the iCodes, for example 
21708 \newline 
21709 the iTemp0 is live from (i.e.
21710  first defined in iCode with execution sequence number 3, and is last used
21711  in the iCode with sequence number 5).
21712  For induction variables such as iTemp21 the live range computation extends
21713  the lifetime from the start to the end of the loop.
21714 \newline 
21715 The register allocator used the live range information to allocate registers,
21716  the same registers may be used for different temporaries if their live
21717  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
21718  iTemp17 since their live ranges do not overlap.
21719  In addition the allocator also takes into consideration the type and usage
21720  of a temporary, for example itemp6 is a pointer to near space and is used
21721  as to fetch data from (i.e.
21722  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
21723  Some short lived temporaries are allocated to special registers which have
21724  meaning to the code generator e.g.
21725  iTemp13 is allocated to a pseudo register CC which tells the back end that
21726  the temporary is used only for a conditional jump the code generation makes
21727  use of this information to optimize a compare and jump ICode.
21728 \newline 
21729 There are several loop optimizations
21730 \begin_inset LatexCommand \index{Loop optimization}
21731
21732 \end_inset 
21733
21734  performed by the compiler.
21735  It can detect induction variables iTemp21(i) and iTemp23(j).
21736  Also note the compiler does selective strength reduction
21737 \begin_inset LatexCommand \index{Strength reduction}
21738
21739 \end_inset 
21740
21741 , i.e.
21742  the multiplication of an induction variable in line 18 (gint = j * 3) is
21743  changed to addition, a new temporary iTemp17 is allocated and assigned
21744  a initial value, a constant 3 is then added for each iteration of the loop.
21745  The compiler does not change the multiplication
21746 \begin_inset LatexCommand \index{Multiplication}
21747
21748 \end_inset 
21749
21750  in line 17 however since the processor does support an 8 * 8 bit multiplication.
21751 \newline 
21752 Note the dead code elimination
21753 \begin_inset LatexCommand \index{Dead-code elimination}
21754
21755 \end_inset 
21756
21757  optimization eliminated the dead assignments in line 7 & 8 to I and sum
21758  respectively.
21759 \newline 
21760
21761 \layout Standard
21762
21763
21764 \size footnotesize 
21765 Sample.c (5:1:0:0) _entry($9) :
21766 \layout Standard
21767
21768
21769 \size footnotesize 
21770 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
21771 \layout Standard
21772
21773
21774 \size footnotesize 
21775 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
21776 \layout Standard
21777
21778
21779 \size footnotesize 
21780 Sample.c(11:4:53:0) preHeaderLbl0($11) :
21781 \layout Standard
21782
21783
21784 \size footnotesize 
21785 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
21786  * int}[r2]
21787 \layout Standard
21788
21789
21790 \size footnotesize 
21791 Sample.c(11:6:5:1) _whilecontinue_0($1) :
21792 \layout Standard
21793
21794
21795 \size footnotesize 
21796 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
21797  int}[r0]]
21798 \layout Standard
21799
21800
21801 \size footnotesize 
21802 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21803 \layout Standard
21804
21805
21806 \size footnotesize 
21807 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
21808  * int}
21809 \layout Standard
21810
21811
21812 \size footnotesize 
21813 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
21814  {short}
21815 \layout Standard
21816
21817
21818 \size footnotesize 
21819 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
21820  * int}[DPTR]]
21821 \layout Standard
21822
21823
21824 \size footnotesize 
21825 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
21826 }[r2 r3]
21827 \layout Standard
21828
21829
21830 \size footnotesize 
21831 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
21832  * int}[r0] + 0x2 {short}
21833 \layout Standard
21834
21835
21836 \size footnotesize 
21837 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
21838 \layout Standard
21839
21840
21841 \size footnotesize 
21842 Sample.c(11:17:21:0)_whilebreak_0($3) :
21843 \layout Standard
21844
21845
21846 \size footnotesize 
21847 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21848 \layout Standard
21849
21850
21851 \size footnotesize 
21852 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21853 \layout Standard
21854
21855
21856 \size footnotesize 
21857 Sample.c(15:20:54:0)preHeaderLbl1($13) :
21858 \layout Standard
21859
21860
21861 \size footnotesize 
21862 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21863 \layout Standard
21864
21865
21866 \size footnotesize 
21867 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21868 \layout Standard
21869
21870
21871 \size footnotesize 
21872 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21873 \layout Standard
21874
21875
21876 \size footnotesize 
21877 Sample.c(15:24:26:1)_forcond_0($4) :
21878 \layout Standard
21879
21880
21881 \size footnotesize 
21882 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
21883  < 0xa {short}
21884 \layout Standard
21885
21886
21887 \size footnotesize 
21888 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21889 \layout Standard
21890
21891
21892 \size footnotesize 
21893 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
21894  + ITemp21 [lr21:38]{short}[r4]
21895 \layout Standard
21896
21897
21898 \size footnotesize 
21899 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
21900  * 0x3 {short}
21901 \layout Standard
21902
21903
21904 \size footnotesize 
21905 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
21906  + iTemp15 [lr29:30]{short}[r1]
21907 \layout Standard
21908
21909
21910 \size footnotesize 
21911 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
21912  r0]- 0x3 {short}
21913 \layout Standard
21914
21915
21916 \size footnotesize 
21917 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
21918 int}[r7 r0]
21919 \layout Standard
21920
21921
21922 \size footnotesize 
21923 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
21924  + 0x1 {short}
21925 \layout Standard
21926
21927
21928 \size footnotesize 
21929 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
21930  r6]- 0x1 {short}
21931 \layout Standard
21932
21933
21934 \size footnotesize 
21935 Sample.c(19:38:47:1) goto _forcond_0($4)
21936 \layout Standard
21937
21938
21939 \size footnotesize 
21940 Sample.c(19:39:48:0)_forbreak_0($7) :
21941 \layout Standard
21942
21943
21944 \size footnotesize 
21945 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
21946  + ITemp11 [lr19:40]{short}[r3]
21947 \layout Standard
21948
21949
21950 \size footnotesize 
21951 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
21952 \layout Standard
21953
21954
21955 \size footnotesize 
21956 Sample.c(20:42:51:0)_return($8) :
21957 \layout Standard
21958
21959
21960 \size footnotesize 
21961 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
21962 \size default 
21963
21964 \newline 
21965
21966 \newline 
21967 Finally the code generated for this function:
21968 \newline 
21969
21970 \layout Standard
21971
21972
21973 \size footnotesize 
21974 .area DSEG (DATA)
21975 \layout Standard
21976
21977
21978 \size footnotesize 
21979 _p::
21980 \layout Standard
21981
21982
21983 \size footnotesize 
21984 \SpecialChar ~
21985 \SpecialChar ~
21986 .ds 2
21987 \layout Standard
21988
21989
21990 \size footnotesize 
21991 _gint::
21992 \layout Standard
21993
21994
21995 \size footnotesize 
21996 \SpecialChar ~
21997 \SpecialChar ~
21998 .ds 2
21999 \layout Standard
22000
22001
22002 \size footnotesize 
22003 ; sample.c 5
22004 \layout Standard
22005
22006
22007 \size footnotesize 
22008 ; ----------------------------------------------
22009 \layout Standard
22010
22011
22012 \size footnotesize 
22013 ; function function
22014 \layout Standard
22015
22016
22017 \size footnotesize 
22018 ; ----------------------------------------------
22019 \layout Standard
22020
22021
22022 \size footnotesize 
22023 _function:
22024 \layout Standard
22025
22026
22027 \size footnotesize 
22028 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
22029 \layout Standard
22030
22031
22032 \size footnotesize 
22033 \SpecialChar ~
22034 \SpecialChar ~
22035 mov r2,dpl
22036 \layout Standard
22037
22038
22039 \size footnotesize 
22040 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
22041 \layout Standard
22042
22043
22044 \size footnotesize 
22045 \SpecialChar ~
22046 \SpecialChar ~
22047 mov ar0,r2
22048 \layout Standard
22049
22050
22051 \size footnotesize 
22052 ;_whilecontinue_0($1) :
22053 \layout Standard
22054
22055
22056 \size footnotesize 
22057 00101$:
22058 \layout Standard
22059
22060
22061 \size footnotesize 
22062 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
22063 \layout Standard
22064
22065
22066 \size footnotesize 
22067 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
22068 \layout Standard
22069
22070
22071 \size footnotesize 
22072 \SpecialChar ~
22073 \SpecialChar ~
22074 mov ar2,@r0
22075 \layout Standard
22076
22077
22078 \size footnotesize 
22079 \SpecialChar ~
22080 \SpecialChar ~
22081 inc r0
22082 \layout Standard
22083
22084
22085 \size footnotesize 
22086 \SpecialChar ~
22087 \SpecialChar ~
22088 mov ar3,@r0
22089 \layout Standard
22090
22091
22092 \size footnotesize 
22093 \SpecialChar ~
22094 \SpecialChar ~
22095 dec r0
22096 \layout Standard
22097
22098
22099 \size footnotesize 
22100 \SpecialChar ~
22101 \SpecialChar ~
22102 mov a,r2
22103 \layout Standard
22104
22105
22106 \size footnotesize 
22107 \SpecialChar ~
22108 \SpecialChar ~
22109 orl a,r3
22110 \layout Standard
22111
22112
22113 \size footnotesize 
22114 \SpecialChar ~
22115 \SpecialChar ~
22116 jz 00103$
22117 \layout Standard
22118
22119
22120 \size footnotesize 
22121 00114$:
22122 \layout Standard
22123
22124
22125 \size footnotesize 
22126 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
22127 \layout Standard
22128
22129
22130 \size footnotesize 
22131 \SpecialChar ~
22132 \SpecialChar ~
22133 mov dpl,_p
22134 \layout Standard
22135
22136
22137 \size footnotesize 
22138 \SpecialChar ~
22139 \SpecialChar ~
22140 mov dph,(_p + 1)
22141 \layout Standard
22142
22143
22144 \size footnotesize 
22145 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
22146 \layout Standard
22147
22148
22149 \size footnotesize 
22150 \SpecialChar ~
22151 \SpecialChar ~
22152 mov a,#0x02
22153 \layout Standard
22154
22155
22156 \size footnotesize 
22157 \SpecialChar ~
22158 \SpecialChar ~
22159 add a,_p
22160 \layout Standard
22161
22162
22163 \size footnotesize 
22164 \SpecialChar ~
22165 \SpecialChar ~
22166 mov _p,a
22167 \layout Standard
22168
22169
22170 \size footnotesize 
22171 \SpecialChar ~
22172 \SpecialChar ~
22173 clr a
22174 \layout Standard
22175
22176
22177 \size footnotesize 
22178 \SpecialChar ~
22179 \SpecialChar ~
22180 addc a,(_p + 1)
22181 \layout Standard
22182
22183
22184 \size footnotesize 
22185 \SpecialChar ~
22186 \SpecialChar ~
22187 mov (_p + 1),a
22188 \layout Standard
22189
22190
22191 \size footnotesize 
22192 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
22193 \layout Standard
22194
22195
22196 \size footnotesize 
22197 \SpecialChar ~
22198 \SpecialChar ~
22199 movx a,@dptr
22200 \layout Standard
22201
22202
22203 \size footnotesize 
22204 \SpecialChar ~
22205 \SpecialChar ~
22206 mov r2,a
22207 \layout Standard
22208
22209
22210 \size footnotesize 
22211 \SpecialChar ~
22212 \SpecialChar ~
22213 inc dptr
22214 \layout Standard
22215
22216
22217 \size footnotesize 
22218 \SpecialChar ~
22219 \SpecialChar ~
22220 movx a,@dptr
22221 \layout Standard
22222
22223
22224 \size footnotesize 
22225 \SpecialChar ~
22226 \SpecialChar ~
22227 mov r3,a
22228 \layout Standard
22229
22230
22231 \size footnotesize 
22232 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
22233 \layout Standard
22234
22235
22236 \size footnotesize 
22237 \SpecialChar ~
22238 \SpecialChar ~
22239 mov @r0,ar2
22240 \layout Standard
22241
22242
22243 \size footnotesize 
22244 \SpecialChar ~
22245 \SpecialChar ~
22246 inc r0
22247 \layout Standard
22248
22249
22250 \size footnotesize 
22251 \SpecialChar ~
22252 \SpecialChar ~
22253 mov @r0,ar3
22254 \layout Standard
22255
22256
22257 \size footnotesize 
22258 ; iTemp6 [lr5:16]{_near * int}[r0] = 
22259 \layout Standard
22260
22261
22262 \size footnotesize 
22263 ; iTemp6 [lr5:16]{_near * int}[r0] + 
22264 \layout Standard
22265
22266
22267 \size footnotesize 
22268 ; 0x2 {short}
22269 \layout Standard
22270
22271
22272 \size footnotesize 
22273 \SpecialChar ~
22274 \SpecialChar ~
22275 inc r0
22276 \layout Standard
22277
22278
22279 \size footnotesize 
22280 ; goto _whilecontinue_0($1)
22281 \layout Standard
22282
22283
22284 \size footnotesize 
22285 \SpecialChar ~
22286 \SpecialChar ~
22287 sjmp 00101$
22288 \layout Standard
22289
22290
22291 \size footnotesize 
22292 ; _whilebreak_0($3) :
22293 \layout Standard
22294
22295
22296 \size footnotesize 
22297 00103$:
22298 \layout Standard
22299
22300
22301 \size footnotesize 
22302 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
22303 \layout Standard
22304
22305
22306 \size footnotesize 
22307 \SpecialChar ~
22308 \SpecialChar ~
22309 mov r2,#0x00
22310 \layout Standard
22311
22312
22313 \size footnotesize 
22314 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
22315 \layout Standard
22316
22317
22318 \size footnotesize 
22319 \SpecialChar ~
22320 \SpecialChar ~
22321 mov r3,#0x00
22322 \layout Standard
22323
22324
22325 \size footnotesize 
22326 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
22327 \layout Standard
22328
22329
22330 \size footnotesize 
22331 \SpecialChar ~
22332 \SpecialChar ~
22333 mov r4,#0x00
22334 \layout Standard
22335
22336
22337 \size footnotesize 
22338 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
22339 \layout Standard
22340
22341
22342 \size footnotesize 
22343 \SpecialChar ~
22344 \SpecialChar ~
22345 mov r5,#0x0A
22346 \layout Standard
22347
22348
22349 \size footnotesize 
22350 \SpecialChar ~
22351 \SpecialChar ~
22352 mov r6,#0x00
22353 \layout Standard
22354
22355
22356 \size footnotesize 
22357 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
22358 \layout Standard
22359
22360
22361 \size footnotesize 
22362 \SpecialChar ~
22363 \SpecialChar ~
22364 mov r7,#0x1E
22365 \layout Standard
22366
22367
22368 \size footnotesize 
22369 \SpecialChar ~
22370 \SpecialChar ~
22371 mov r0,#0x00
22372 \layout Standard
22373
22374
22375 \size footnotesize 
22376 ; _forcond_0($4) :
22377 \layout Standard
22378
22379
22380 \size footnotesize 
22381 00104$:
22382 \layout Standard
22383
22384
22385 \size footnotesize 
22386 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
22387 \layout Standard
22388
22389
22390 \size footnotesize 
22391 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
22392 \layout Standard
22393
22394
22395 \size footnotesize 
22396 \SpecialChar ~
22397 \SpecialChar ~
22398 clr c
22399 \layout Standard
22400
22401
22402 \size footnotesize 
22403 \SpecialChar ~
22404 \SpecialChar ~
22405 mov a,r4
22406 \layout Standard
22407
22408
22409 \size footnotesize 
22410 \SpecialChar ~
22411 \SpecialChar ~
22412 xrl a,#0x80
22413 \layout Standard
22414
22415
22416 \size footnotesize 
22417 \SpecialChar ~
22418 \SpecialChar ~
22419 subb a,#0x8a
22420 \layout Standard
22421
22422
22423 \size footnotesize 
22424 \SpecialChar ~
22425 \SpecialChar ~
22426 jnc 00107$
22427 \layout Standard
22428
22429
22430 \size footnotesize 
22431 00115$:
22432 \layout Standard
22433
22434
22435 \size footnotesize 
22436 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
22437 \layout Standard
22438
22439
22440 \size footnotesize 
22441 ; iTemp21 [lr21:38]{short}[r4]
22442 \layout Standard
22443
22444
22445 \size footnotesize 
22446 \SpecialChar ~
22447 \SpecialChar ~
22448 mov a,r4
22449 \layout Standard
22450
22451
22452 \size footnotesize 
22453 \SpecialChar ~
22454 \SpecialChar ~
22455 add a,r2
22456 \layout Standard
22457
22458
22459 \size footnotesize 
22460 \SpecialChar ~
22461 \SpecialChar ~
22462 mov r2,a
22463 \layout Standard
22464
22465
22466 \size footnotesize 
22467 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
22468 \layout Standard
22469
22470
22471 \size footnotesize 
22472 \SpecialChar ~
22473 \SpecialChar ~
22474 mov b,#0x03
22475 \layout Standard
22476
22477
22478 \size footnotesize 
22479 \SpecialChar ~
22480 \SpecialChar ~
22481 mov a,r4
22482 \layout Standard
22483
22484
22485 \size footnotesize 
22486 \SpecialChar ~
22487 \SpecialChar ~
22488 mul ab
22489 \layout Standard
22490
22491
22492 \size footnotesize 
22493 \SpecialChar ~
22494 \SpecialChar ~
22495 mov r1,a
22496 \layout Standard
22497
22498
22499 \size footnotesize 
22500 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
22501 \layout Standard
22502
22503
22504 \size footnotesize 
22505 ; iTemp15 [lr29:30]{short}[r1]
22506 \layout Standard
22507
22508
22509 \size footnotesize 
22510 \SpecialChar ~
22511 \SpecialChar ~
22512 add a,r3
22513 \layout Standard
22514
22515
22516 \size footnotesize 
22517 \SpecialChar ~
22518 \SpecialChar ~
22519 mov r3,a
22520 \layout Standard
22521
22522
22523 \size footnotesize 
22524 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
22525 \layout Standard
22526
22527
22528 \size footnotesize 
22529 \SpecialChar ~
22530 \SpecialChar ~
22531 mov a,r7
22532 \layout Standard
22533
22534
22535 \size footnotesize 
22536 \SpecialChar ~
22537 \SpecialChar ~
22538 add a,#0xfd
22539 \layout Standard
22540
22541
22542 \size footnotesize 
22543 \SpecialChar ~
22544 \SpecialChar ~
22545 mov r7,a
22546 \layout Standard
22547
22548
22549 \size footnotesize 
22550 \SpecialChar ~
22551 \SpecialChar ~
22552 mov a,r0
22553 \layout Standard
22554
22555
22556 \size footnotesize 
22557 \SpecialChar ~
22558 \SpecialChar ~
22559 addc a,#0xff
22560 \layout Standard
22561
22562
22563 \size footnotesize 
22564 \SpecialChar ~
22565 \SpecialChar ~
22566 mov r0,a
22567 \layout Standard
22568
22569
22570 \size footnotesize 
22571 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
22572 \layout Standard
22573
22574
22575 \size footnotesize 
22576 \SpecialChar ~
22577 \SpecialChar ~
22578 mov a,r7
22579 \layout Standard
22580
22581
22582 \size footnotesize 
22583 \SpecialChar ~
22584 \SpecialChar ~
22585 add a,_gint
22586 \layout Standard
22587
22588
22589 \size footnotesize 
22590 \SpecialChar ~
22591 \SpecialChar ~
22592 mov _gint,a
22593 \layout Standard
22594
22595
22596 \size footnotesize 
22597 \SpecialChar ~
22598 \SpecialChar ~
22599 mov a,r0
22600 \layout Standard
22601
22602
22603 \size footnotesize 
22604 \SpecialChar ~
22605 \SpecialChar ~
22606 addc a,(_gint + 1)
22607 \layout Standard
22608
22609
22610 \size footnotesize 
22611 \SpecialChar ~
22612 \SpecialChar ~
22613 mov (_gint + 1),a
22614 \layout Standard
22615
22616
22617 \size footnotesize 
22618 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
22619 \layout Standard
22620
22621
22622 \size footnotesize 
22623 \SpecialChar ~
22624 \SpecialChar ~
22625 inc r4
22626 \layout Standard
22627
22628
22629 \size footnotesize 
22630 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
22631 \layout Standard
22632
22633
22634 \size footnotesize 
22635 \SpecialChar ~
22636 \SpecialChar ~
22637 dec r5
22638 \layout Standard
22639
22640
22641 \size footnotesize 
22642 \SpecialChar ~
22643 \SpecialChar ~
22644 cjne r5,#0xff,00104$
22645 \layout Standard
22646
22647
22648 \size footnotesize 
22649 \SpecialChar ~
22650 \SpecialChar ~
22651 dec r6
22652 \layout Standard
22653
22654
22655 \size footnotesize 
22656 ; goto _forcond_0($4)
22657 \layout Standard
22658
22659
22660 \size footnotesize 
22661 \SpecialChar ~
22662 \SpecialChar ~
22663 sjmp 00104$
22664 \layout Standard
22665
22666
22667 \size footnotesize 
22668 ; _forbreak_0($7) :
22669 \layout Standard
22670
22671
22672 \size footnotesize 
22673 00107$:
22674 \layout Standard
22675
22676
22677 \size footnotesize 
22678 ; ret iTemp24 [lr40:41]{short}
22679 \layout Standard
22680
22681
22682 \size footnotesize 
22683 \SpecialChar ~
22684 \SpecialChar ~
22685 mov a,r3
22686 \layout Standard
22687
22688
22689 \size footnotesize 
22690 \SpecialChar ~
22691 \SpecialChar ~
22692 add a,r2
22693 \layout Standard
22694
22695
22696 \size footnotesize 
22697 \SpecialChar ~
22698 \SpecialChar ~
22699 mov dpl,a
22700 \layout Standard
22701
22702
22703 \size footnotesize 
22704 ; _return($8) :
22705 \layout Standard
22706
22707
22708 \size footnotesize 
22709 00108$:
22710 \layout Standard
22711
22712
22713 \size footnotesize 
22714 \SpecialChar ~
22715 \SpecialChar ~
22716 ret
22717 \newline 
22718
22719 \layout Section
22720
22721 A few words about basic block successors, predecessors and dominators
22722 \layout Standard
22723
22724 Successors are basic blocks
22725 \begin_inset LatexCommand \index{Basic blocks}
22726
22727 \end_inset 
22728
22729  that might execute after this basic block.
22730 \newline 
22731 Predecessors are basic blocks that might execute before reaching this basic
22732  block.
22733 \newline 
22734 Dominators are basic blocks that WILL execute before reaching this basic
22735  block.
22736 \newline 
22737
22738 \layout Standard
22739
22740 [basic block 1]
22741 \layout Standard
22742
22743 if (something)
22744 \layout Standard
22745
22746 \SpecialChar ~
22747 \SpecialChar ~
22748 \SpecialChar ~
22749 \SpecialChar ~
22750 [basic block 2]
22751 \layout Standard
22752
22753 else
22754 \layout Standard
22755
22756 \SpecialChar ~
22757 \SpecialChar ~
22758 \SpecialChar ~
22759 \SpecialChar ~
22760 [basic block 3]
22761 \layout Standard
22762
22763 [basic block 4]
22764 \newline 
22765
22766 \layout Standard
22767
22768 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
22769 \layout Standard
22770
22771 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
22772 \layout Standard
22773
22774 c) domVect of [BB4] = BB1 ...
22775  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
22776  was executed.
22777 \layout Chapter
22778
22779 Acknowledgments
22780 \layout Standard
22781
22782
22783 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
22784
22785 \end_inset 
22786
22787
22788 \newline 
22789
22790 \newline 
22791
22792 \emph on 
22793 Thanks to all the other volunteer developers who have helped with coding,
22794  testing, web-page creation, distribution sets, etc.
22795  You know who you are :-)
22796 \emph default 
22797
22798 \newline 
22799
22800 \layout Standard
22801
22802 This document was initially written by Sandeep Dutta
22803 \layout Standard
22804
22805 All product names mentioned herein may be trademarks
22806 \begin_inset LatexCommand \index{Trademarks}
22807
22808 \end_inset 
22809
22810  of their respective companies.
22811  
22812 \layout Section*
22813
22814 Alphabetical index
22815 \layout Standard
22816
22817 To avoid confusion, the installation and building options for SDCC itself
22818  (chapter 2) are not part of the index.
22819 \layout Standard
22820
22821
22822 \begin_inset LatexCommand \printindex{}
22823
22824 \end_inset 
22825
22826
22827 \the_end