582b8366792cb3fa72445d7b6ce3c34f1e7b0703
[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 \layout Section
1961
1962 Search Paths
1963 \begin_inset LatexCommand \label{sub:Search-Paths}
1964
1965 \end_inset 
1966
1967
1968 \begin_inset LatexCommand \index{Search path}
1969
1970 \end_inset 
1971
1972
1973 \layout Standard
1974
1975 Some search paths or parts of them are determined by configure variables
1976  (in 
1977 \emph on 
1978 italics
1979 \emph default 
1980 , see section above).
1981  Further search paths are determined by environment variables during runtime.
1982  
1983 \newline 
1984 The paths searched when running the compiler are as follows (the first catch
1985  wins):
1986 \newline 
1987
1988 \newline 
1989 1.
1990  Binary files (preprocessor, assembler and linker)
1991 \newline 
1992
1993 \layout Standard
1994 \align center 
1995
1996 \begin_inset  Tabular
1997 <lyxtabular version="3" rows="4" columns="3">
1998 <features>
1999 <column alignment="block" valignment="top" leftline="true" width="0in">
2000 <column alignment="block" valignment="top" leftline="true" width="0in">
2001 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2002 <row topline="true" bottomline="true">
2003 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2004 \begin_inset Text
2005
2006 \layout Standard
2007
2008 Search path
2009 \end_inset 
2010 </cell>
2011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2012 \begin_inset Text
2013
2014 \layout Standard
2015
2016 default
2017 \end_inset 
2018 </cell>
2019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2020 \begin_inset Text
2021
2022 \layout Standard
2023
2024 Win32 builds
2025 \end_inset 
2026 </cell>
2027 </row>
2028 <row topline="true">
2029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2030 \begin_inset Text
2031
2032 \layout Standard
2033
2034 $SDCC_HOME/
2035 \emph on 
2036 $PPREFIX2BIN_DIR
2037 \end_inset 
2038 </cell>
2039 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2040 \begin_inset Text
2041
2042 \layout Standard
2043
2044 $SDCC_HOME/bin
2045 \end_inset 
2046 </cell>
2047 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2048 \begin_inset Text
2049
2050 \layout Standard
2051
2052 $SDCC_HOME
2053 \backslash 
2054 bin
2055 \end_inset 
2056 </cell>
2057 </row>
2058 <row topline="true">
2059 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2060 \begin_inset Text
2061
2062 \layout Standard
2063
2064 Path of argv[0] (if available)
2065 \end_inset 
2066 </cell>
2067 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2068 \begin_inset Text
2069
2070 \layout Standard
2071
2072 Path of argv[0]
2073 \end_inset 
2074 </cell>
2075 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2076 \begin_inset Text
2077
2078 \layout Standard
2079
2080 Path of argv[0]
2081 \end_inset 
2082 </cell>
2083 </row>
2084 <row topline="true" bottomline="true">
2085 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2086 \begin_inset Text
2087
2088 \layout Standard
2089
2090 $PATH
2091 \end_inset 
2092 </cell>
2093 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2094 \begin_inset Text
2095
2096 \layout Standard
2097
2098 $PATH
2099 \end_inset 
2100 </cell>
2101 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2102 \begin_inset Text
2103
2104 \layout Standard
2105
2106 $PATH
2107 \end_inset 
2108 </cell>
2109 </row>
2110 </lyxtabular>
2111
2112 \end_inset 
2113
2114  
2115 \newline 
2116
2117 \layout Standard
2118 \noindent 
2119 2.
2120  Include files
2121 \newline 
2122
2123 \layout Standard
2124 \align center 
2125
2126 \begin_inset  Tabular
2127 <lyxtabular version="3" rows="6" columns="3">
2128 <features>
2129 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2130 <column alignment="block" valignment="top" leftline="true" width="1.5in">
2131 <column alignment="block" valignment="top" leftline="true" rightline="true" width="0in">
2132 <row topline="true" bottomline="true">
2133 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2134 \begin_inset Text
2135
2136 \layout Standard
2137
2138 Search path
2139 \end_inset 
2140 </cell>
2141 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2142 \begin_inset Text
2143
2144 \layout Standard
2145
2146 default
2147 \end_inset 
2148 </cell>
2149 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2150 \begin_inset Text
2151
2152 \layout Standard
2153
2154 Win32 builds
2155 \end_inset 
2156 </cell>
2157 </row>
2158 <row topline="true">
2159 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2160 \begin_inset Text
2161
2162 \layout Standard
2163
2164 -
2165 \begin_inset ERT
2166 status Collapsed
2167
2168 \layout Standard
2169
2170 \backslash 
2171 /
2172 \end_inset 
2173
2174 -I dir
2175 \end_inset 
2176 </cell>
2177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2178 \begin_inset Text
2179
2180 \layout Standard
2181
2182 -
2183 \begin_inset ERT
2184 status Collapsed
2185
2186 \layout Standard
2187
2188 \backslash 
2189 /
2190 \end_inset 
2191
2192 -I dir
2193 \end_inset 
2194 </cell>
2195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2196 \begin_inset Text
2197
2198 \layout Standard
2199
2200 -
2201 \begin_inset ERT
2202 status Collapsed
2203
2204 \layout Standard
2205
2206 \backslash 
2207 /
2208 \end_inset 
2209
2210 -I dir
2211 \end_inset 
2212 </cell>
2213 </row>
2214 <row topline="true">
2215 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2216 \begin_inset Text
2217
2218 \layout Standard
2219
2220 $SDCC_INCLUDE
2221 \end_inset 
2222 </cell>
2223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2224 \begin_inset Text
2225
2226 \layout Standard
2227
2228 $SDCC_INCLUDE
2229 \end_inset 
2230 </cell>
2231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2232 \begin_inset Text
2233
2234 \layout Standard
2235
2236 $SDCC_INCLUDE
2237 \end_inset 
2238 </cell>
2239 </row>
2240 <row topline="true">
2241 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2242 \begin_inset Text
2243
2244 \layout Standard
2245
2246 $SDCC_HOME/
2247 \newline 
2248
2249 \emph on 
2250 $PREFIX2DATA_DIR/
2251 \newline 
2252 $INCLUDE_DIR_SUFFIX
2253 \end_inset 
2254 </cell>
2255 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2256 \begin_inset Text
2257
2258 \layout Standard
2259
2260 $SDCC_ HOME/
2261 \newline 
2262 share/sdcc/
2263 \newline 
2264 include
2265 \end_inset 
2266 </cell>
2267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2268 \begin_inset Text
2269
2270 \layout Standard
2271
2272 $SDCC_HOME
2273 \backslash 
2274 include
2275 \end_inset 
2276 </cell>
2277 </row>
2278 <row topline="true">
2279 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2280 \begin_inset Text
2281
2282 \layout Standard
2283
2284 path(argv[0])/
2285 \newline 
2286
2287 \emph on 
2288 $BIN2DATADIR/
2289 \emph default 
2290
2291 \newline 
2292
2293 \emph on 
2294 $INCLUDE_DIR_SUFFIX
2295 \end_inset 
2296 </cell>
2297 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2298 \begin_inset Text
2299
2300 \layout Standard
2301
2302 path(argv[0])/
2303 \newline 
2304 ../sdcc/include
2305 \newline 
2306 \SpecialChar ~
2307 \SpecialChar ~
2308 \SpecialChar ~
2309 \SpecialChar ~
2310 \SpecialChar ~
2311 \SpecialChar ~
2312 \SpecialChar ~
2313 \SpecialChar ~
2314 \SpecialChar ~
2315 \SpecialChar ~
2316 \SpecialChar ~
2317 \SpecialChar ~
2318 \SpecialChar ~
2319 \SpecialChar ~
2320 \SpecialChar ~
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
2345 \end_inset 
2346 </cell>
2347 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2348 \begin_inset Text
2349
2350 \layout Standard
2351
2352 path(argv[0])
2353 \backslash 
2354 ..
2355 \backslash 
2356 include
2357 \end_inset 
2358 </cell>
2359 </row>
2360 <row topline="true" bottomline="true">
2361 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2362 \begin_inset Text
2363
2364 \layout Standard
2365
2366
2367 \emph on 
2368 $DATADIR/
2369 \emph default 
2370
2371 \newline 
2372
2373 \emph on 
2374 $INCLUDE_DIR_SUFFIX
2375 \end_inset 
2376 </cell>
2377 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2378 \begin_inset Text
2379
2380 \layout Standard
2381
2382 /usr/local/share/sdcc/
2383 \newline 
2384 include
2385 \end_inset 
2386 </cell>
2387 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2388 \begin_inset Text
2389
2390 \layout Standard
2391
2392 (not on Win32)
2393 \end_inset 
2394 </cell>
2395 </row>
2396 </lyxtabular>
2397
2398 \end_inset 
2399
2400  
2401 \newline 
2402
2403 \layout Standard
2404 \noindent 
2405 The option -
2406 \begin_inset ERT
2407 status Collapsed
2408
2409 \layout Standard
2410
2411 \backslash 
2412 /
2413 \end_inset 
2414
2415 -nostdinc disables the last two search paths.
2416 \newline 
2417
2418 \newline 
2419 3.
2420  Library files 
2421 \newline 
2422
2423 \layout Standard
2424
2425 With the exception of 
2426 \begin_inset Quotes sld
2427 \end_inset 
2428
2429 -
2430 \begin_inset ERT
2431 status Collapsed
2432
2433 \layout Standard
2434
2435 \backslash 
2436 /
2437 \end_inset 
2438
2439 -L dir
2440 \begin_inset Quotes srd
2441 \end_inset 
2442
2443  the 
2444 \shape italic 
2445 model
2446 \shape default 
2447  is auto-appended by the compiler (e.g.
2448  small, large, z80, ds390 etc.).
2449  
2450 \newline 
2451
2452 \layout Standard
2453 \align center 
2454
2455 \begin_inset  Tabular
2456 <lyxtabular version="3" rows="6" columns="3">
2457 <features>
2458 <column alignment="block" valignment="top" leftline="true" width="1.7in">
2459 <column alignment="block" valignment="top" leftline="true" width="1.2in">
2460 <column alignment="block" valignment="top" leftline="true" rightline="true" width="1.2in">
2461 <row topline="true" bottomline="true">
2462 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2463 \begin_inset Text
2464
2465 \layout Standard
2466
2467 Search path
2468 \end_inset 
2469 </cell>
2470 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2471 \begin_inset Text
2472
2473 \layout Standard
2474
2475 default
2476 \end_inset 
2477 </cell>
2478 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2479 \begin_inset Text
2480
2481 \layout Standard
2482
2483 Win32 builds
2484 \end_inset 
2485 </cell>
2486 </row>
2487 <row topline="true">
2488 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2489 \begin_inset Text
2490
2491 \layout Standard
2492
2493 -
2494 \begin_inset ERT
2495 status Collapsed
2496
2497 \layout Standard
2498
2499 \backslash 
2500 /
2501 \end_inset 
2502
2503 -L dir
2504 \end_inset 
2505 </cell>
2506 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2507 \begin_inset Text
2508
2509 \layout Standard
2510
2511 -
2512 \begin_inset ERT
2513 status Collapsed
2514
2515 \layout Standard
2516
2517 \backslash 
2518 /
2519 \end_inset 
2520
2521 -L dir
2522 \end_inset 
2523 </cell>
2524 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2525 \begin_inset Text
2526
2527 \layout Standard
2528
2529 -
2530 \begin_inset ERT
2531 status Collapsed
2532
2533 \layout Standard
2534
2535 \backslash 
2536 /
2537 \end_inset 
2538
2539 -L dir
2540 \end_inset 
2541 </cell>
2542 </row>
2543 <row topline="true">
2544 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2545 \begin_inset Text
2546
2547 \layout Standard
2548
2549 $SDCC_LIB/
2550 \newline 
2551
2552 \emph on 
2553 <model>
2554 \end_inset 
2555 </cell>
2556 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2557 \begin_inset Text
2558
2559 \layout Standard
2560
2561 $SDCC_LIB/
2562 \newline 
2563
2564 \emph on 
2565 <model>
2566 \end_inset 
2567 </cell>
2568 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2569 \begin_inset Text
2570
2571 \layout Standard
2572
2573 $SDCC_LIB
2574 \backslash 
2575
2576 \newline 
2577
2578 \emph on 
2579 <model>
2580 \end_inset 
2581 </cell>
2582 </row>
2583 <row topline="true">
2584 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2585 \begin_inset Text
2586
2587 \layout Standard
2588
2589 $SDCC_HOME/
2590 \newline 
2591
2592 \emph on 
2593 $PREFIX2DATA_DIR/
2594 \newline 
2595 $LIB_DIR_SUFFIX/<model>
2596 \end_inset 
2597 </cell>
2598 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2599 \begin_inset Text
2600
2601 \layout Standard
2602
2603 $SDCC_HOME/
2604 \newline 
2605 share/sdcc/
2606 \newline 
2607 lib/
2608 \emph on 
2609 <model>
2610 \end_inset 
2611 </cell>
2612 <cell alignment="left" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2613 \begin_inset Text
2614
2615 \layout Standard
2616
2617 $SDCC_HOME
2618 \backslash 
2619 lib
2620 \backslash 
2621
2622 \emph on 
2623
2624 \newline 
2625 <model>
2626 \end_inset 
2627 </cell>
2628 </row>
2629 <row topline="true">
2630 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2631 \begin_inset Text
2632
2633 \layout Standard
2634
2635 path(argv[0])/
2636 \newline 
2637
2638 \emph on 
2639 $BIN2DATADIR/
2640 \emph default 
2641
2642 \newline 
2643
2644 \emph on 
2645 $LIB_DIR_SUFFIX/<model>
2646 \end_inset 
2647 </cell>
2648 <cell alignment="left" valignment="top" topline="true" leftline="true" usebox="none">
2649 \begin_inset Text
2650
2651 \layout Standard
2652
2653 path(argv[0])/
2654 \newline 
2655 ../sdcc/lib/
2656 \emph on 
2657 <model>
2658 \newline 
2659 \SpecialChar ~
2660 \SpecialChar ~
2661 \SpecialChar ~
2662 \SpecialChar ~
2663 \SpecialChar ~
2664 \SpecialChar ~
2665 \SpecialChar ~
2666 \SpecialChar ~
2667 \SpecialChar ~
2668 \SpecialChar ~
2669 \SpecialChar ~
2670 \SpecialChar ~
2671 \SpecialChar ~
2672 \SpecialChar ~
2673 \SpecialChar ~
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
2699 \end_inset 
2700 </cell>
2701 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2702 \begin_inset Text
2703
2704 \layout Standard
2705
2706 path(argv[0])
2707 \backslash 
2708
2709 \newline 
2710 ..
2711 \backslash 
2712 lib
2713 \backslash 
2714
2715 \emph on 
2716 <model>
2717 \newline 
2718 \SpecialChar ~
2719 \SpecialChar ~
2720 \SpecialChar ~
2721 \SpecialChar ~
2722 \SpecialChar ~
2723 \SpecialChar ~
2724 \SpecialChar ~
2725 \SpecialChar ~
2726 \SpecialChar ~
2727 \SpecialChar ~
2728 \SpecialChar ~
2729 \SpecialChar ~
2730 \SpecialChar ~
2731 \SpecialChar ~
2732 \SpecialChar ~
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
2754 \end_inset 
2755 </cell>
2756 </row>
2757 <row topline="true" bottomline="true">
2758 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2759 \begin_inset Text
2760
2761 \layout Standard
2762
2763
2764 \emph on 
2765 $DATADIR/
2766 \newline 
2767 $LIB_DIR_SUFFIX/<model>
2768 \end_inset 
2769 </cell>
2770 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2771 \begin_inset Text
2772
2773 \layout Standard
2774
2775 /usr/local/share/sdcc/
2776 \newline 
2777 lib/
2778 \emph on 
2779 <model>
2780 \end_inset 
2781 </cell>
2782 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2783 \begin_inset Text
2784
2785 \layout Standard
2786
2787 (not on Win32)
2788 \end_inset 
2789 </cell>
2790 </row>
2791 </lyxtabular>
2792
2793 \end_inset 
2794
2795
2796 \newline 
2797
2798 \layout Comment
2799
2800 Don't delete any of the stray spaces in the table above without checking
2801  the HTML output (last line)!
2802 \layout Standard
2803
2804 \SpecialChar ~
2805
2806 \newline 
2807 The option -
2808 \begin_inset ERT
2809 status Collapsed
2810
2811 \layout Standard
2812
2813 \backslash 
2814 /
2815 \end_inset 
2816
2817 -nostdlib disables the last two search paths.
2818 \layout Section
2819
2820 Building SDCC
2821 \begin_inset LatexCommand \index{Building SDCC}
2822
2823 \end_inset 
2824
2825
2826 \layout Subsection
2827
2828 Building SDCC on Linux
2829 \begin_inset LatexCommand \label{sub:Building-SDCC-on-Linux}
2830
2831 \end_inset 
2832
2833
2834 \layout Enumerate
2835
2836
2837 \series medium 
2838 Download the source package
2839 \series default 
2840  either from the SDCC CVS repository or from the nightly snapshots
2841 \series medium 
2842 , it will be named something like sdcc
2843 \series default 
2844 .src
2845 \series medium 
2846 .t
2847 \series default 
2848 ar.
2849 \series medium 
2850 gz
2851 \series default 
2852  
2853 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
2854
2855 \end_inset 
2856
2857 .
2858 \layout Enumerate
2859
2860
2861 \series medium 
2862 Bring up a command line terminal, such as xterm.
2863 \layout Enumerate
2864
2865
2866 \series medium 
2867 Unpack the file using a command like: 
2868 \family sans 
2869 \series bold 
2870 "tar -xvzf sdcc.src.tar.gz
2871 \family default 
2872 \series default 
2873 "
2874 \series medium 
2875 , this will create a sub-directory called sdcc with all of the sources.
2876 \layout Enumerate
2877
2878 Change directory into the main SDCC directory, for example type: 
2879 \family sans 
2880 \series bold 
2881 "cd sdcc
2882 \series default 
2883 ".
2884 \layout Enumerate
2885
2886
2887 \series medium 
2888 Type 
2889 \family sans 
2890 \series bold 
2891 "./configure
2892 \family default 
2893 \series default 
2894 ".
2895  This configures the package for compilation on your system.
2896 \layout Enumerate
2897
2898
2899 \series medium 
2900 Type 
2901 \family sans 
2902 \series bold 
2903 "make
2904 \family default 
2905 \series default 
2906 "
2907 \series medium 
2908 .
2909
2910 \series default 
2911  All of the source packages will compile, this can take a while.
2912 \layout Enumerate
2913
2914
2915 \series medium 
2916 Type 
2917 \family sans 
2918 \series bold 
2919 "make install"
2920 \family default 
2921 \series default 
2922  as root
2923 \series medium 
2924 .
2925
2926 \series default 
2927  This copies the binary executables, the include files, the libraries and
2928  the documentation to the install directories.
2929  Proceed with section 
2930 \begin_inset LatexCommand \ref{sec:Testing-the-SDCC}
2931
2932 \end_inset 
2933
2934 .
2935 \layout Subsection
2936
2937 Building SDCC on OSX 2.x
2938 \layout Standard
2939
2940 Follow the instruction for Linux.
2941 \newline 
2942
2943 \newline 
2944 On OSX 2.x it was reported, that the default gcc (version 3.1 20020420 (prerelease
2945 )) fails to compile SDCC.
2946  Fortunately there's also gcc 2.9.x installed, which works fine.
2947  This compiler can be selected by running 'configure' with:
2948 \layout LyX-Code
2949
2950 ./configure CC=gcc2 CXX=g++2
2951 \layout Subsection
2952
2953 Cross compiling SDCC on Linux for Windows
2954 \layout Standard
2955
2956 With the Mingw32 gcc cross compiler it's easy to compile SDCC for Win32.
2957  See section 'Configure Options'.
2958 \layout Subsection
2959
2960 Building SDCC on Windows 
2961 \layout Standard
2962
2963 With the exception of Cygwin the SDCC binaries uCsim and sdcdb can't be
2964  built on Windows.
2965  They use Unix-sockets, which are not available on Win32.
2966 \layout Subsection
2967
2968 Building SDCC using Cygwin and Mingw32
2969 \layout Standard
2970
2971 For building and installing a Cygwin executable follow the instructions
2972  for Linux.
2973 \newline 
2974
2975 \newline 
2976 On Cygwin a 
2977 \begin_inset Quotes sld
2978 \end_inset 
2979
2980 native
2981 \begin_inset Quotes srd
2982 \end_inset 
2983
2984  Win32-binary can be built, which will not need the Cygwin-DLL.
2985  For the necessary 'configure' options see section 'configure options' or
2986  the script 'sdcc/support/scripts/sdcc_cygwin_mingw32'.
2987 \newline 
2988
2989 \newline 
2990 In order to install Cygwin on Windows download setup.exe from 
2991 \begin_inset LatexCommand \url[www.cygwin.com]{http://www.cygwin.com/}
2992
2993 \end_inset 
2994
2995 .
2996  Run it, set the 
2997 \begin_inset Quotes sld
2998 \end_inset 
2999
3000 default text file type
3001 \begin_inset Quotes srd
3002 \end_inset 
3003
3004  to 
3005 \begin_inset Quotes sld
3006 \end_inset 
3007
3008 unix
3009 \begin_inset Quotes srd
3010 \end_inset 
3011
3012  and download/install at least the following packages.
3013  Some packages are selected by default, others will be automatically selected
3014  because of dependencies with the manually selected packages.
3015  Never deselect these packages!
3016 \layout Itemize
3017
3018 flex
3019 \layout Itemize
3020
3021 bison
3022 \layout Itemize
3023
3024 gcc ; version 3.x is fine, no need to use the old 2.9x
3025 \layout Itemize
3026
3027 binutils ; selected with gcc
3028 \layout Itemize
3029
3030 make
3031 \layout Itemize
3032
3033 rxvt ; a nice console, which makes life much easier under windoze (see below)
3034 \layout Itemize
3035
3036 man ; not really needed for building SDCC, but you'll miss it sooner or
3037  later
3038 \layout Itemize
3039
3040 less ; not really needed for building SDCC, but you'll miss it sooner or
3041  later
3042 \layout Itemize
3043
3044 cvs ; only if you use CVS access
3045 \layout Standard
3046
3047 If you want to develop something you'll need:
3048 \layout Itemize
3049
3050 python ; for the regression tests
3051 \layout Itemize
3052
3053 gdb ; the gnu debugger, together with the nice GUI 
3054 \begin_inset Quotes sld
3055 \end_inset 
3056
3057 insight
3058 \begin_inset Quotes srd
3059 \end_inset 
3060
3061
3062 \layout Itemize
3063
3064 openssh ; to access the CF or commit changes
3065 \layout Itemize
3066
3067 autoconf and autoconf-devel ; if you want to fight with 'configure', don't
3068  use autoconf-stable!
3069 \layout Standard
3070
3071 rxvt is a nice console with history.
3072  Replace in your cygwin.bat the line
3073 \layout LyX-Code
3074
3075 bash -
3076 \begin_inset ERT
3077 status Collapsed
3078
3079 \layout Standard
3080
3081 \backslash 
3082 /
3083 \end_inset 
3084
3085 -login -i 
3086 \layout Standard
3087
3088 with (one line):
3089 \layout LyX-Code
3090
3091 rxvt -sl 1000 -fn "Lucida Console-12" -sr -cr red
3092 \layout LyX-Code
3093
3094      -bg black -fg white -geometry 100x65 -e bash -
3095 \begin_inset ERT
3096 status Collapsed
3097
3098 \layout Standard
3099
3100 \backslash 
3101 /
3102 \end_inset 
3103
3104 -login
3105 \layout Standard
3106
3107 Text selected with the mouse is automatically copied to the clipboard, pasting
3108  works with shift-insert.
3109 \newline 
3110
3111 \newline 
3112 The other good tip is to make sure you have no //c/-style paths anywhere,
3113  use /cygdrive/c/ instead.
3114  Using // invokes a network lookup which is very slow.
3115  If you think 
3116 \begin_inset Quotes sld
3117 \end_inset 
3118
3119 cygdrive
3120 \begin_inset Quotes srd
3121 \end_inset 
3122
3123  is too long, you can change it with e.g.
3124 \layout LyX-Code
3125
3126 mount -s -u -c /mnt
3127 \layout Standard
3128
3129 SDCC sources use the unix line ending LF.
3130  Life is much easier, if you store the source tree on a drive which is mounted
3131  in binary mode.
3132  And use an editor which can handle LF-only line endings.
3133  Make sure not to commit files with windows line endings.
3134  The tabulator spacing
3135 \begin_inset LatexCommand \index{tabulator spacing (8)}
3136
3137 \end_inset 
3138
3139  used in the project is 8.
3140 \layout Subsection
3141
3142 Building SDCC Using Microsoft Visual C++ 6.0/NET (MSVC)
3143 \layout Standard
3144
3145
3146 \series medium 
3147 Download the source package
3148 \series default 
3149  either from the SDCC CVS repository or from the 
3150 \begin_inset LatexCommand \url[nightly snapshots]{http://sdcc.sourceforge.net/snap.php}
3151
3152 \end_inset 
3153
3154
3155 \series medium 
3156 , it will be named something like sdcc
3157 \series default 
3158 .src
3159 \series medium 
3160 .tgz.
3161
3162 \series default 
3163  SDCC is distributed with all the projects, workspaces, and files you need
3164  to build it using Visual C++ 6.0/NET (except for sdcdb.exe which currently
3165  doesn't build under MSVC).
3166  The workspace name is 'sdcc.dsw'.
3167  Please note that as it is now, all the executables are created in a folder
3168  called sdcc
3169 \backslash 
3170 bin_vc.
3171  Once built you need to copy the executables from sdcc
3172 \backslash 
3173 bin_vc to sdcc
3174 \backslash 
3175 bin before running SDCC.
3176  
3177 \newline 
3178
3179 \newline 
3180 WARNING: Visual studio is very picky with line terminations; it expects
3181  the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings.
3182  If you are getting a message such as "This makefile was not generated by
3183  Developer Studio etc.
3184  etc.
3185 \begin_inset Quotes srd
3186 \end_inset 
3187
3188  when opening the sdcc.dsw workspace or any of the *.dsp projects, then you
3189  need to convert the Unix style line endings to DOS style line endings.
3190  To do so you can use the 
3191 \begin_inset Quotes sld
3192 \end_inset 
3193
3194 unix2dos
3195 \begin_inset Quotes srd
3196 \end_inset 
3197
3198  utility freely available on the internet.
3199  Doug Hawkins reported in the sdcc-user list that this works:
3200 \newline 
3201
3202 \newline 
3203 C:
3204 \backslash 
3205 Programming
3206 \backslash 
3207 SDCC> unix2dos sdcc.dsw
3208 \newline 
3209 C:
3210 \backslash 
3211 Programming
3212 \backslash 
3213 SDCC> for /R %I in (*.dsp) do @unix2dos "%I"
3214 \newline 
3215
3216 \newline 
3217 In order to build SDCC with MSVC you need win32 executables of bison.exe,
3218  flex.exe, and gawk.exe.
3219  One good place to get them is 
3220 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
3221
3222 \end_inset 
3223
3224
3225 \newline 
3226
3227 \newline 
3228 Download the file UnxUtils
3229 \begin_inset LatexCommand \index{UnxUtils}
3230
3231 \end_inset 
3232
3233 .zip.
3234  Now you have to install the utilities and setup MSVC so it can locate the
3235  required programs.
3236  Here there are two alternatives (choose one!):
3237 \layout Enumerate
3238
3239 The easy way:
3240 \newline 
3241
3242 \newline 
3243 a) Extract UnxUtils.zip to your C:
3244 \backslash 
3245  hard disk PRESERVING the original paths, otherwise bison won't work.
3246  (If you are using WinZip make certain that 'Use folder names' is selected)
3247 \newline 
3248
3249 \newline 
3250 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3251  in 'Show directories for:' select 'Executable files', and in the directories
3252  window add a new path: 'C:
3253 \backslash 
3254 user
3255 \backslash 
3256 local
3257 \backslash 
3258 wbin', click ok.
3259 \newline 
3260
3261 \newline 
3262 (As a side effect, you get a bunch of Unix utilities that could be useful,
3263  such as diff and patch.)
3264 \layout Enumerate
3265
3266 A more compact way:
3267 \newline 
3268
3269 \newline 
3270 This one avoids extracting a bunch of files you may not use, but requires
3271  some extra work:
3272 \newline 
3273
3274 \newline 
3275 a) Create a directory were to put the tools needed, or use a directory already
3276  present.
3277  Say for example 'C:
3278 \backslash 
3279 util'.
3280 \newline 
3281
3282 \newline 
3283 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
3284  to such directory WITHOUT preserving the original paths.
3285  (If you are using WinZip make certain that 'Use folder names' is not selected)
3286 \newline 
3287
3288 \newline 
3289 c) Rename bison.exe to '_bison.exe'.
3290 \newline 
3291
3292 \newline 
3293 d) Create a batch file 'bison.bat' in 'C:
3294 \backslash 
3295 util
3296 \backslash 
3297 ' and add these lines: 
3298 \newline 
3299 \SpecialChar ~
3300 \SpecialChar ~
3301 set BISON_SIMPLE=C:
3302 \backslash 
3303 util
3304 \backslash 
3305 bison.simple 
3306 \newline 
3307 \SpecialChar ~
3308 \SpecialChar ~
3309 set BISON_HAIRY=C:
3310 \backslash 
3311 util
3312 \backslash 
3313 bison.hairy
3314 \newline 
3315 \SpecialChar ~
3316 \SpecialChar ~
3317 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
3318 \newline 
3319
3320 \newline 
3321 Steps 'c' and 'd' are needed because bison requires by default that the
3322  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
3323  '/usr/local/share/' I think.
3324  So it is necessary to tell bison where those files are located if they
3325  are not in such directory.
3326  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
3327 \newline 
3328
3329 \newline 
3330 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
3331  in 'Show directories for:' select 'Executable files', and in the directories
3332  window add a new path: 'c:
3333 \backslash 
3334 util', click ok.
3335  Note that you can use any other path instead of 'c:
3336 \backslash 
3337 util', even the path where the Visual C++ tools are, probably: 'C:
3338 \backslash 
3339 Program Files
3340 \backslash 
3341 Microsoft Visual Studio
3342 \backslash 
3343 Common
3344 \backslash 
3345 Tools'.
3346  So you don't have to execute step 'e' :)
3347 \layout Standard
3348
3349 That is it.
3350  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
3351  the executables from sdcc
3352 \backslash 
3353 bin_vc to sdcc
3354 \backslash 
3355 bin, and you can compile using SDCC.
3356 \layout Subsection
3357
3358 Building SDCC Using Borland
3359 \layout Enumerate
3360
3361 From the sdcc directory, run the command "make -f Makefile.bcc".
3362  This should regenerate all the .exe files in the bin directory except for
3363  sdcdb.exe (which currently doesn't build under Borland C++).
3364 \layout Enumerate
3365
3366 If you modify any source files and need to rebuild, be aware that the dependenci
3367 es may not be correctly calculated.
3368  The safest option is to delete all .obj files and run the build again.
3369  From a Cygwin BASH prompt, this can easily be done with the command (be
3370  sure you are in the sdcc directory):
3371 \newline 
3372
3373 \newline 
3374
3375 \family sans 
3376 \series bold 
3377 find .
3378  
3379 \backslash 
3380 ( -name '*.obj' -o -name '*.lib' -o -name '*.rul' 
3381 \backslash 
3382 ) -print -exec rm {} 
3383 \backslash 
3384 ;
3385 \family default 
3386 \series default 
3387
3388 \newline 
3389
3390 \newline 
3391 or on Windows NT/2000/XP from the command prompt with the command:
3392 \newline 
3393
3394 \family sans 
3395 \series bold 
3396
3397 \newline 
3398 del /s *.obj *.lib *.rul
3399 \family default 
3400 \series default 
3401  from the sdcc directory.
3402 \layout Subsection
3403
3404 Windows Install Using a Binary Package
3405 \begin_inset LatexCommand \label{sub:Windows-Install}
3406
3407 \end_inset 
3408
3409
3410 \layout Enumerate
3411
3412 Download the binary package from 
3413 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3414
3415 \end_inset 
3416
3417  and unpack it using your favorite unpacking tool (gunzip, WinZip, etc).
3418  This should unpack to a group of sub-directories.
3419  An example directory structure after unpacking the mingw32 package is:
3420  c:
3421 \backslash 
3422 sdcc
3423 \backslash 
3424 bin for the executables, c:
3425 \backslash 
3426 sdcc
3427 \backslash 
3428 include and c:
3429 \backslash 
3430 sdcc
3431 \backslash 
3432 lib for the include and libraries.
3433 \layout Enumerate
3434
3435 Adjust your environment variable PATH to include the location of the bin
3436  directory or start sdcc using the full path.
3437 \layout Section
3438
3439 Building the Documentation
3440 \layout Standard
3441
3442 If the necessary tools (LyX, LaTeX, LaTeX2HTML) are installed it is as easy
3443  as changing into the doc directory and typing 
3444 \family sans 
3445 \series bold 
3446
3447 \begin_inset Quotes srd
3448 \end_inset 
3449
3450 make
3451 \begin_inset Quotes srd
3452 \end_inset 
3453
3454
3455 \family default 
3456 \series default 
3457  there.
3458  You're invited to make changes and additions to this manual (sdcc/doc/sdccman.ly
3459 x).
3460  Using LyX 
3461 \begin_inset LatexCommand \url{www.lyx.org}
3462
3463 \end_inset 
3464
3465  as editor this is straightforward.
3466  Prebuilt documentation in html and pdf format is available from 
3467 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/snap.php}
3468
3469 \end_inset 
3470
3471 .
3472 \layout Section
3473
3474 Reading the Documentation
3475 \layout Standard
3476
3477 Currently reading the document in pdf format is recommended, as for unknown
3478  reason the hyperlinks are working there whereas in the html version they
3479  are not
3480 \begin_inset Foot
3481 collapsed false
3482
3483 \layout Standard
3484
3485 If you should know why please drop us a note
3486 \end_inset 
3487
3488 .
3489  You'll find the pdf version at 
3490 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net/doc/sdccman.pdf}
3491
3492 \end_inset 
3493
3494 .
3495 \newline 
3496 This documentation is in some aspects different from a commercial documentation:
3497  
3498 \layout Itemize
3499
3500 It tries to document SDCC for several processor architectures in one document
3501  (commercially these probably would be separate documents/products).
3502  This document
3503 \begin_inset LatexCommand \index{Status of documentation}
3504
3505 \end_inset 
3506
3507  currently matches SDCC for mcs51 and DS390 best and does give too few informati
3508 on about f.e.
3509  Z80, PIC14, PIC16 and HC08.
3510 \layout Itemize
3511
3512 There are many references pointing away from this documentation.
3513  Don't let this distract you.
3514  If there f.e.
3515  was a reference like 
3516 \begin_inset LatexCommand \url{www.opencores.org}
3517
3518 \end_inset 
3519
3520  together with a statement 
3521 \begin_inset Quotes sld
3522 \end_inset 
3523
3524 some processors which are targetted by SDCC can be implemented in a 
3525 \emph on 
3526 f
3527 \emph default 
3528 ield 
3529 \emph on 
3530 p
3531 \emph default 
3532 rogrammable 
3533 \emph on 
3534 g
3535 \emph default 
3536 ate 
3537 \emph on 
3538 a
3539 \emph default 
3540 rray
3541 \begin_inset LatexCommand \index{fpga (field programmable gate array)}
3542
3543 \end_inset 
3544
3545
3546 \begin_inset Quotes srd
3547 \end_inset 
3548
3549  we expect you to have a quick look there and come back.
3550  If you read this you are on the right track.
3551 \layout Itemize
3552
3553 Some sections attribute more space to problems, restrictions and warnings
3554  than to the solution.
3555 \layout Itemize
3556
3557 The installation section and the section about the debugger is intimidating.
3558 \layout Itemize
3559
3560 There are still lots of typos and there are more different writing styles
3561  than pictures.
3562 \layout Section
3563
3564 Testing the SDCC Compiler
3565 \begin_inset LatexCommand \label{sec:Testing-the-SDCC}
3566
3567 \end_inset 
3568
3569
3570 \layout Standard
3571
3572 The first thing you should do after installing your SDCC compiler is to
3573  see if it runs.
3574  Type 
3575 \family sans 
3576 \series bold 
3577 "sdcc -
3578 \begin_inset ERT
3579 status Collapsed
3580
3581 \layout Standard
3582
3583 \backslash 
3584 /
3585 \end_inset 
3586
3587 -version"
3588 \begin_inset LatexCommand \index{version}
3589
3590 \end_inset 
3591
3592
3593 \family default 
3594 \series default 
3595  at the prompt, and the program should run and tell you the version.
3596  If it doesn't run, or gives a message about not finding sdcc program, then
3597  you need to check over your installation.
3598  Make sure that the sdcc bin directory is in your executable search path
3599  defined by the PATH environment setting (
3600 \series medium 
3601 see 
3602 \series default 
3603 section 
3604 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3605
3606 \end_inset 
3607
3608 \SpecialChar ~
3609
3610 \series medium 
3611 Install trouble-shooting for suggestions
3612 \series default 
3613 ).
3614  Make sure that the sdcc program is in the bin folder, if not perhaps something
3615  did not install correctly.
3616 \newline 
3617
3618 \newline 
3619
3620 \series medium 
3621 SDCC 
3622 \series default 
3623 is commonly installed as described in section 
3624 \begin_inset Quotes sld
3625 \end_inset 
3626
3627 Install and search paths
3628 \begin_inset Quotes srd
3629 \end_inset 
3630
3631 .
3632 \newline 
3633
3634 \newline 
3635
3636 \series medium 
3637 Make sure the compiler works on a very simple example.
3638  Type in the following test.c program using your favorite 
3639 \series default 
3640 ASCII 
3641 \series medium 
3642 editor:
3643 \layout Verse
3644
3645
3646 \family typewriter 
3647 char test;
3648 \newline 
3649
3650 \newline 
3651 void main(void) {
3652 \newline 
3653 \SpecialChar ~
3654 \SpecialChar ~
3655 \SpecialChar ~
3656 \SpecialChar ~
3657 test=0;
3658 \newline 
3659 }
3660 \layout Standard
3661
3662
3663 \series medium 
3664 Compile this using the following command: 
3665 \family sans 
3666 \series bold 
3667 "sdcc -c test.c".
3668
3669 \family default 
3670 \series default 
3671  
3672 \series medium 
3673 If all goes well, the compiler will generate a test.asm and test.rel file.
3674  Congratulations, you've just compiled your first program with SDCC.
3675  We used the -c option to tell SDCC not to link the generated code, just
3676  to keep things simple for this step.
3677 \series default 
3678
3679 \newline 
3680
3681 \newline 
3682
3683 \series medium 
3684 The next step is to try it with the linker.
3685  Type in 
3686 \family sans 
3687 \series bold 
3688 "sdcc test.c
3689 \family default 
3690 \series default 
3691 "
3692 \series medium 
3693 .
3694  If all goes well the compiler will link with the libraries and produce
3695  a test.ihx output file.
3696  If this step fails
3697 \series default 
3698  
3699 \series medium 
3700 (no test.ihx, and the linker generates warnings), then the problem is most
3701  likely that 
3702 \series default 
3703 SDCC
3704 \series medium 
3705  cannot find the 
3706 \series default 
3707 /
3708 \series medium 
3709 usr/local/share/sdcc/lib directory
3710 \series default 
3711  
3712 \series medium 
3713 (see 
3714 \series default 
3715 section 
3716 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3717
3718 \end_inset 
3719
3720 \SpecialChar ~
3721
3722 \series medium 
3723 Install trouble-shooting for suggestions).
3724 \series default 
3725
3726 \newline 
3727
3728 \newline 
3729
3730 \series medium 
3731 The final test is to ensure 
3732 \series default 
3733 SDCC
3734 \series medium 
3735  can use the 
3736 \series default 
3737 standard
3738 \series medium 
3739  header files and libraries.
3740  Edit test.c and change it to the following:
3741 \layout Verse
3742
3743
3744 \family typewriter 
3745 #include <string.h>
3746 \newline 
3747
3748 \newline 
3749 char str1[10];
3750 \newline 
3751
3752 \newline 
3753 void main(void) {
3754 \newline 
3755 \SpecialChar ~
3756 \SpecialChar ~
3757 strcpy(str1, "testing");
3758 \newline 
3759 }
3760 \layout Standard
3761
3762
3763 \series medium 
3764 Compile this by typing 
3765 \family sans 
3766 \series bold 
3767 "sdcc test.c"
3768 \family default 
3769 \series medium 
3770 .
3771  This should generate a test.ihx output file, and it should give no warnings
3772  such as not finding the string.h file.
3773  If it cannot find the string.h file, then the problem is that 
3774 \series default 
3775 SDCC
3776 \series medium 
3777  cannot find the /usr/local/share/sdcc/include directory
3778 \series default 
3779  
3780 \series medium 
3781 (see the 
3782 \series default 
3783 section 
3784 \begin_inset LatexCommand \ref{sub:Install-Trouble-shooting}
3785
3786 \end_inset 
3787
3788 \SpecialChar ~
3789
3790 \series medium 
3791 Install trouble-shooting section for suggestions).
3792
3793 \series default 
3794  Use option 
3795 \series bold 
3796 -
3797 \begin_inset ERT
3798 status Collapsed
3799
3800 \layout Standard
3801
3802 \backslash 
3803 /
3804 \end_inset 
3805
3806 -print-search-dirs
3807 \series default 
3808
3809 \begin_inset LatexCommand \index{-\/-print-search-dirs}
3810
3811 \end_inset 
3812
3813  to find exactly where SDCC is looking for the include and lib files.
3814 \layout Section
3815
3816 Install Trouble-shooting
3817 \begin_inset LatexCommand \label{sub:Install-Trouble-shooting}
3818
3819 \end_inset 
3820
3821
3822 \begin_inset LatexCommand \index{Install trouble-shooting}
3823
3824 \end_inset 
3825
3826
3827 \layout Subsection
3828
3829 If SDCC does not build correctly
3830 \layout Standard
3831
3832 A thing to try is starting from scratch by unpacking the .tgz source package
3833  again in an empty directory.
3834  Configure it like:
3835 \newline 
3836
3837 \newline 
3838
3839 \family sans 
3840 \series bold 
3841 ./configure 2>&1 | tee configure.log
3842 \family default 
3843 \series default 
3844
3845 \newline 
3846
3847 \newline 
3848 and build it like:
3849 \newline 
3850
3851 \newline 
3852
3853 \family sans 
3854 \series bold 
3855 make 2>&1 | tee make.log
3856 \family default 
3857 \series default 
3858
3859 \newline 
3860
3861 \newline 
3862 If anything goes wrong, you can review the log files to locate the problem.
3863  Or a relevant part of this can be attached to an email that could be helpful
3864  when requesting help from the mailing list.
3865 \layout Subsection
3866
3867 What the 
3868 \begin_inset Quotes sld
3869 \end_inset 
3870
3871 ./configure
3872 \begin_inset Quotes srd
3873 \end_inset 
3874
3875  does
3876 \layout Standard
3877
3878 The 
3879 \begin_inset Quotes sld
3880 \end_inset 
3881
3882 ./configure
3883 \begin_inset Quotes srd
3884 \end_inset 
3885
3886  command is a script that analyzes your system and performs some configuration
3887  to ensure the source package compiles on your system.
3888  It will take a few minutes to run, and will compile a few tests to determine
3889  what compiler features are installed.
3890 \layout Subsection
3891
3892 What the 
3893 \begin_inset Quotes sld
3894 \end_inset 
3895
3896 make
3897 \begin_inset Quotes srd
3898 \end_inset 
3899
3900  does
3901 \layout Standard
3902
3903 This runs the GNU make tool, which automatically compiles all the source
3904  packages into the final installed binary executables.
3905 \layout Subsection
3906
3907 What the 
3908 \begin_inset Quotes sld
3909 \end_inset 
3910
3911 make install
3912 \begin_inset Quotes erd
3913 \end_inset 
3914
3915  command does.
3916 \layout Standard
3917
3918 This will install the compiler, other executables libraries and include
3919  files into the appropriate directories.
3920  See sections 
3921 \begin_inset LatexCommand \ref{sub:Install-paths}
3922
3923 \end_inset 
3924
3925 ,\SpecialChar ~
3926
3927 \begin_inset LatexCommand \ref{sub:Search-Paths}
3928
3929 \end_inset 
3930
3931 \SpecialChar ~
3932 about install and search paths.
3933 \newline 
3934 On most systems you will need super-user privileges to do this.
3935 \layout Section
3936
3937 Components of SDCC
3938 \layout Standard
3939
3940 SDCC is not just a compiler, but a collection of tools by various developers.
3941  These include linkers, assemblers, simulators and other components.
3942  Here is a summary of some of the components.
3943  Note that the included simulator and assembler have separate documentation
3944  which you can find in the source package in their respective directories.
3945  As SDCC grows to include support for other processors, other packages from
3946  various developers are included and may have their own sets of documentation.
3947 \newline 
3948
3949 \newline 
3950 You might want to look at the files which are installed in <installdir>.
3951  At the time of this writing, we find the following programs for gcc-builds:
3952 \newline 
3953  
3954 \newline 
3955 In <installdir>/bin:
3956 \layout Itemize
3957
3958 sdcc - The compiler.
3959 \layout Itemize
3960
3961 sdcpp - The C preprocessor.
3962 \layout Itemize
3963
3964 asx8051 - The assembler for 8051 type processors.
3965 \layout Itemize
3966
3967 as-z80
3968 \series bold 
3969
3970 \series default 
3971 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
3972 \layout Itemize
3973
3974 aslink -The linker for 8051 type processors.
3975 \layout Itemize
3976
3977 link-z80
3978 \series bold 
3979
3980 \series default 
3981 link-gbz80 - The Z80 and GameBoy Z80 linkers.
3982 \layout Itemize
3983
3984 s51 - The ucSim 8051 simulator.
3985 \layout Itemize
3986
3987 sdcdb - The source debugger.
3988 \layout Itemize
3989
3990 packihx - A tool to pack (compress) Intel hex files.
3991 \layout Standard
3992
3993 In <installdir>/share/sdcc/include
3994 \layout Itemize
3995
3996 the include files
3997 \layout Standard
3998
3999 In <installdir>/share/sdcc/lib
4000 \layout Itemize
4001
4002 the subdirs src and small, large, z80, gbz80 and ds390 with the precompiled
4003  relocatables.
4004 \layout Standard
4005
4006 In <installdir>/share/sdcc/doc
4007 \layout Itemize
4008
4009 the documentation
4010 \layout Standard
4011
4012 As development for other processors proceeds, this list will expand to include
4013  executables to support processors like AVR, PIC, etc.
4014 \layout Subsection
4015
4016 sdcc - The Compiler
4017 \layout Standard
4018
4019 This is the actual compiler, it in turn uses the c-preprocessor and invokes
4020  the assembler and linkage editor.
4021 \layout Subsection
4022
4023 sdcpp - The C-Preprocessor
4024 \layout Standard
4025
4026 The preprocessor
4027 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
4028
4029 \end_inset 
4030
4031  is a modified version of the GNU preprocessor.
4032  The C preprocessor is used to pull in #include sources, process #ifdef
4033  statements, #defines and so on.
4034 \layout Subsection
4035
4036 as
4037 \emph on 
4038 xxxx
4039 \emph default 
4040 , aslink, link-
4041 \emph on 
4042 xxx
4043 \emph default 
4044  - The Assemblers and Linkage Editors
4045 \layout Standard
4046
4047 This is retargettable assembler & linkage editor, it was developed by Alan
4048  Baldwin.
4049  John Hartman created the version for 8051, and I (Sandeep) have made some
4050  enhancements and bug fixes for it to work properly with SDCC.
4051 \layout Subsection
4052
4053 s51 - The Simulator
4054 \layout Standard
4055
4056 S51
4057 \begin_inset LatexCommand \index{s51}
4058
4059 \end_inset 
4060
4061  is a freeware, opensource simulator developed by Daniel Drotos (
4062 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
4063
4064 \end_inset 
4065
4066 ).
4067  The simulator is built as part of the build process.
4068  For more information visit Daniel's web site at: 
4069 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
4070
4071 \end_inset 
4072
4073 .
4074  It currently supports the core mcs51, the Dallas DS80C390 and the Phillips
4075  XA51 family.
4076 \layout Subsection
4077
4078 sdcdb - Source Level Debugger
4079 \layout Standard
4080
4081 Sdcdb
4082 \begin_inset LatexCommand \index{sdcdb (debugger)}
4083
4084 \end_inset 
4085
4086  is the companion source level debugger.
4087  More about sdcdb in section 
4088 \begin_inset LatexCommand \ref{cha:Debugging-with-SDCDB}
4089
4090 \end_inset 
4091
4092 .
4093  The current version of the debugger uses Daniel's Simulator S51
4094 \begin_inset LatexCommand \index{s51}
4095
4096 \end_inset 
4097
4098 , but can be easily changed to use other simulators.
4099  
4100 \layout Chapter
4101
4102 Using SDCC
4103 \layout Section
4104
4105 Compiling
4106 \layout Subsection
4107
4108 Single Source File Projects
4109 \layout Standard
4110
4111 For single source file 8051 projects the process is very simple.
4112  Compile your programs with the following command 
4113 \family sans 
4114 \series bold 
4115 "sdcc sourcefile.c".
4116
4117 \family default 
4118 \series default 
4119  This will compile, assemble and link your source file.
4120  Output files are as follows:
4121 \layout Itemize
4122
4123 sourcefile.asm
4124 \begin_inset LatexCommand \index{<file>.asm}
4125
4126 \end_inset 
4127
4128  - Assembler source
4129 \begin_inset LatexCommand \index{Assembler source}
4130
4131 \end_inset 
4132
4133  file created by the compiler
4134 \layout Itemize
4135
4136 sourcefile.lst
4137 \begin_inset LatexCommand \index{<file>.lst}
4138
4139 \end_inset 
4140
4141  - Assembler listing
4142 \begin_inset LatexCommand \index{Assembler listing}
4143
4144 \end_inset 
4145
4146  file created by the Assembler
4147 \layout Itemize
4148
4149 sourcefile.rst
4150 \begin_inset LatexCommand \index{<file>.rst}
4151
4152 \end_inset 
4153
4154  - Assembler listing
4155 \begin_inset LatexCommand \index{Assembler listing}
4156
4157 \end_inset 
4158
4159  file updated with linkedit information, created by linkage editor
4160 \layout Itemize
4161
4162 sourcefile.sym
4163 \begin_inset LatexCommand \index{<file>.sym}
4164
4165 \end_inset 
4166
4167  - symbol listing
4168 \begin_inset LatexCommand \index{Symbol listing}
4169
4170 \end_inset 
4171
4172  for the sourcefile, created by the assembler
4173 \layout Itemize
4174
4175 sourcefile.rel
4176 \begin_inset LatexCommand \index{<file>.rel}
4177
4178 \end_inset 
4179
4180  or sourcefile.o
4181 \begin_inset LatexCommand \index{<file>.o}
4182
4183 \end_inset 
4184
4185  - Object file
4186 \begin_inset LatexCommand \index{Object file}
4187
4188 \end_inset 
4189
4190  created by the assembler, input to Linkage editor
4191 \layout Itemize
4192
4193 sourcefile.map
4194 \begin_inset LatexCommand \index{<file>.map}
4195
4196 \end_inset 
4197
4198  - The memory map
4199 \begin_inset LatexCommand \index{Memory map}
4200
4201 \end_inset 
4202
4203  for the load module, created by the Linker
4204 \layout Itemize
4205
4206 sourcefile.mem
4207 \begin_inset LatexCommand \index{<file>.mem}
4208
4209 \end_inset 
4210
4211  - A file with a summary of the memory usage
4212 \layout Itemize
4213
4214 sourcefile.ihx
4215 \begin_inset LatexCommand \index{<file>.ihx}
4216
4217 \end_inset 
4218
4219  - The load module in Intel hex format
4220 \begin_inset LatexCommand \index{Intel hex format}
4221
4222 \end_inset 
4223
4224  (you can select the Motorola S19 format
4225 \begin_inset LatexCommand \index{Motorola S19 format}
4226
4227 \end_inset 
4228
4229  with -
4230 \begin_inset ERT
4231 status Collapsed
4232
4233 \layout Standard
4234
4235 \backslash 
4236 /
4237 \end_inset 
4238
4239 -out-fmt-s19
4240 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
4241
4242 \end_inset 
4243
4244 .
4245  If you need another format you might want to use 
4246 \family sans 
4247 \shape italic 
4248 objdump
4249 \family default 
4250 \shape default 
4251
4252 \begin_inset LatexCommand \index{objdump (tool)}
4253
4254 \end_inset 
4255
4256  or
4257 \family sans 
4258 \shape italic 
4259  srecord
4260 \family default 
4261 \shape default 
4262
4263 \begin_inset LatexCommand \index{srecord (tool)}
4264
4265 \end_inset 
4266
4267 ).
4268  Both formats are documented in the documentation of srecord
4269 \begin_inset LatexCommand \index{srecord (tool)}
4270
4271 \end_inset 
4272
4273
4274 \layout Itemize
4275
4276 sourcefile.adb
4277 \begin_inset LatexCommand \index{<file>.adb}
4278
4279 \end_inset 
4280
4281  - An intermediate file containing debug information needed to create the
4282  .cdb file (with -
4283 \begin_inset ERT
4284 status Open
4285
4286 \layout Standard
4287
4288 \backslash 
4289 /
4290 \end_inset 
4291
4292 -debug
4293 \begin_inset LatexCommand \index{-\/-debug}
4294
4295 \end_inset 
4296
4297
4298 \layout Itemize
4299
4300 sourcefile.cdb
4301 \begin_inset LatexCommand \index{<file>.cdb}
4302
4303 \end_inset 
4304
4305  - An optional file (with -
4306 \begin_inset ERT
4307 status Collapsed
4308
4309 \layout Standard
4310
4311 \backslash 
4312 /
4313 \end_inset 
4314
4315 -debug) containing debug information.
4316  The format is documented in cdbfileformat.pdf.
4317 \layout Itemize
4318
4319 sourcefile.
4320  - (no extension)
4321 \begin_inset LatexCommand \index{<file> (no extension)}
4322
4323 \end_inset 
4324
4325  An optional AOMF or AOMF51
4326 \begin_inset LatexCommand \index{AOMF, AOMF51}
4327
4328 \end_inset 
4329
4330  file containing debug information (generated with option -
4331 \begin_inset ERT
4332 status Collapsed
4333
4334 \layout Standard
4335
4336 \backslash 
4337 /
4338 \end_inset 
4339
4340 -debug).
4341  The (Intel)
4342 \emph on 
4343  a
4344 \emph default 
4345 bsolute 
4346 \emph on 
4347 o
4348 \emph default 
4349 bject 
4350 \emph on 
4351 m
4352 \emph default 
4353 odule 
4354 \emph on 
4355 f
4356 \emph default 
4357 ormat is commonly used by third party tools (debuggers
4358 \begin_inset LatexCommand \index{Debugger}
4359
4360 \end_inset 
4361
4362 , simulators, emulators)
4363 \layout Itemize
4364
4365 sourcefile.dump*
4366 \begin_inset LatexCommand \index{<file>.dump*}
4367
4368 \end_inset 
4369
4370  - Dump file to debug the compiler it self (generated with option -
4371 \begin_inset ERT
4372 status Collapsed
4373
4374 \layout Standard
4375
4376 \backslash 
4377 /
4378 \end_inset 
4379
4380 -dumpall) (see section 
4381 \begin_inset LatexCommand \ref{sub:Intermediate-Dump-Options}
4382
4383 \end_inset 
4384
4385 \SpecialChar ~
4386  and section 
4387 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
4388
4389 \end_inset 
4390
4391 \SpecialChar ~
4392
4393 \begin_inset Quotes sld
4394 \end_inset 
4395
4396 Anatomy of the compiler
4397 \begin_inset Quotes srd
4398 \end_inset 
4399
4400 ).
4401 \layout Subsection
4402
4403 Projects with Multiple Source Files
4404 \layout Standard
4405
4406 SDCC can compile only ONE file at a time.
4407  Let us for example assume that you have a project containing the following
4408  files:
4409 \newline 
4410
4411 \newline 
4412 foo1.c (contains some functions)
4413 \newline 
4414 foo2.c (contains some more functions)
4415 \newline 
4416 foomain.c (contains more functions and the function main)
4417 \newline 
4418
4419 \size footnotesize 
4420
4421 \newline 
4422
4423 \size default 
4424 The first two files will need to be compiled separately with the commands:
4425 \size footnotesize 
4426  
4427 \size default 
4428
4429 \newline 
4430
4431 \newline 
4432
4433 \family sans 
4434 \series bold 
4435 sdcc\SpecialChar ~
4436 -c\SpecialChar ~
4437 foo1.c
4438 \family default 
4439 \series default 
4440 \size footnotesize 
4441
4442 \newline 
4443
4444 \family sans 
4445 \series bold 
4446 \size default 
4447 sdcc\SpecialChar ~
4448 -c\SpecialChar ~
4449 foo2.c
4450 \family default 
4451 \series default 
4452
4453 \newline 
4454
4455 \newline 
4456 Then compile the source file containing the 
4457 \emph on 
4458 main()
4459 \emph default 
4460  function and link
4461 \begin_inset LatexCommand \index{Linker}
4462
4463 \end_inset 
4464
4465  the files together with the following command: 
4466 \newline 
4467
4468 \newline 
4469
4470 \family sans 
4471 \series bold 
4472 sdcc\SpecialChar ~
4473 foomain.c\SpecialChar ~
4474 foo1.rel\SpecialChar ~
4475 foo2.rel
4476 \family default 
4477 \series default 
4478
4479 \begin_inset LatexCommand \index{<file>.rel}
4480
4481 \end_inset 
4482
4483
4484 \newline 
4485
4486 \newline 
4487 Alternatively, 
4488 \emph on 
4489 foomain.c 
4490 \emph default 
4491 can be separately compiled as well: 
4492 \family sans 
4493 \series bold 
4494
4495 \newline 
4496
4497 \newline 
4498 sdcc\SpecialChar ~
4499 -c\SpecialChar ~
4500 foomain.c
4501 \newline 
4502 sdcc foomain.rel foo1.rel foo2.rel
4503 \newline 
4504
4505 \newline 
4506
4507 \family default 
4508 \series default 
4509 The file containing the 
4510 \emph on 
4511 main()
4512 \emph default 
4513  function
4514 \emph on 
4515  
4516 \emph default 
4517 \noun on 
4518 must
4519 \noun default 
4520  be the 
4521 \noun on 
4522 first
4523 \noun default 
4524  file specified in the command line, since the linkage editor processes
4525  file in the order they are presented to it.
4526  The linker is invoked from SDCC using a script file with extension .lnk
4527 \begin_inset LatexCommand \index{<file>.lnk}
4528
4529 \end_inset 
4530
4531 .
4532  You can view this file to troubleshoot linking problems such as those arising
4533  from missing libraries.
4534 \layout Subsection
4535
4536 Projects with Additional Libraries
4537 \begin_inset LatexCommand \index{Libraries}
4538
4539 \end_inset 
4540
4541
4542 \layout Standard
4543
4544 Some reusable routines may be compiled into a library, see the documentation
4545  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
4546  for how to create a 
4547 \emph on 
4548 .lib
4549 \begin_inset LatexCommand \index{<file>.lib}
4550
4551 \end_inset 
4552
4553
4554 \emph default 
4555  library file.
4556  Libraries created in this manner can be included in the command line.
4557  Make sure you include the -L <library-path> option to tell the linker where
4558  to look for these files if they are not in the current directory.
4559  Here is an example, assuming you have the source file 
4560 \emph on 
4561 foomain.c
4562 \emph default 
4563  and a library
4564 \emph on 
4565  foolib.lib
4566 \emph default 
4567  in the directory 
4568 \emph on 
4569 mylib
4570 \emph default 
4571  (if that is not the same as your current project):
4572 \newline 
4573
4574 \newline 
4575
4576 \family sans 
4577 \series bold 
4578 sdcc foomain.c foolib.lib -L mylib
4579 \newline 
4580
4581 \newline 
4582
4583 \family default 
4584 \series default 
4585 Note here that
4586 \emph on 
4587  mylib
4588 \emph default 
4589  must be an absolute path name.
4590 \newline 
4591
4592 \newline 
4593 The most efficient way to use libraries is to keep separate modules in separate
4594  source files.
4595  The lib file now should name all the modules.rel
4596 \begin_inset LatexCommand \index{<file>.rel}
4597
4598 \end_inset 
4599
4600  files.
4601  For an example see the standard library file 
4602 \emph on 
4603 libsdcc.lib
4604 \emph default 
4605  in the directory <installdir>/share/lib/small.
4606 \layout Subsection
4607
4608 Using sdcclib to Create and Manage Libraries
4609 \begin_inset LatexCommand \index{sdcclib}
4610
4611 \end_inset 
4612
4613
4614 \layout Standard
4615
4616 Alternatively, instead of having a .rel file for each entry on the library
4617  file as described in the preceding section, sdcclib can be used to embed
4618  all the modules belonging to such library in the library file itself.
4619  This results in a larger library file, but it greatly reduces the number
4620  of disk files accessed by the linker.
4621   Additionally, the packed library file contains an index of all include
4622  modules and symbols that significantly speeds up the linking process.
4623  To display a list of options supported by sdcclib type:
4624 \newline 
4625
4626 \layout Standard
4627
4628
4629 \family sans 
4630 \series bold 
4631 sdcclib -?
4632 \begin_inset LatexCommand \index{sdcclib}
4633
4634 \end_inset 
4635
4636
4637 \newline 
4638
4639 \newline 
4640
4641 \family default 
4642 \series default 
4643 To create a new library file, start by compiling all the required modules.
4644  For example:
4645 \newline 
4646
4647 \layout Standard
4648
4649
4650 \family sans 
4651 \series bold 
4652 sdcc -c _divsint.c
4653 \layout Standard
4654
4655
4656 \family sans 
4657 \series bold 
4658 sdcc -c _divuint.c
4659 \layout Standard
4660
4661
4662 \family sans 
4663 \series bold 
4664 sdcc -c _modsint.c
4665 \layout Standard
4666
4667
4668 \family sans 
4669 \series bold 
4670 sdcc -c _moduint.c
4671 \layout Standard
4672
4673
4674 \family sans 
4675 \series bold 
4676 sdcc -c _mulint.c
4677 \newline 
4678
4679 \layout Standard
4680
4681 This will create files _divsint.rel, _divuint.rel, _modsint.rel, _moduint.rel,
4682  and _mulint.rel.
4683  The next step is to add the .rel files to the library file:
4684 \newline 
4685
4686 \layout Standard
4687
4688
4689 \family sans 
4690 \series bold 
4691 sdcclib libint.lib _divsint.rel
4692 \family default 
4693
4694 \begin_inset LatexCommand \index{sdcclib}
4695
4696 \end_inset 
4697
4698
4699 \layout Standard
4700
4701
4702 \family sans 
4703 \series bold 
4704 sdcclib libint.lib _divuint.rel
4705 \layout Standard
4706
4707
4708 \family sans 
4709 \series bold 
4710 sdcclib libint.lib _modsint.rel
4711 \layout Standard
4712
4713
4714 \family sans 
4715 \series bold 
4716 sdcclib libint.lib _moduint.rel
4717 \layout Standard
4718
4719
4720 \family sans 
4721 \series bold 
4722 sdcclib libint.lib _mulint.rel
4723 \series default 
4724
4725 \newline 
4726
4727 \layout Standard
4728
4729 If the file already exists in the library, it will be replaced.
4730  To see what modules and symbols are included in the library, options -s
4731  and -m are available.
4732  For example:
4733 \newline 
4734
4735 \newline 
4736
4737 \family sans 
4738 \series bold 
4739 sdcclib -s libint.lib
4740 \family default 
4741
4742 \begin_inset LatexCommand \index{sdcclib}
4743
4744 \end_inset 
4745
4746
4747 \newline 
4748
4749 \family typewriter 
4750 \series default 
4751 _divsint.rel:
4752 \layout Standard
4753
4754
4755 \family typewriter 
4756 __divsint_a_1_1
4757 \layout Standard
4758
4759
4760 \family typewriter 
4761 __divsint_PARM_2
4762 \layout Standard
4763
4764
4765 \family typewriter 
4766 __divsint
4767 \newline 
4768 _divuint.rel:
4769 \layout Standard
4770
4771
4772 \family typewriter 
4773 __divuint_a_1_1
4774 \layout Standard
4775
4776
4777 \family typewriter 
4778 __divuint_PARM_2
4779 \layout Standard
4780
4781
4782 \family typewriter 
4783 __divuint_reste_1_1
4784 \layout Standard
4785
4786
4787 \family typewriter 
4788 __divuint_count_1_1
4789 \layout Standard
4790
4791
4792 \family typewriter 
4793 __divuint
4794 \newline 
4795 _modsint.rel:
4796 \layout Standard
4797
4798
4799 \family typewriter 
4800 __modsint_a_1_1
4801 \layout Standard
4802
4803
4804 \family typewriter 
4805 __modsint_PARM_2
4806 \layout Standard
4807
4808
4809 \family typewriter 
4810 __modsint
4811 \newline 
4812 _moduint.rel:
4813 \layout Standard
4814
4815
4816 \family typewriter 
4817 __moduint_a_1_1
4818 \layout Standard
4819
4820
4821 \family typewriter 
4822 __moduint_PARM_2
4823 \layout Standard
4824
4825
4826 \family typewriter 
4827 __moduint_count_1_1
4828 \layout Standard
4829
4830
4831 \family typewriter 
4832 __moduint
4833 \newline 
4834 _mulint.rel:
4835 \layout Standard
4836
4837
4838 \family typewriter 
4839 __mulint_PARM_2
4840 \layout Standard
4841
4842
4843 \family typewriter 
4844 __mulint
4845 \family default 
4846 \series bold 
4847
4848 \newline 
4849
4850 \layout Standard
4851
4852 If the source files are compiled using -
4853 \begin_inset ERT
4854 status Open
4855
4856 \layout Standard
4857
4858 \backslash 
4859 /
4860 \end_inset 
4861
4862 -debug
4863 \begin_inset LatexCommand \index{-\/-debug}
4864
4865 \end_inset 
4866
4867 , the corresponding debug information file .adb will be include in the library
4868  file as well.
4869  The library files created with sdcclib are plain text files, so they can
4870  be viewed with a text editor.
4871  It is not recomended to modify a library file created with sdcclib using
4872  a text editor, as there are file indexes numbers located accross the file
4873  used by the linker to quickly locate the required module to link.
4874  Once a .rel file (as well as a .adb file) is added to a library using sdcclib,
4875  it can be safely deleted, since all the information required for linking
4876  is embedded in the library file itself.
4877  Library files created using sdcclib are used as described in the preceding
4878  sections.
4879 \layout Section
4880
4881 Command Line Options
4882 \begin_inset LatexCommand \index{Command Line Options}
4883
4884 \end_inset 
4885
4886
4887 \layout Subsection
4888
4889 Processor Selection Options
4890 \begin_inset LatexCommand \index{Options processor selection}
4891
4892 \end_inset 
4893
4894
4895 \begin_inset LatexCommand \index{Processor selection options}
4896
4897 \end_inset 
4898
4899
4900 \layout List
4901 \labelwidthstring 00.00.0000
4902
4903
4904 \series bold 
4905 -mmcs51
4906 \begin_inset LatexCommand \index{-mmcs51}
4907
4908 \end_inset 
4909
4910
4911 \series default 
4912  Generate code for the Intel MCS51
4913 \begin_inset LatexCommand \index{MCS51}
4914
4915 \end_inset 
4916
4917  family of processors.
4918  This is the default processor target.
4919 \layout List
4920 \labelwidthstring 00.00.0000
4921
4922
4923 \series bold 
4924 -mds390
4925 \begin_inset LatexCommand \index{-mds390}
4926
4927 \end_inset 
4928
4929
4930 \series default 
4931  Generate code for the Dallas DS80C390
4932 \begin_inset LatexCommand \index{DS80C390}
4933
4934 \end_inset 
4935
4936  processor.
4937 \layout List
4938 \labelwidthstring 00.00.0000
4939
4940
4941 \series bold 
4942 -mds400
4943 \begin_inset LatexCommand \index{-mds400}
4944
4945 \end_inset 
4946
4947
4948 \series default 
4949  Generate code for the Dallas DS80C400
4950 \begin_inset LatexCommand \index{DS80C400}
4951
4952 \end_inset 
4953
4954  processor.
4955 \layout List
4956 \labelwidthstring 00.00.0000
4957
4958
4959 \series bold 
4960 -mhc08
4961 \begin_inset LatexCommand \index{-mhc08}
4962
4963 \end_inset 
4964
4965
4966 \series default 
4967  Generate code for the Motorola HC08
4968 \begin_inset LatexCommand \index{HC08}
4969
4970 \end_inset 
4971
4972  family of processors (added Oct 2003).
4973 \layout List
4974 \labelwidthstring 00.00.0000
4975
4976
4977 \series bold 
4978 -mz80
4979 \begin_inset LatexCommand \index{-mz80}
4980
4981 \end_inset 
4982
4983
4984 \series default 
4985  Generate code for the Zilog Z80
4986 \begin_inset LatexCommand \index{Z80}
4987
4988 \end_inset 
4989
4990  family of processors.
4991 \layout List
4992 \labelwidthstring 00.00.0000
4993
4994
4995 \series bold 
4996 -mgbz80
4997 \begin_inset LatexCommand \index{-mgbz80}
4998
4999 \end_inset 
5000
5001
5002 \series default 
5003  Generate code for the GameBoy Z80
5004 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
5005
5006 \end_inset 
5007
5008  processor (Not actively maintained).
5009 \layout List
5010 \labelwidthstring 00.00.0000
5011
5012
5013 \series bold 
5014 -mavr
5015 \begin_inset LatexCommand \index{-mavr}
5016
5017 \end_inset 
5018
5019
5020 \series default 
5021  Generate code for the Atmel AVR
5022 \begin_inset LatexCommand \index{AVR}
5023
5024 \end_inset 
5025
5026  processor (In development, not complete).
5027  AVR users should probably have a look at avr-gcc 
5028 \begin_inset LatexCommand \url{ http://savannah.nongnu.org/download/avr-libc/snapshots/}
5029
5030 \end_inset 
5031
5032  or winavr 
5033 \begin_inset LatexCommand \url{http://winavr.sourceforge.net}
5034
5035 \end_inset 
5036
5037 .
5038 \layout Comment
5039
5040 I think it is fair to direct users there for now.
5041  Open source is also about avoiding unnecessary work .
5042  But I didn't find the 'official' link.
5043 \layout List
5044 \labelwidthstring 00.00.0000
5045
5046
5047 \series bold 
5048 -mpic14
5049 \begin_inset LatexCommand \index{-mpic14}
5050
5051 \end_inset 
5052
5053
5054 \series default 
5055  Generate code for the Microchip PIC 14
5056 \begin_inset LatexCommand \index{PIC14}
5057
5058 \end_inset 
5059
5060 -bit processors (p16f84 and variants.
5061  In development, not complete).
5062 \layout Comment
5063
5064 p16f627 p16f628 p16f84 p16f873 p16f877?
5065 \layout List
5066 \labelwidthstring 00.00.0000
5067
5068
5069 \series bold 
5070 -mpic16
5071 \begin_inset LatexCommand \index{-mpic16}
5072
5073 \end_inset 
5074
5075
5076 \series default 
5077  Generate code for the Microchip PIC 16
5078 \begin_inset LatexCommand \index{PIC16}
5079
5080 \end_inset 
5081
5082 -bit processors (p18f452 and variants.
5083  In development, not complete).
5084 \layout List
5085 \labelwidthstring 00.00.0000
5086
5087
5088 \series bold 
5089 -mtlcs900h
5090 \series default 
5091  Generate code for the Toshiba TLCS-900H
5092 \begin_inset LatexCommand \index{TLCS-900H}
5093
5094 \end_inset 
5095
5096  processor (Not maintained, not complete).
5097 \layout List
5098 \labelwidthstring 00.00.0000
5099
5100
5101 \series bold 
5102 -mxa51
5103 \begin_inset LatexCommand \index{-mxa51}
5104
5105 \end_inset 
5106
5107
5108 \series default 
5109  Generate code for the Phillips XA51
5110 \begin_inset LatexCommand \index{XA51}
5111
5112 \end_inset 
5113
5114  processor (Not maintained, not complete).
5115 \layout Subsection
5116
5117 Preprocessor Options
5118 \begin_inset LatexCommand \index{Options preprocessor}
5119
5120 \end_inset 
5121
5122
5123 \begin_inset LatexCommand \index{Preprocessor options}
5124
5125 \end_inset 
5126
5127
5128 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5129
5130 \end_inset 
5131
5132
5133 \layout List
5134 \labelwidthstring 00.00.0000
5135
5136
5137 \series bold 
5138 -I<path>
5139 \begin_inset LatexCommand \index{-I<path>}
5140
5141 \end_inset 
5142
5143
5144 \series default 
5145  The additional location where the pre processor will look for <..h> or 
5146 \begin_inset Quotes eld
5147 \end_inset 
5148
5149 ..h
5150 \begin_inset Quotes erd
5151 \end_inset 
5152
5153  files.
5154 \layout List
5155 \labelwidthstring 00.00.0000
5156
5157
5158 \series bold 
5159 -D<macro[=value]>
5160 \begin_inset LatexCommand \index{-D<macro[=value]>}
5161
5162 \end_inset 
5163
5164
5165 \series default 
5166  Command line definition of macros.
5167  Passed to the preprocessor.
5168 \layout List
5169 \labelwidthstring 00.00.0000
5170
5171
5172 \series bold 
5173 -M
5174 \begin_inset LatexCommand \index{-M}
5175
5176 \end_inset 
5177
5178
5179 \series default 
5180  Tell the preprocessor to output a rule suitable for make describing the
5181  dependencies of each object file.
5182  For each source file, the preprocessor outputs one make-rule whose target
5183  is the object file name for that source file and whose dependencies are
5184  all the files `#include'd in it.
5185  This rule may be a single line or may be continued with `
5186 \backslash 
5187 '-newline if it is long.
5188  The list of rules is printed on standard output instead of the preprocessed
5189  C program.
5190  `-M' implies `-E
5191 \begin_inset LatexCommand \index{-E}
5192
5193 \end_inset 
5194
5195 '.
5196 \layout List
5197 \labelwidthstring 00.00.0000
5198
5199
5200 \series bold 
5201 -C
5202 \begin_inset LatexCommand \index{-C}
5203
5204 \end_inset 
5205
5206
5207 \series default 
5208  Tell the preprocessor not to discard comments.
5209  Used with the `-E' option.
5210 \layout List
5211 \labelwidthstring 00.00.0000
5212
5213
5214 \series bold 
5215 -MM
5216 \begin_inset LatexCommand \index{-MM}
5217
5218 \end_inset 
5219
5220
5221 \size large 
5222 \bar under 
5223  
5224 \series default 
5225 \size default 
5226 \bar default 
5227 Like `-M' but the output mentions only the user header files included with
5228  `#include 
5229 \begin_inset Quotes eld
5230 \end_inset 
5231
5232 file"'.
5233  System header files included with `#include <file>' are omitted.
5234 \layout List
5235 \labelwidthstring 00.00.0000
5236
5237
5238 \series bold 
5239 -Aquestion(answer)
5240 \begin_inset LatexCommand \index{-Aquestion(answer)}
5241
5242 \end_inset 
5243
5244
5245 \series default 
5246  Assert the answer answer for question, in case it is tested with a preprocessor
5247  conditional such as `#if #question(answer)'.
5248  `-A-' disables the standard assertions that normally describe the target
5249  machine.
5250 \layout List
5251 \labelwidthstring 00.00.0000
5252
5253
5254 \series bold 
5255 -Umacro
5256 \begin_inset LatexCommand \index{-Umacro}
5257
5258 \end_inset 
5259
5260
5261 \series default 
5262  Undefine macro macro.
5263  `-U' options are evaluated after all `-D' options, but before any `-include'
5264  and `-imacros' options.
5265 \layout List
5266 \labelwidthstring 00.00.0000
5267
5268
5269 \series bold 
5270 -dM
5271 \begin_inset LatexCommand \index{-dM}
5272
5273 \end_inset 
5274
5275
5276 \series default 
5277  Tell the preprocessor to output only a list of the macro definitions that
5278  are in effect at the end of preprocessing.
5279  Used with the `-E' option.
5280 \layout List
5281 \labelwidthstring 00.00.0000
5282
5283
5284 \series bold 
5285 -dD
5286 \begin_inset LatexCommand \index{-dD}
5287
5288 \end_inset 
5289
5290
5291 \series default 
5292  Tell the preprocessor to pass all macro definitions into the output, in
5293  their proper sequence in the rest of the output.
5294 \layout List
5295 \labelwidthstring 00.00.0000
5296
5297
5298 \series bold 
5299 -dN
5300 \begin_inset LatexCommand \index{-dN}
5301
5302 \end_inset 
5303
5304
5305 \size large 
5306 \bar under 
5307  
5308 \series default 
5309 \size default 
5310 \bar default 
5311 Like `-dD' except that the macro arguments and contents are omitted.
5312  Only `#define name' is included in the output.
5313 \layout List
5314 \labelwidthstring 00.00.0000
5315
5316
5317 \series bold 
5318 -Wp\SpecialChar ~
5319 preprocessorOption[,preprocessorOption]
5320 \series default 
5321
5322 \begin_inset LatexCommand \index{-Wp preprocessorOption[,preprocessorOption]}
5323
5324 \end_inset 
5325
5326 ...
5327  Pass the preprocessorOption to the preprocessor 
5328 \family typewriter 
5329 sdcpp
5330 \family default 
5331
5332 \begin_inset LatexCommand \index{sdcpp (preprocessor)}
5333
5334 \end_inset 
5335
5336 .
5337  SDCC uses an adapted version of the preprocessor cpp of the GNU Compiler
5338  Collection (gcc), if you need more dedicated options please refer to the
5339  documentation at 
5340 \begin_inset LatexCommand \htmlurl{http://www.gnu.org/software/gcc/onlinedocs/}
5341
5342 \end_inset 
5343
5344 .
5345 \layout Subsection
5346
5347 Linker Options
5348 \begin_inset LatexCommand \index{Options linker}
5349
5350 \end_inset 
5351
5352
5353 \begin_inset LatexCommand \index{Linker options}
5354
5355 \end_inset 
5356
5357
5358 \layout List
5359 \labelwidthstring 00.00.0000
5360
5361
5362 \series bold 
5363 -L\SpecialChar ~
5364 -
5365 \series default 
5366
5367 \begin_inset ERT
5368 status Collapsed
5369
5370 \layout Standard
5371
5372 \backslash 
5373 /
5374 \end_inset 
5375
5376
5377 \series bold 
5378 -lib-path
5379 \begin_inset LatexCommand \index{-\/-lib-path <path>}
5380
5381 \end_inset 
5382
5383
5384 \begin_inset LatexCommand \index{-L -\/-lib-path}
5385
5386 \end_inset 
5387
5388
5389 \series default 
5390 \SpecialChar ~
5391 <absolute path to additional libraries> This option is passed to the linkage
5392  editor's additional libraries
5393 \begin_inset LatexCommand \index{Libraries}
5394
5395 \end_inset 
5396
5397  search path.
5398  The path name must be absolute.
5399  Additional library files may be specified in the command line.
5400  See section Compiling programs for more details.
5401 \layout List
5402 \labelwidthstring 00.00.0000
5403
5404
5405 \series bold 
5406 -
5407 \begin_inset ERT
5408 status Collapsed
5409
5410 \layout Standard
5411
5412 \backslash 
5413 /
5414 \end_inset 
5415
5416 -xram-loc
5417 \series default 
5418
5419 \begin_inset LatexCommand \index{-\/-xram-loc <Value>}
5420
5421 \end_inset 
5422
5423 \SpecialChar ~
5424 <Value> The start location of the external ram
5425 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
5426
5427 \end_inset 
5428
5429 , default value is 0.
5430  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5431 \begin_inset ERT
5432 status Collapsed
5433
5434 \layout Standard
5435
5436 \backslash 
5437 /
5438 \end_inset 
5439
5440 -xram-loc 0x8000 or -
5441 \begin_inset ERT
5442 status Collapsed
5443
5444 \layout Standard
5445
5446 \backslash 
5447 /
5448 \end_inset 
5449
5450 -xram-loc 32768.
5451 \layout List
5452 \labelwidthstring 00.00.0000
5453
5454
5455 \series bold 
5456 -
5457 \begin_inset ERT
5458 status Collapsed
5459
5460 \layout Standard
5461
5462 \backslash 
5463 /
5464 \end_inset 
5465
5466 -code-loc
5467 \series default 
5468
5469 \begin_inset LatexCommand \index{-\/-code-loc <Value>}
5470
5471 \end_inset 
5472
5473 \SpecialChar ~
5474 <Value> The start location of the code
5475 \begin_inset LatexCommand \index{code}
5476
5477 \end_inset 
5478
5479  segment, default value 0.
5480  Note when this option is used the interrupt vector table is also relocated
5481  to the given address.
5482  The value entered can be in Hexadecimal or Decimal format, e.g.: -
5483 \begin_inset ERT
5484 status Collapsed
5485
5486 \layout Standard
5487
5488 \backslash 
5489 /
5490 \end_inset 
5491
5492 -code-loc 0x8000 or -
5493 \begin_inset ERT
5494 status Collapsed
5495
5496 \layout Standard
5497
5498 \backslash 
5499 /
5500 \end_inset 
5501
5502 -code-loc 32768.
5503 \layout List
5504 \labelwidthstring 00.00.0000
5505
5506
5507 \series bold 
5508 -
5509 \begin_inset ERT
5510 status Collapsed
5511
5512 \layout Standard
5513
5514 \backslash 
5515 /
5516 \end_inset 
5517
5518 -stack-loc
5519 \series default 
5520
5521 \begin_inset LatexCommand \index{-\/-stack-loc <Value>}
5522
5523 \end_inset 
5524
5525 \SpecialChar ~
5526 <Value> By default the stack
5527 \begin_inset LatexCommand \index{stack}
5528
5529 \end_inset 
5530
5531  is placed after the data segment.
5532  Using this option the stack can be placed anywhere in the internal memory
5533  space of the 8051.
5534  The value entered can be in Hexadecimal or Decimal format, e.g.
5535  -
5536 \begin_inset ERT
5537 status Collapsed
5538
5539 \layout Standard
5540
5541 \backslash 
5542 /
5543 \end_inset 
5544
5545 -stack-loc 0x20 or -
5546 \begin_inset ERT
5547 status Collapsed
5548
5549 \layout Standard
5550
5551 \backslash 
5552 /
5553 \end_inset 
5554
5555 -stack-loc 32.
5556  Since the sp register is incremented before a push or call, the initial
5557  sp will be set to one byte prior the provided value.
5558  The provided value should not overlap any other memory areas such as used
5559  register banks or the data segment and with enough space for the current
5560  application.
5561 \layout List
5562 \labelwidthstring 00.00.0000
5563
5564
5565 \series bold 
5566 -
5567 \begin_inset ERT
5568 status Collapsed
5569
5570 \layout Standard
5571
5572 \backslash 
5573 /
5574 \end_inset 
5575
5576 -data-loc
5577 \series default 
5578
5579 \begin_inset LatexCommand \index{-\/-data-loc <Value>}
5580
5581 \end_inset 
5582
5583 \SpecialChar ~
5584 <Value> The start location of the internal ram data
5585 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
5586
5587 \end_inset 
5588
5589  segment.
5590  The value entered can be in Hexadecimal or Decimal format, eg.
5591  -
5592 \begin_inset ERT
5593 status Collapsed
5594
5595 \layout Standard
5596
5597 \backslash 
5598 /
5599 \end_inset 
5600
5601 -data-loc 0x20 or -
5602 \begin_inset ERT
5603 status Collapsed
5604
5605 \layout Standard
5606
5607 \backslash 
5608 /
5609 \end_inset 
5610
5611 -data-loc 32.
5612  (By default, the start location of the internal ram data segment  is set
5613  as low as possible in memory, taking into account the used register banks
5614  and the bit segment at address 0x20.
5615  For example if register banks 0 and 1 are used without bit variables, the
5616  data segment will be set, if -
5617 \begin_inset ERT
5618 status Collapsed
5619
5620 \layout Standard
5621
5622 \backslash 
5623 /
5624 \end_inset 
5625
5626 -data-loc is not used, to location 0x10.)
5627 \layout List
5628 \labelwidthstring 00.00.0000
5629
5630
5631 \series bold 
5632 -
5633 \begin_inset ERT
5634 status Collapsed
5635
5636 \layout Standard
5637
5638 \backslash 
5639 /
5640 \end_inset 
5641
5642 -idata-loc
5643 \series default 
5644
5645 \begin_inset LatexCommand \index{-\/-idata-loc <Value>}
5646
5647 \end_inset 
5648
5649 \SpecialChar ~
5650 <Value> The start location of the indirectly addressable internal ram
5651 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
5652
5653 \end_inset 
5654
5655  of the 8051, default value is 0x80.
5656  The value entered can be in Hexadecimal or Decimal format, eg.
5657  -
5658 \begin_inset ERT
5659 status Collapsed
5660
5661 \layout Standard
5662
5663 \backslash 
5664 /
5665 \end_inset 
5666
5667 -idata-loc 0x88 or -
5668 \begin_inset ERT
5669 status Collapsed
5670
5671 \layout Standard
5672
5673 \backslash 
5674 /
5675 \end_inset 
5676
5677 -idata-loc 136.
5678 \layout List
5679 \labelwidthstring 00.00.0000
5680
5681
5682 \series bold 
5683 -
5684 \begin_inset ERT
5685 status Collapsed
5686
5687 \layout Standard
5688
5689 \backslash 
5690 /
5691 \end_inset 
5692
5693 -bit-loc
5694 \series default 
5695 \SpecialChar ~
5696 <Value> The start location of the bit
5697 \begin_inset LatexCommand \index{bit}
5698
5699 \end_inset 
5700
5701  addressable internal ram of the 8051.
5702  This is 
5703 \emph on 
5704 not
5705 \emph default 
5706  implemented yet.
5707  Instead an option can be passed directly to the linker: -Wl\SpecialChar ~
5708 -bBSEG=<Value>.
5709 \layout List
5710 \labelwidthstring 00.00.0000
5711
5712
5713 \series bold 
5714 -
5715 \begin_inset ERT
5716 status Collapsed
5717
5718 \layout Standard
5719
5720 \backslash 
5721 /
5722 \end_inset 
5723
5724 -out-fmt-ihx
5725 \begin_inset LatexCommand \index{-\/-out-fmt-ihx}
5726
5727 \end_inset 
5728
5729
5730 \bar under 
5731  
5732 \series default 
5733 \bar default 
5734 The linker output (final object code) is in Intel Hex format.
5735 \begin_inset LatexCommand \index{Intel hex format}
5736
5737 \end_inset 
5738
5739  This is the default option.
5740  The format itself is documented in the documentation of srecord
5741 \begin_inset LatexCommand \index{srecord (tool)}
5742
5743 \end_inset 
5744
5745 .
5746 \layout List
5747 \labelwidthstring 00.00.0000
5748
5749
5750 \series bold 
5751 -
5752 \begin_inset ERT
5753 status Collapsed
5754
5755 \layout Standard
5756
5757 \backslash 
5758 /
5759 \end_inset 
5760
5761 -out-fmt-s19
5762 \begin_inset LatexCommand \index{-\/-out-fmt-s19}
5763
5764 \end_inset 
5765
5766
5767 \bar under 
5768  
5769 \series default 
5770 \bar default 
5771 The linker output (final object code) is in Motorola S19 format
5772 \begin_inset LatexCommand \index{Motorola S19 format}
5773
5774 \end_inset 
5775
5776 .
5777  The format itself is documented in the documentation of srecord.
5778 \layout List
5779 \labelwidthstring 00.00.0000
5780
5781
5782 \series bold 
5783 -Wl\SpecialChar ~
5784 linkOption[,linkOption]
5785 \series default 
5786
5787 \begin_inset LatexCommand \index{-Wl linkOption[,linkOption]}
5788
5789 \end_inset 
5790
5791 ...
5792  Pass the linkOption to the linker.
5793  See file sdcc/as/doc/asxhtm.html for more on linker options.
5794 \layout Subsection
5795
5796 MCS51 Options
5797 \begin_inset LatexCommand \index{Options MCS51}
5798
5799 \end_inset 
5800
5801
5802 \begin_inset LatexCommand \index{MCS51 options}
5803
5804 \end_inset 
5805
5806
5807 \layout List
5808 \labelwidthstring 00.00.0000
5809
5810
5811 \series bold 
5812 -
5813 \begin_inset ERT
5814 status Collapsed
5815
5816 \layout Standard
5817
5818 \backslash 
5819 /
5820 \end_inset 
5821
5822 -model-small
5823 \begin_inset LatexCommand \index{-\/-model-small}
5824
5825 \end_inset 
5826
5827
5828 \series default 
5829 \size large 
5830 \emph on 
5831  
5832 \size default 
5833 \emph default 
5834 Generate code for Small Model programs, see section Memory Models for more
5835  details.
5836  This is the default model.
5837 \layout List
5838 \labelwidthstring 00.00.0000
5839
5840
5841 \series bold 
5842 -
5843 \begin_inset ERT
5844 status Collapsed
5845
5846 \layout Standard
5847
5848 \backslash 
5849 /
5850 \end_inset 
5851
5852 -model-large
5853 \begin_inset LatexCommand \index{-\/-model-large}
5854
5855 \end_inset 
5856
5857
5858 \series default 
5859  Generate code for Large model programs, see section Memory Models for more
5860  details.
5861  If this option is used all source files in the project have to be compiled
5862  with this option.
5863 \layout List
5864 \labelwidthstring 00.00.0000
5865
5866
5867 \series bold 
5868 -
5869 \begin_inset ERT
5870 status Collapsed
5871
5872 \layout Standard
5873
5874 \backslash 
5875 /
5876 \end_inset 
5877
5878 -xstack
5879 \begin_inset LatexCommand \index{-\/-xstack}
5880
5881 \end_inset 
5882
5883
5884 \series default 
5885  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
5886  variables and passing parameters.
5887  See section 
5888 \begin_inset LatexCommand \ref{sub:External-Stack}
5889
5890 \end_inset 
5891
5892 \SpecialChar ~
5893  External Stack for more details.
5894 \layout List
5895 \labelwidthstring 00.00.0000
5896
5897
5898 \series bold 
5899 -
5900 \begin_inset ERT
5901 status Collapsed
5902
5903 \layout Standard
5904
5905 \backslash 
5906 /
5907 \end_inset 
5908
5909 -iram-size
5910 \series default 
5911 \SpecialChar ~
5912 <Value>
5913 \begin_inset LatexCommand \index{-\/-iram-size <Value>}
5914
5915 \end_inset 
5916
5917  Causes the linker to check if the internal ram usage is within limits of
5918  the given value.
5919 \layout List
5920 \labelwidthstring 00.00.0000
5921
5922
5923 \series bold 
5924 -
5925 \begin_inset ERT
5926 status Collapsed
5927
5928 \layout Standard
5929
5930 \backslash 
5931 /
5932 \end_inset 
5933
5934 -xram-size
5935 \series default 
5936 \SpecialChar ~
5937 <Value>
5938 \begin_inset LatexCommand \index{-\/-xram-size <Value>}
5939
5940 \end_inset 
5941
5942  Causes the linker to check if the external ram usage is within limits of
5943  the given value.
5944 \layout List
5945 \labelwidthstring 00.00.0000
5946
5947
5948 \series bold 
5949 -
5950 \begin_inset ERT
5951 status Collapsed
5952
5953 \layout Standard
5954
5955 \backslash 
5956 /
5957 \end_inset 
5958
5959 -code-size
5960 \series default 
5961 \SpecialChar ~
5962 <Value>
5963 \begin_inset LatexCommand \index{-\/-code-size <Value>}
5964
5965 \end_inset 
5966
5967  Causes the linker to check if the code memory usage is within limits of
5968  the given value.
5969 \layout List
5970 \labelwidthstring 00.00.0000
5971
5972
5973 \series bold 
5974 -
5975 \begin_inset ERT
5976 status Collapsed
5977
5978 \layout Standard
5979
5980 \backslash 
5981 /
5982 \end_inset 
5983
5984 -stack-size
5985 \series default 
5986 \SpecialChar ~
5987 <Value>
5988 \begin_inset LatexCommand \index{-\/-stack-size <Value>}
5989
5990 \end_inset 
5991
5992  Causes the linker to check if there is at minimum <Value> bytes for stack.
5993 \layout List
5994 \labelwidthstring 00.00.0000
5995
5996
5997 \series bold 
5998 -
5999 \begin_inset ERT
6000 status Collapsed
6001
6002 \layout Standard
6003
6004 \backslash 
6005 /
6006 \end_inset 
6007
6008 -pack-iram
6009 \series default 
6010 \SpecialChar ~
6011
6012 \begin_inset LatexCommand \index{-\/-pack-iram}
6013
6014 \end_inset 
6015
6016  Causes the linker use unused register banks for data variables or stack.
6017 \layout Subsection
6018
6019 DS390 / DS400 Options
6020 \begin_inset LatexCommand \index{Options DS390}
6021
6022 \end_inset 
6023
6024
6025 \begin_inset LatexCommand \index{DS390 options}
6026
6027 \end_inset 
6028
6029
6030 \layout List
6031 \labelwidthstring 00.00.0000
6032
6033
6034 \series bold 
6035 -
6036 \begin_inset ERT
6037 status Collapsed
6038
6039 \layout Standard
6040
6041 \backslash 
6042 /
6043 \end_inset 
6044
6045 -model-flat24
6046 \series default 
6047
6048 \begin_inset LatexCommand \index{-\/-model-flat24}
6049
6050 \end_inset 
6051
6052
6053 \size large 
6054 \emph on 
6055  
6056 \size default 
6057 \emph default 
6058 Generate 24-bit flat mode code.
6059  This is the one and only that the ds390 code generator supports right now
6060  and is default when using 
6061 \emph on 
6062 -mds390
6063 \emph default 
6064 .
6065  See section Memory Models for more details.
6066 \layout List
6067 \labelwidthstring 00.00.0000
6068
6069
6070 \series bold 
6071 -
6072 \begin_inset ERT
6073 status Collapsed
6074
6075 \layout Standard
6076
6077 \backslash 
6078 /
6079 \end_inset 
6080
6081 -protect-sp-update
6082 \begin_inset LatexCommand \index{-\/-protect-sp-update}
6083
6084 \end_inset 
6085
6086
6087 \series default 
6088  disable interrupts during ESP:SP updates.
6089 \layout List
6090 \labelwidthstring 00.00.0000
6091
6092
6093 \series bold 
6094 -
6095 \begin_inset ERT
6096 status Collapsed
6097
6098 \layout Standard
6099
6100 \backslash 
6101 /
6102 \end_inset 
6103
6104 -stack-10bit
6105 \series default 
6106
6107 \begin_inset LatexCommand \index{-\/-stack-10bit}
6108
6109 \end_inset 
6110
6111  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
6112  This is the one and only that the ds390 code generator supports right now
6113  and is default when using 
6114 \emph on 
6115 -mds390
6116 \emph default 
6117 .
6118  In this mode, the stack is located in the lower 1K of the internal RAM,
6119  which is mapped to 0x400000.
6120  Note that the support is incomplete, since it still uses a single byte
6121  as the stack pointer.
6122  This means that only the lower 256 bytes of the potential 1K stack space
6123  will actually be used.
6124  However, this does allow you to reclaim the precious 256 bytes of low RAM
6125  for use for the DATA and IDATA segments.
6126  The compiler will not generate any code to put the processor into 10 bit
6127  stack mode.
6128  It is important to ensure that the processor is in this mode before calling
6129  any re-entrant functions compiled with this option.
6130  In principle, this should work with the 
6131 \emph on 
6132 -
6133 \begin_inset ERT
6134 status Collapsed
6135
6136 \layout Standard
6137
6138 \backslash 
6139 /
6140 \end_inset 
6141
6142 -stack-auto
6143 \begin_inset LatexCommand \index{-\/-stack-auto}
6144
6145 \end_inset 
6146
6147
6148 \emph default 
6149  option, but that has not been tested.
6150  It is incompatible with the 
6151 \emph on 
6152 -
6153 \begin_inset ERT
6154 status Collapsed
6155
6156 \layout Standard
6157
6158 \backslash 
6159 /
6160 \end_inset 
6161
6162 -xstack
6163 \begin_inset LatexCommand \index{-\/-xstack}
6164
6165 \end_inset 
6166
6167
6168 \emph default 
6169  option.
6170  It also only makes sense if the processor is in 24 bit contiguous addressing
6171  mode (see the 
6172 \emph on 
6173 -
6174 \begin_inset ERT
6175 status Collapsed
6176
6177 \layout Standard
6178
6179 \backslash 
6180 /
6181 \end_inset 
6182
6183 -model-flat24 option
6184 \emph default 
6185 ).
6186 \layout List
6187 \labelwidthstring 00.00.0000
6188
6189
6190 \series bold 
6191 -
6192 \begin_inset ERT
6193 status Collapsed
6194
6195 \layout Standard
6196
6197 \backslash 
6198 /
6199 \end_inset 
6200
6201 -stack-probe
6202 \begin_inset LatexCommand \index{-\/-stack-probe}
6203
6204 \end_inset 
6205
6206
6207 \series default 
6208  insert call to function __stack_probe at each function prologue.
6209 \layout List
6210 \labelwidthstring 00.00.0000
6211
6212
6213 \series bold 
6214 -
6215 \begin_inset ERT
6216 status Collapsed
6217
6218 \layout Standard
6219
6220 \backslash 
6221 /
6222 \end_inset 
6223
6224 -tini-libid
6225 \begin_inset LatexCommand \index{-\/-tini-libid}
6226
6227 \end_inset 
6228
6229
6230 \series default 
6231  <nnnn> LibraryID used in -mTININative.
6232  
6233 \layout List
6234 \labelwidthstring 00.00.0000
6235
6236
6237 \series bold 
6238 -
6239 \begin_inset ERT
6240 status Collapsed
6241
6242 \layout Standard
6243
6244 \backslash 
6245 /
6246 \end_inset 
6247
6248 -use-accelerator
6249 \begin_inset LatexCommand \index{-\/-use-accelerator}
6250
6251 \end_inset 
6252
6253
6254 \series default 
6255  generate code for DS390 Arithmetic Accelerator.
6256  
6257 \layout Subsection
6258
6259 Z80 Options
6260 \begin_inset LatexCommand \index{Options Z80}
6261
6262 \end_inset 
6263
6264
6265 \begin_inset LatexCommand \index{Z80 options}
6266
6267 \end_inset 
6268
6269
6270 \layout List
6271 \labelwidthstring 00.00.0000
6272
6273
6274 \series bold 
6275 -
6276 \begin_inset ERT
6277 status Collapsed
6278
6279 \layout Standard
6280
6281 \backslash 
6282 /
6283 \end_inset 
6284
6285 -callee-saves-bc
6286 \series default 
6287
6288 \begin_inset LatexCommand \index{-\/-callee-saves-bc}
6289
6290 \end_inset 
6291
6292
6293 \size large 
6294 \emph on 
6295  
6296 \size default 
6297 \emph default 
6298 Force a called function to always save BC.
6299 \layout List
6300 \labelwidthstring 00.00.0000
6301
6302
6303 \series bold 
6304 -
6305 \begin_inset ERT
6306 status Collapsed
6307
6308 \layout Standard
6309
6310 \backslash 
6311 /
6312 \end_inset 
6313
6314 -no-std-crt0
6315 \series default 
6316
6317 \begin_inset LatexCommand \index{-\/-no-std-crt0}
6318
6319 \end_inset 
6320
6321  When linking, skip the standard crt0.o object file.
6322  You must provide your own crt0.o for your system when linking.
6323  
6324 \layout Subsection
6325
6326 Optimization Options
6327 \begin_inset LatexCommand \index{Options optimization}
6328
6329 \end_inset 
6330
6331
6332 \begin_inset LatexCommand \index{Optimization options}
6333
6334 \end_inset 
6335
6336
6337 \layout List
6338 \labelwidthstring 00.00.0000
6339
6340
6341 \series bold 
6342 -
6343 \begin_inset ERT
6344 status Collapsed
6345
6346 \layout Standard
6347
6348 \backslash 
6349 /
6350 \end_inset 
6351
6352 -nogcse
6353 \begin_inset LatexCommand \index{-\/-nogcse}
6354
6355 \end_inset 
6356
6357
6358 \series default 
6359  Will not do global subexpression elimination, this option may be used when
6360  the compiler creates undesirably large stack/data spaces to store compiler
6361  temporaries.
6362  A warning message will be generated when this happens and the compiler
6363  will indicate the number of extra bytes it allocated.
6364  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6365 nogcse
6366 \begin_inset LatexCommand \index{\#pragma nogcse}
6367
6368 \end_inset 
6369
6370  can be used to turn off global subexpression elimination
6371 \begin_inset LatexCommand \index{Subexpression elimination}
6372
6373 \end_inset 
6374
6375  for a given function only.
6376 \layout List
6377 \labelwidthstring 00.00.0000
6378
6379
6380 \series bold 
6381 -
6382 \begin_inset ERT
6383 status Collapsed
6384
6385 \layout Standard
6386
6387 \backslash 
6388 /
6389 \end_inset 
6390
6391 -noinvariant
6392 \begin_inset LatexCommand \index{-\/-noinvariant}
6393
6394 \end_inset 
6395
6396
6397 \series default 
6398  Will not do loop invariant optimizations, this may be turned off for reasons
6399  explained for the previous option.
6400  For more details of loop optimizations performed see Loop Invariants in
6401  section 
6402 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
6403
6404 \end_inset 
6405
6406 .
6407  It is recommended that this option NOT be used, #pragma\SpecialChar ~
6408 noinvariant
6409 \begin_inset LatexCommand \index{\#pragma noinvariant}
6410
6411 \end_inset 
6412
6413  can be used to turn off invariant optimizations for a given function only.
6414 \layout List
6415 \labelwidthstring 00.00.0000
6416
6417
6418 \series bold 
6419 -
6420 \begin_inset ERT
6421 status Collapsed
6422
6423 \layout Standard
6424
6425 \backslash 
6426 /
6427 \end_inset 
6428
6429 -noinduction
6430 \begin_inset LatexCommand \index{-\/-noinduction}
6431
6432 \end_inset 
6433
6434
6435 \series default 
6436  Will not do loop induction optimizations, see section strength reduction
6437  for more details.
6438  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6439 noinduction
6440 \begin_inset LatexCommand \index{\#pragma noinduction}
6441
6442 \end_inset 
6443
6444  can be used to turn off induction optimizations for a given function only.
6445 \layout List
6446 \labelwidthstring 00.00.0000
6447
6448
6449 \series bold 
6450 -
6451 \begin_inset ERT
6452 status Collapsed
6453
6454 \layout Standard
6455
6456 \backslash 
6457 /
6458 \end_inset 
6459
6460 -nojtbound
6461 \begin_inset LatexCommand \index{-\/-nojtbound}
6462
6463 \end_inset 
6464
6465
6466 \size large 
6467 \bar under 
6468  
6469 \series default 
6470 \size default 
6471 \bar default 
6472  Will not generate boundary condition check when switch statements
6473 \begin_inset LatexCommand \index{switch statement}
6474
6475 \end_inset 
6476
6477  are implemented using jump-tables.
6478  See section 
6479 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
6480
6481 \end_inset 
6482
6483 \SpecialChar ~
6484 Switch Statements for more details.
6485  It is recommended that this option is NOT used, #pragma\SpecialChar ~
6486 nojtbound
6487 \begin_inset LatexCommand \index{\#pragma nojtbound}
6488
6489 \end_inset 
6490
6491  can be used to turn off boundary checking for jump tables for a given function
6492  only.
6493 \layout List
6494 \labelwidthstring 00.00.0000
6495
6496
6497 \series bold 
6498 -
6499 \begin_inset ERT
6500 status Collapsed
6501
6502 \layout Standard
6503
6504 \backslash 
6505 /
6506 \end_inset 
6507
6508 -noloopreverse
6509 \begin_inset LatexCommand \index{-\/-noloopreverse}
6510
6511 \end_inset 
6512
6513
6514 \series default 
6515 \size large 
6516  
6517 \size default 
6518 Will not do loop reversal 
6519 \begin_inset LatexCommand \index{Loop reversing}
6520
6521 \end_inset 
6522
6523 optimization.
6524 \layout List
6525 \labelwidthstring 00.00.0000
6526
6527 -
6528 \begin_inset ERT
6529 status Collapsed
6530
6531 \layout Standard
6532
6533 \backslash 
6534 /
6535 \end_inset 
6536
6537 -
6538 \series bold 
6539 nolabelopt
6540 \series default 
6541  
6542 \begin_inset LatexCommand \index{-\/-nolabelopt }
6543
6544 \end_inset 
6545
6546 Will not optimize labels (makes the dumpfiles more readable).
6547 \layout List
6548 \labelwidthstring 00.00.0000
6549
6550
6551 \series bold 
6552 -
6553 \begin_inset ERT
6554 status Collapsed
6555
6556 \layout Standard
6557
6558 \backslash 
6559 /
6560 \end_inset 
6561
6562 -no-xinit-opt
6563 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
6564
6565 \end_inset 
6566
6567
6568 \series default 
6569  Will not memcpy initialized data from code space into xdata space.
6570  This saves a few bytes in code space if you don't have initialized data.
6571 \layout List
6572 \labelwidthstring 00.00.0000
6573
6574
6575 \series bold 
6576 -
6577 \begin_inset ERT
6578 status Collapsed
6579
6580 \layout Standard
6581
6582 \backslash 
6583 /
6584 \end_inset 
6585
6586 -nooverlay
6587 \begin_inset LatexCommand \index{-\/-nooverlay}
6588
6589 \end_inset 
6590
6591
6592 \series default 
6593   The compiler will not overlay parameters and local variables of any function,
6594  see section Parameters and local variables for more details.
6595 \layout List
6596 \labelwidthstring 00.00.0000
6597
6598
6599 \series bold 
6600 -
6601 \begin_inset ERT
6602 status Collapsed
6603
6604 \layout Standard
6605
6606 \backslash 
6607 /
6608 \end_inset 
6609
6610 -no-peep
6611 \begin_inset LatexCommand \index{-\/-no-peep}
6612
6613 \end_inset 
6614
6615
6616 \series default 
6617  Disable peep-hole optimization.
6618 \layout List
6619 \labelwidthstring 00.00.0000
6620
6621
6622 \series bold 
6623 -
6624 \begin_inset ERT
6625 status Collapsed
6626
6627 \layout Standard
6628
6629 \backslash 
6630 /
6631 \end_inset 
6632
6633 -peep-file
6634 \series default 
6635
6636 \begin_inset LatexCommand \index{-\/-peep-file}
6637
6638 \end_inset 
6639
6640 \SpecialChar ~
6641 <filename> This option can be used to use additional rules to be used by
6642  the peep hole optimizer.
6643  See section 
6644 \begin_inset LatexCommand \ref{sub:Peephole-Optimizer}
6645
6646 \end_inset 
6647
6648 \SpecialChar ~
6649 Peep Hole optimizations for details on how to write these rules.
6650 \layout List
6651 \labelwidthstring 00.00.0000
6652
6653
6654 \series bold 
6655 -
6656 \begin_inset ERT
6657 status Collapsed
6658
6659 \layout Standard
6660
6661 \backslash 
6662 /
6663 \end_inset 
6664
6665 -peep-asm
6666 \begin_inset LatexCommand \index{-\/-peep-asm}
6667
6668 \end_inset 
6669
6670
6671 \series default 
6672   Pass the inline assembler code through the peep hole optimizer.
6673  This can cause unexpected changes to inline assembler code, please go through
6674  the peephole optimizer
6675 \begin_inset LatexCommand \index{Peephole optimizer}
6676
6677 \end_inset 
6678
6679  rules defined in the source file tree '<target>/peeph.def' before using
6680  this option.
6681 \layout Subsection
6682
6683 Other Options
6684 \begin_inset LatexCommand \index{Options other}
6685
6686 \end_inset 
6687
6688
6689 \layout List
6690 \labelwidthstring 00.00.0000
6691
6692
6693 \series bold 
6694 -c\SpecialChar ~
6695 -
6696 \begin_inset ERT
6697 status Collapsed
6698
6699 \layout Standard
6700
6701 \backslash 
6702 /
6703 \end_inset 
6704
6705 -compile-only
6706 \begin_inset LatexCommand \index{-\/-compile-only}
6707
6708 \end_inset 
6709
6710
6711 \begin_inset LatexCommand \index{-c -\/-compile-only}
6712
6713 \end_inset 
6714
6715
6716 \series default 
6717  will compile and assemble the source, but will not call the linkage editor.
6718 \layout List
6719 \labelwidthstring 00.00.0000
6720
6721
6722 \series bold 
6723 -
6724 \series default 
6725
6726 \begin_inset ERT
6727 status Collapsed
6728
6729 \layout Standard
6730
6731 \backslash 
6732 /
6733 \end_inset 
6734
6735
6736 \series bold 
6737 -c1mode
6738 \begin_inset LatexCommand \index{-\/-c1mode}
6739
6740 \end_inset 
6741
6742
6743 \series default 
6744  reads the preprocessed source from standard input and compiles it.
6745  The file name for the assembler output must be specified using the -o option.
6746 \layout List
6747 \labelwidthstring 00.00.0000
6748
6749
6750 \series bold 
6751 -E
6752 \begin_inset LatexCommand \index{-E}
6753
6754 \end_inset 
6755
6756
6757 \series default 
6758  Run only the C preprocessor.
6759  Preprocess all the C source files specified and output the results to standard
6760  output.
6761 \layout List
6762 \labelwidthstring 00.00.0000
6763
6764
6765 \series bold 
6766 -o\SpecialChar ~
6767 <path/file>
6768 \begin_inset LatexCommand \index{-o <path/file>}
6769
6770 \end_inset 
6771
6772  
6773 \series default 
6774 The output path resp.
6775  file where everything will be placed.
6776  If the parameter is a path, it must have a trailing slash (or backslash
6777  for the Windows binaries) to be recognized as a path.
6778  
6779 \layout List
6780 \labelwidthstring 00.00.0000
6781
6782
6783 \series bold 
6784 -
6785 \begin_inset ERT
6786 status Collapsed
6787
6788 \layout Standard
6789
6790 \backslash 
6791 /
6792 \end_inset 
6793
6794 -stack-auto
6795 \begin_inset LatexCommand \index{-\/-stack-auto}
6796
6797 \end_inset 
6798
6799
6800 \series default 
6801 \size large 
6802 \emph on 
6803  
6804 \size default 
6805 \emph default 
6806 All functions in the source file will be compiled as 
6807 \emph on 
6808 reentrant
6809 \emph default 
6810
6811 \begin_inset LatexCommand \index{reentrant}
6812
6813 \end_inset 
6814
6815 , i.e.
6816  the parameters and local variables will be allocated on the stack
6817 \begin_inset LatexCommand \index{stack}
6818
6819 \end_inset 
6820
6821 .
6822  See section 
6823 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
6824
6825 \end_inset 
6826
6827  Parameters and Local Variables for more details.
6828  If this option is used all source files in the project should be compiled
6829  with this option.
6830  
6831 \layout List
6832 \labelwidthstring 00.00.0000
6833
6834
6835 \series bold 
6836 -
6837 \begin_inset ERT
6838 status Collapsed
6839
6840 \layout Standard
6841
6842 \backslash 
6843 /
6844 \end_inset 
6845
6846 -callee-saves
6847 \begin_inset LatexCommand \index{-\/-callee-saves}
6848
6849 \end_inset 
6850
6851  function1[,function2][,function3]....
6852
6853 \series default 
6854  The compiler by default uses a caller saves convention for register saving
6855  across function calls, however this can cause unnecessary register pushing
6856  & popping when calling small functions from larger functions.
6857  This option can be used to switch the register saving convention for the
6858  function names specified.
6859  The compiler will not save registers when calling these functions, no extra
6860  code will be generated at the entry & exit (function prologue
6861 \series bold 
6862
6863 \begin_inset LatexCommand \index{function prologue}
6864
6865 \end_inset 
6866
6867
6868 \series default 
6869  & epilogue
6870 \series bold 
6871
6872 \begin_inset LatexCommand \index{function epilogue}
6873
6874 \end_inset 
6875
6876
6877 \series default 
6878 ) for these functions to save & restore the registers used by these functions,
6879  this can SUBSTANTIALLY reduce code & improve run time performance of the
6880  generated code.
6881  In the future the compiler (with inter procedural analysis) will be able
6882  to determine the appropriate scheme to use for each function call.
6883  DO NOT use this option for built-in functions such as _mulint..., if this
6884  option is used for a library function the appropriate library function
6885  needs to be recompiled with the same option.
6886  If the project consists of multiple source files then all the source file
6887  should be compiled with the same -
6888 \begin_inset ERT
6889 status Collapsed
6890
6891 \layout Standard
6892
6893 \backslash 
6894 /
6895 \end_inset 
6896
6897 -callee-saves option string.
6898  Also see #pragma\SpecialChar ~
6899 callee_saves
6900 \begin_inset LatexCommand \index{\#pragma callee\_saves}
6901
6902 \end_inset 
6903
6904 .
6905 \layout List
6906 \labelwidthstring 00.00.0000
6907
6908
6909 \series bold 
6910 -
6911 \begin_inset ERT
6912 status Open
6913
6914 \layout Standard
6915
6916 \backslash 
6917 /
6918 \end_inset 
6919
6920 -debug
6921 \begin_inset LatexCommand \index{-\/-debug}
6922
6923 \end_inset 
6924
6925
6926 \bar under 
6927  
6928 \series default 
6929 \bar default 
6930 When this option is used the compiler will generate debug information.
6931  The debug information collected in a file with .cdb extension can be used
6932  with the SDCDB.
6933  For more information see documentation for SDCDB.
6934  Another file with no extension contains debug information in AOMF or AOMF51
6935 \begin_inset LatexCommand \index{AOMF, AOMF51}
6936
6937 \end_inset 
6938
6939  format which is commonly used by third party tools.
6940 \layout List
6941 \labelwidthstring 00.00.0000
6942
6943
6944 \series bold 
6945 -S
6946 \begin_inset LatexCommand \index{-S}
6947
6948 \end_inset 
6949
6950
6951 \size large 
6952 \bar under 
6953  
6954 \series default 
6955 \size default 
6956 \bar default 
6957 Stop after the stage of compilation proper; do not assemble.
6958  The output is an assembler code file for the input file specified.
6959 \layout List
6960 \labelwidthstring 00.00.0000
6961
6962
6963 \series bold 
6964 -
6965 \begin_inset ERT
6966 status Collapsed
6967
6968 \layout Standard
6969
6970 \backslash 
6971 /
6972 \end_inset 
6973
6974 -int-long-reent
6975 \begin_inset LatexCommand \index{-\/-int-long-reent}
6976
6977 \end_inset 
6978
6979
6980 \series default 
6981  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
6982  Note by default these libraries are compiled as non-reentrant.
6983  See section Installation for more details.
6984 \layout List
6985 \labelwidthstring 00.00.0000
6986
6987
6988 \series bold 
6989 -
6990 \begin_inset ERT
6991 status Collapsed
6992
6993 \layout Standard
6994
6995 \backslash 
6996 /
6997 \end_inset 
6998
6999 -cyclomatic
7000 \begin_inset LatexCommand \index{-\/-cyclomatic}
7001
7002 \end_inset 
7003
7004
7005 \bar under 
7006  
7007 \series default 
7008 \bar default 
7009 This option will cause the compiler to generate an information message for
7010  each function in the source file.
7011  The message contains some 
7012 \emph on 
7013 important
7014 \emph default 
7015  information about the function.
7016  The number of edges and nodes the compiler detected in the control flow
7017  graph of the function, and most importantly the 
7018 \emph on 
7019 cyclomatic complexity
7020 \begin_inset LatexCommand \index{Cyclomatic complexity}
7021
7022 \end_inset 
7023
7024
7025 \emph default 
7026  see section on Cyclomatic Complexity for more details.
7027 \layout List
7028 \labelwidthstring 00.00.0000
7029
7030
7031 \series bold 
7032 -
7033 \begin_inset ERT
7034 status Collapsed
7035
7036 \layout Standard
7037
7038 \backslash 
7039 /
7040 \end_inset 
7041
7042 -float-reent
7043 \begin_inset LatexCommand \index{-\/-float-reent}
7044
7045 \end_inset 
7046
7047
7048 \series default 
7049  Floating point library is compiled as reentrant
7050 \begin_inset LatexCommand \index{reentrant}
7051
7052 \end_inset 
7053
7054 .
7055  See section Installation for more details.
7056 \layout List
7057 \labelwidthstring 00.00.0000
7058
7059
7060 \series bold 
7061 -
7062 \begin_inset ERT
7063 status Collapsed
7064
7065 \layout Standard
7066
7067 \backslash 
7068 /
7069 \end_inset 
7070
7071 -main-return
7072 \begin_inset LatexCommand \index{-\/-main-return}
7073
7074 \end_inset 
7075
7076
7077 \series default 
7078  This option can be used if the code generated is called by a monitor program
7079  or if the main routine includes an endless loop.
7080  This option might result in slightly smaller code and save two bytes of
7081  stack space.
7082  The return from the 'main'
7083 \begin_inset LatexCommand \index{main return}
7084
7085 \end_inset 
7086
7087  function will return to the function calling main.
7088  The default setting is to lock up i.e.
7089  generate a '
7090 \family typewriter 
7091 sjmp .
7092 \family default 
7093 '.
7094 \layout List
7095 \labelwidthstring 00.00.0000
7096
7097
7098 \series bold 
7099 -
7100 \begin_inset ERT
7101 status Collapsed
7102
7103 \layout Standard
7104
7105 \backslash 
7106 /
7107 \end_inset 
7108
7109 -nostdincl
7110 \begin_inset LatexCommand \index{-\/-nostdincl}
7111
7112 \end_inset 
7113
7114
7115 \series default 
7116  This will prevent the compiler from passing on the default include path
7117  to the preprocessor.
7118 \layout List
7119 \labelwidthstring 00.00.0000
7120
7121
7122 \series bold 
7123 -
7124 \begin_inset ERT
7125 status Collapsed
7126
7127 \layout Standard
7128
7129 \backslash 
7130 /
7131 \end_inset 
7132
7133 -nostdlib
7134 \begin_inset LatexCommand \index{-\/-nostdlib}
7135
7136 \end_inset 
7137
7138
7139 \series default 
7140  This will prevent the compiler from passing on the default library
7141 \begin_inset LatexCommand \index{Libraries}
7142
7143 \end_inset 
7144
7145  path to the linker.
7146 \layout List
7147 \labelwidthstring 00.00.0000
7148
7149
7150 \series bold 
7151 -
7152 \begin_inset ERT
7153 status Collapsed
7154
7155 \layout Standard
7156
7157 \backslash 
7158 /
7159 \end_inset 
7160
7161 -verbose
7162 \begin_inset LatexCommand \index{-\/-verbose}
7163
7164 \end_inset 
7165
7166
7167 \series default 
7168  Shows the various actions the compiler is performing.
7169 \layout List
7170 \labelwidthstring 00.00.0000
7171
7172
7173 \series bold 
7174 -V
7175 \begin_inset LatexCommand \index{-V}
7176
7177 \end_inset 
7178
7179
7180 \series default 
7181  Shows the actual commands the compiler is executing.
7182 \layout List
7183 \labelwidthstring 00.00.0000
7184
7185
7186 \series bold 
7187 -
7188 \begin_inset ERT
7189 status Collapsed
7190
7191 \layout Standard
7192
7193 \backslash 
7194 /
7195 \end_inset 
7196
7197 -no-c-code-in-asm
7198 \begin_inset LatexCommand \index{-\/-no-c-code-in-asm}
7199
7200 \end_inset 
7201
7202
7203 \series default 
7204  Hides your ugly and inefficient c-code from the asm file, so you can always
7205  blame the compiler :)
7206 \layout List
7207 \labelwidthstring 00.00.0000
7208
7209
7210 \series bold 
7211 -
7212 \begin_inset ERT
7213 status Collapsed
7214
7215 \layout Standard
7216
7217 \backslash 
7218 /
7219 \end_inset 
7220
7221 -no-peep-comments
7222 \begin_inset LatexCommand \index{-\/-no-peep-comments}
7223
7224 \end_inset 
7225
7226
7227 \series default 
7228  Will not include peep-hole comments in the generated files.
7229 \layout List
7230 \labelwidthstring 00.00.0000
7231
7232
7233 \series bold 
7234 -
7235 \begin_inset ERT
7236 status Collapsed
7237
7238 \layout Standard
7239
7240 \backslash 
7241 /
7242 \end_inset 
7243
7244 -i-code-in-asm
7245 \begin_inset LatexCommand \index{-\/-i-code-in-asm}
7246
7247 \end_inset 
7248
7249
7250 \series default 
7251  Include i-codes in the asm file.
7252  Sounds like noise but is most helpful for debugging the compiler itself.
7253 \layout List
7254 \labelwidthstring 00.00.0000
7255
7256
7257 \series bold 
7258 -
7259 \begin_inset ERT
7260 status Collapsed
7261
7262 \layout Standard
7263
7264 \backslash 
7265 /
7266 \end_inset 
7267
7268 -less-pedantic
7269 \begin_inset LatexCommand \index{-\/-less-pedantic}
7270
7271 \end_inset 
7272
7273
7274 \series default 
7275  Disable some of the more pedantic warnings
7276 \begin_inset LatexCommand \index{Warnings}
7277
7278 \end_inset 
7279
7280  (jwk burps: please be more specific here, please!).
7281  If you want rather more than less warnings you should consider using a
7282  separate tool dedicated to syntax checking like splint 
7283 \begin_inset LatexCommand \url{www.splint.org}
7284
7285 \end_inset 
7286
7287 .
7288 \layout List
7289 \labelwidthstring 00.00.0000
7290
7291
7292 \series bold 
7293 -
7294 \begin_inset ERT
7295 status Collapsed
7296
7297 \layout Standard
7298
7299 \backslash 
7300 /
7301 \end_inset 
7302
7303 -print-search-dirs
7304 \begin_inset LatexCommand \index{-\/-print-search-dirs}
7305
7306 \end_inset 
7307
7308
7309 \series default 
7310  Display the directories in the compiler's search path
7311 \layout List
7312 \labelwidthstring 00.00.0000
7313
7314
7315 \series bold 
7316 -
7317 \begin_inset ERT
7318 status Collapsed
7319
7320 \layout Standard
7321
7322 \backslash 
7323 /
7324 \end_inset 
7325
7326 -vc
7327 \begin_inset LatexCommand \index{-\/-vc}
7328
7329 \end_inset 
7330
7331
7332 \series default 
7333  Display errors and warnings using MSVC style, so you can use SDCC with
7334  visual studio.
7335 \layout List
7336 \labelwidthstring 00.00.0000
7337
7338
7339 \series bold 
7340 -
7341 \begin_inset ERT
7342 status Collapsed
7343
7344 \layout Standard
7345
7346 \backslash 
7347 /
7348 \end_inset 
7349
7350 -use-stdout
7351 \begin_inset LatexCommand \index{-\/-use-stdout}
7352
7353 \end_inset 
7354
7355
7356 \series default 
7357  Send errors and warnings to stdout instead of stderr.
7358 \layout List
7359 \labelwidthstring 00.00.0000
7360
7361
7362 \series bold 
7363 -Wa\SpecialChar ~
7364 asmOption[,asmOption]
7365 \series default 
7366
7367 \begin_inset LatexCommand \index{-Wa asmOption[,asmOption]}
7368
7369 \end_inset 
7370
7371 ...
7372  Pass the asmOption to the assembler
7373 \begin_inset LatexCommand \index{Options assembler}
7374
7375 \end_inset 
7376
7377
7378 \begin_inset LatexCommand \index{Assembler options}
7379
7380 \end_inset 
7381
7382 .
7383  See file sdcc/as/doc/asxhtm.html for assembler options.
7384 \layout Subsection
7385
7386 Intermediate Dump Options
7387 \begin_inset LatexCommand \label{sub:Intermediate-Dump-Options}
7388
7389 \end_inset 
7390
7391
7392 \begin_inset LatexCommand \index{Options intermediate dump}
7393
7394 \end_inset 
7395
7396
7397 \begin_inset LatexCommand \index{Intermediate dump options}
7398
7399 \end_inset 
7400
7401
7402 \layout Standard
7403
7404 The following options are provided for the purpose of retargetting and debugging
7405  the compiler.
7406  These provided a means to dump the intermediate code (iCode
7407 \begin_inset LatexCommand \index{iCode}
7408
7409 \end_inset 
7410
7411 ) generated by the compiler in human readable form at various stages of
7412  the compilation process.
7413  More on iCodes see chapter 
7414 \begin_inset LatexCommand \ref{sub:The-anatomy-of}
7415
7416 \end_inset 
7417
7418  
7419 \begin_inset Quotes srd
7420 \end_inset 
7421
7422 The anatomy of the compiler
7423 \begin_inset Quotes srd
7424 \end_inset 
7425
7426 .
7427 \layout List
7428 \labelwidthstring 00.00.0000
7429
7430
7431 \series bold 
7432 -
7433 \begin_inset ERT
7434 status Collapsed
7435
7436 \layout Standard
7437
7438 \backslash 
7439 /
7440 \end_inset 
7441
7442 -dumpraw
7443 \begin_inset LatexCommand \index{-\/-dumpraw}
7444
7445 \end_inset 
7446
7447
7448 \series default 
7449  This option will cause the compiler to dump the intermediate code into
7450  a file of named 
7451 \emph on 
7452 <source filename>.dumpraw
7453 \emph default 
7454  just after the intermediate code has been generated for a function, i.e.
7455  before any optimizations are done.
7456  The basic blocks
7457 \begin_inset LatexCommand \index{Basic blocks}
7458
7459 \end_inset 
7460
7461  at this stage ordered in the depth first number, so they may not be in
7462  sequence of execution.
7463 \layout List
7464 \labelwidthstring 00.00.0000
7465
7466
7467 \series bold 
7468 -
7469 \begin_inset ERT
7470 status Collapsed
7471
7472 \layout Standard
7473
7474 \backslash 
7475 /
7476 \end_inset 
7477
7478 -dumpgcse
7479 \begin_inset LatexCommand \index{-\/-dumpgcse}
7480
7481 \end_inset 
7482
7483
7484 \series default 
7485  Will create a dump of iCode's, after global subexpression elimination
7486 \begin_inset LatexCommand \index{Global subexpression elimination}
7487
7488 \end_inset 
7489
7490 , into a file named 
7491 \emph on 
7492 <source filename>.dumpgcse.
7493 \layout List
7494 \labelwidthstring 00.00.0000
7495
7496
7497 \series bold 
7498 -
7499 \begin_inset ERT
7500 status Collapsed
7501
7502 \layout Standard
7503
7504 \backslash 
7505 /
7506 \end_inset 
7507
7508 -dumpdeadcode
7509 \begin_inset LatexCommand \index{-\/-dumpdeadcode}
7510
7511 \end_inset 
7512
7513
7514 \series default 
7515  Will create a dump of iCode's, after deadcode elimination
7516 \begin_inset LatexCommand \index{Dead-code elimination}
7517
7518 \end_inset 
7519
7520 , into a file named 
7521 \emph on 
7522 <source filename>.dumpdeadcode.
7523 \layout List
7524 \labelwidthstring 00.00.0000
7525
7526
7527 \series bold 
7528 -
7529 \begin_inset ERT
7530 status Collapsed
7531
7532 \layout Standard
7533
7534 \backslash 
7535 /
7536 \end_inset 
7537
7538 -dumploop
7539 \begin_inset LatexCommand \index{-\/-dumploop}
7540
7541 \end_inset 
7542
7543
7544 \series default 
7545 \size large 
7546  
7547 \size default 
7548 Will create a dump of iCode's, after loop optimizations
7549 \begin_inset LatexCommand \index{Loop optimization}
7550
7551 \end_inset 
7552
7553 , into a file named 
7554 \emph on 
7555 <source filename>.dumploop.
7556 \layout List
7557 \labelwidthstring 00.00.0000
7558
7559
7560 \series bold 
7561 -
7562 \begin_inset ERT
7563 status Collapsed
7564
7565 \layout Standard
7566
7567 \backslash 
7568 /
7569 \end_inset 
7570
7571 -dumprange
7572 \begin_inset LatexCommand \index{-\/-dumprange}
7573
7574 \end_inset 
7575
7576
7577 \series default 
7578 \size large 
7579  
7580 \size default 
7581 Will create a dump of iCode's, after live range analysis
7582 \begin_inset LatexCommand \index{Live range analysis}
7583
7584 \end_inset 
7585
7586 , into a file named 
7587 \emph on 
7588 <source filename>.dumprange.
7589 \layout List
7590 \labelwidthstring 00.00.0000
7591
7592
7593 \series bold 
7594 -
7595 \begin_inset ERT
7596 status Collapsed
7597
7598 \layout Standard
7599
7600 \backslash 
7601 /
7602 \end_inset 
7603
7604 -dumlrange
7605 \begin_inset LatexCommand \index{-\/-dumlrange}
7606
7607 \end_inset 
7608
7609
7610 \series default 
7611  Will dump the life ranges
7612 \begin_inset LatexCommand \index{Live range analysis}
7613
7614 \end_inset 
7615
7616  for all symbols.
7617 \layout List
7618 \labelwidthstring 00.00.0000
7619
7620
7621 \series bold 
7622 -
7623 \begin_inset ERT
7624 status Collapsed
7625
7626 \layout Standard
7627
7628 \backslash 
7629 /
7630 \end_inset 
7631
7632 -dumpregassign
7633 \begin_inset LatexCommand \index{-\/-dumpregassign}
7634
7635 \end_inset 
7636
7637
7638 \bar under 
7639  
7640 \series default 
7641 \bar default 
7642 Will create a dump of iCode's, after register assignment
7643 \begin_inset LatexCommand \index{Register assignment}
7644
7645 \end_inset 
7646
7647 , into a file named 
7648 \emph on 
7649 <source filename>.dumprassgn.
7650 \layout List
7651 \labelwidthstring 00.00.0000
7652
7653
7654 \series bold 
7655 -
7656 \begin_inset ERT
7657 status Collapsed
7658
7659 \layout Standard
7660
7661 \backslash 
7662 /
7663 \end_inset 
7664
7665 -dumplrange
7666 \begin_inset LatexCommand \index{-\/-dumplrange}
7667
7668 \end_inset 
7669
7670
7671 \series default 
7672  Will create a dump of the live ranges of iTemp's
7673 \layout List
7674 \labelwidthstring 00.00.0000
7675
7676
7677 \series bold 
7678 -
7679 \begin_inset ERT
7680 status Collapsed
7681
7682 \layout Standard
7683
7684 \backslash 
7685 /
7686 \end_inset 
7687
7688 -dumpall
7689 \begin_inset LatexCommand \index{-\/-dumpall}
7690
7691 \end_inset 
7692
7693
7694 \size large 
7695 \bar under 
7696  
7697 \series default 
7698 \size default 
7699 \bar default 
7700 Will cause all the above mentioned dumps to be created.
7701 \layout Subsection
7702
7703 Redirecting output on Windows Shells
7704 \layout Standard
7705
7706 By default SDCC writes it's error messages to 
7707 \begin_inset Quotes sld
7708 \end_inset 
7709
7710 standard error
7711 \begin_inset Quotes srd
7712 \end_inset 
7713
7714 .
7715  To force all messages to 
7716 \begin_inset Quotes sld
7717 \end_inset 
7718
7719 standard output
7720 \begin_inset Quotes srd
7721 \end_inset 
7722
7723  use 
7724 \series bold 
7725 -
7726 \series default 
7727 \emph on 
7728
7729 \begin_inset ERT
7730 status Collapsed
7731
7732 \layout Standard
7733
7734 \backslash 
7735 /
7736 \end_inset 
7737
7738
7739 \series bold 
7740 \emph default 
7741 -
7742 \series default 
7743 use-stdout
7744 \begin_inset LatexCommand \index{-\/-use-stdout}
7745
7746 \end_inset 
7747
7748 .
7749  Additionally, if you happen to have visual studio installed in your windows
7750  machine, you can use it to compile your sources using a custom build and
7751  the SDCC -
7752 \emph on 
7753
7754 \begin_inset ERT
7755 status Collapsed
7756
7757 \layout Standard
7758
7759 \backslash 
7760 /
7761 \end_inset 
7762
7763
7764 \emph default 
7765 -vc
7766 \begin_inset LatexCommand \index{-\/-vc}
7767
7768 \end_inset 
7769
7770  option.
7771  Something like this should work:
7772 \newline 
7773
7774 \newline 
7775
7776 \series bold 
7777 c:
7778 \backslash 
7779 sdcc
7780 \backslash 
7781 bin
7782 \backslash 
7783 sdcc.exe -
7784 \series default 
7785 \emph on 
7786
7787 \begin_inset ERT
7788 status Collapsed
7789
7790 \layout Standard
7791
7792 \backslash 
7793 /
7794 \end_inset 
7795
7796
7797 \series bold 
7798 \emph default 
7799 -vc -
7800 \series default 
7801 \emph on 
7802
7803 \begin_inset ERT
7804 status Collapsed
7805
7806 \layout Standard
7807
7808 \backslash 
7809 /
7810 \end_inset 
7811
7812
7813 \series bold 
7814 \emph default 
7815 -model-large -c $(InputPath)
7816 \layout Section
7817
7818 Environment variables
7819 \begin_inset LatexCommand \index{Environment variables}
7820
7821 \end_inset 
7822
7823
7824 \layout Standard
7825
7826 SDCC recognizes the following environment variables:
7827 \layout List
7828 \labelwidthstring 00.00.0000
7829
7830
7831 \series bold 
7832 SDCC_LEAVE_SIGNALS
7833 \begin_inset LatexCommand \index{SDCC\_LEAVE\_SIGNALS}
7834
7835 \end_inset 
7836
7837
7838 \series default 
7839  SDCC installs a signal handler
7840 \begin_inset LatexCommand \index{signal handler}
7841
7842 \end_inset 
7843
7844  to be able to delete temporary files after an user break (^C) or an exception.
7845  If this environment variable is set, SDCC won't install the signal handler
7846  in order to be able to debug SDCC.
7847 \layout List
7848 \labelwidthstring 00.00.0000
7849
7850
7851 \series bold 
7852 TMP,\SpecialChar ~
7853 TEMP,\SpecialChar ~
7854 TMPDIR
7855 \begin_inset LatexCommand \index{TMP, TEMP, TMPDIR}
7856
7857 \end_inset 
7858
7859
7860 \series default 
7861  Path, where temporary files will be created.
7862  The order of the variables is the search order.
7863  In a standard *nix environment these variables are not set, and there's
7864  no need to set them.
7865  On Windows it's recommended to set one of them.
7866 \layout List
7867 \labelwidthstring 00.00.0000
7868
7869
7870 \series bold 
7871 SDCC_HOME
7872 \begin_inset LatexCommand \index{SDCC\_HOME}
7873
7874 \end_inset 
7875
7876
7877 \series default 
7878  Path, see section 
7879 \begin_inset LatexCommand \ref{sub:Install-paths}
7880
7881 \end_inset 
7882
7883 \SpecialChar ~
7884
7885 \begin_inset Quotes sld
7886 \end_inset 
7887
7888  Install Paths
7889 \begin_inset Quotes srd
7890 \end_inset 
7891
7892 .
7893 \layout List
7894 \labelwidthstring 00.00.0000
7895
7896
7897 \series bold 
7898 SDCC_INCLUDE
7899 \begin_inset LatexCommand \index{SDCC\_INCLUDE}
7900
7901 \end_inset 
7902
7903
7904 \series default 
7905  Path, see section 
7906 \begin_inset LatexCommand \ref{sub:Search-Paths}
7907
7908 \end_inset 
7909
7910 \SpecialChar ~
7911
7912 \begin_inset Quotes sld
7913 \end_inset 
7914
7915 Search Paths
7916 \begin_inset Quotes srd
7917 \end_inset 
7918
7919 .
7920 \layout List
7921 \labelwidthstring 00.00.0000
7922
7923
7924 \series bold 
7925 SDCC_LIB
7926 \begin_inset LatexCommand \index{SDCC\_LIB}
7927
7928 \end_inset 
7929
7930
7931 \series default 
7932  Path, see section 
7933 \begin_inset LatexCommand \ref{sub:Search-Paths}
7934
7935 \end_inset 
7936
7937 \SpecialChar ~
7938
7939 \begin_inset Quotes sld
7940 \end_inset 
7941
7942 Search Paths
7943 \begin_inset Quotes srd
7944 \end_inset 
7945
7946 ..
7947 \layout Standard
7948
7949 There are some more environment variables recognized by SDCC, but these
7950  are solely used for debugging purposes.
7951  They can change or disappear very quickly, and will never be documented.
7952 \layout Section
7953
7954 Storage Class Language Extensions
7955 \layout Subsection
7956
7957 MCS51/DS390 Storage Class
7958 \begin_inset LatexCommand \index{Storage class}
7959
7960 \end_inset 
7961
7962  Language Extensions
7963 \layout Standard
7964
7965 In addition to the ANSI storage classes SDCC allows the following MCS51
7966  specific storage classes:
7967 \layout Subsubsection
7968
7969 data
7970 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
7971
7972 \end_inset 
7973
7974  / near
7975 \begin_inset LatexCommand \index{near (storage class)}
7976
7977 \end_inset 
7978
7979
7980 \layout Standard
7981
7982 This is the 
7983 \series bold 
7984 default
7985 \series default 
7986  storage class for the Small Memory model (
7987 \emph on 
7988 data
7989 \emph default 
7990  and 
7991 \emph on 
7992 near
7993 \emph default 
7994  can be used synonymously).
7995  Variables declared with this storage class will be allocated in the directly
7996  addressable portion of the internal RAM of a 8051, e.g.:
7997 \layout Verse
7998
7999
8000 \family typewriter 
8001 data unsigned char test_data;
8002 \layout Standard
8003
8004 Writing 0x01 to this variable generates the assembly code:
8005 \layout Verse
8006
8007
8008 \family typewriter 
8009 75*00 01\SpecialChar ~
8010 \SpecialChar ~
8011 \SpecialChar ~
8012 mov\SpecialChar ~
8013 \SpecialChar ~
8014 _test_data,#0x01 
8015 \layout Subsubsection
8016
8017 xdata
8018 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8019
8020 \end_inset 
8021
8022  / far
8023 \begin_inset LatexCommand \index{far (storage class)}
8024
8025 \end_inset 
8026
8027
8028 \layout Standard
8029
8030 Variables declared with this storage class will be placed in the external
8031  RAM.
8032  This is the 
8033 \series bold 
8034 default
8035 \series default 
8036  storage class for the Large Memory model, e.g.:
8037 \layout Verse
8038
8039
8040 \family typewriter 
8041 xdata unsigned char test_xdata;
8042 \layout Standard
8043
8044 Writing 0x01 to this variable generates the assembly code:
8045 \layout Verse
8046
8047
8048 \family typewriter 
8049 90s00r00\SpecialChar ~
8050 \SpecialChar ~
8051 \SpecialChar ~
8052 mov\SpecialChar ~
8053 \SpecialChar ~
8054 dptr,#_test_xdata 
8055 \newline 
8056 74\SpecialChar ~
8057 01\SpecialChar ~
8058 \SpecialChar ~
8059 \SpecialChar ~
8060 \SpecialChar ~
8061 \SpecialChar ~
8062 \SpecialChar ~
8063 mov\SpecialChar ~
8064 \SpecialChar ~
8065 a,#0x01 
8066 \newline 
8067 F0\SpecialChar ~
8068 \SpecialChar ~
8069 \SpecialChar ~
8070 \SpecialChar ~
8071 \SpecialChar ~
8072 \SpecialChar ~
8073 \SpecialChar ~
8074 \SpecialChar ~
8075 \SpecialChar ~
8076 movx\SpecialChar ~
8077 @dptr,a 
8078 \layout Subsubsection
8079
8080 idata
8081 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8082
8083 \end_inset 
8084
8085
8086 \layout Standard
8087
8088 Variables declared with this storage class will be allocated into the indirectly
8089  addressable portion of the internal ram of a 8051, e.g.:
8090 \layout Verse
8091
8092
8093 \family typewriter 
8094 idata unsigned char test_idata;
8095 \layout Standard
8096
8097 Writing 0x01 to this variable generates the assembly code:
8098 \layout Verse
8099
8100
8101 \family typewriter 
8102 78r00\SpecialChar ~
8103 \SpecialChar ~
8104 \SpecialChar ~
8105 \SpecialChar ~
8106 \SpecialChar ~
8107 \SpecialChar ~
8108 \SpecialChar ~
8109 mov\SpecialChar ~
8110 \SpecialChar ~
8111 r0,#_test_idata
8112 \newline 
8113 76\SpecialChar ~
8114 01\SpecialChar ~
8115 \SpecialChar ~
8116 \SpecialChar ~
8117 \SpecialChar ~
8118 \SpecialChar ~
8119 \SpecialChar ~
8120 \SpecialChar ~
8121 mov\SpecialChar ~
8122 \SpecialChar ~
8123 @r0,#0x01
8124 \layout Standard
8125
8126 Please note, the first 128 byte of idata physically access the same RAM
8127  as the data memory.
8128  The original 8051 had 128 byte idata memory, nowadays most devices have
8129  256 byte idata memory.
8130  The stack
8131 \begin_inset LatexCommand \index{stack}
8132
8133 \end_inset 
8134
8135  is located in idata memory.
8136 \layout Subsubsection
8137
8138 pdata
8139 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
8140
8141 \end_inset 
8142
8143
8144 \layout Standard
8145
8146 Paged xdata access is currently not as straightforward as using the other
8147  addressing modes of a 8051.
8148  The following example writes 0x01 to the address pointed to.
8149  Please note, pdata access physically accesses xdata memory.
8150  The high byte of the address is determined by port P2 
8151 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
8152
8153 \end_inset 
8154
8155 (or in case of some 8051 variants by a separate Special Function Register,
8156  see section 
8157 \begin_inset LatexCommand \ref{sub:MCS51-variants}
8158
8159 \end_inset 
8160
8161 ).
8162 \layout Verse
8163
8164
8165 \family typewriter 
8166 pdata unsigned char *test_pdata_ptr;
8167 \newline 
8168
8169 \newline 
8170 void main() 
8171 \newline 
8172
8173 \newline 
8174 \SpecialChar ~
8175 \SpecialChar ~
8176 \SpecialChar ~
8177 \SpecialChar ~
8178 test_pdata_ptr = (pdata *)0xfe; 
8179 \newline 
8180 \SpecialChar ~
8181 \SpecialChar ~
8182 \SpecialChar ~
8183 \SpecialChar ~
8184 *test_pdata_ptr = 1; 
8185 \newline 
8186
8187 \layout Standard
8188
8189 Generates the assembly code:
8190 \layout Verse
8191
8192
8193 \family typewriter 
8194 75*01 FE\SpecialChar ~
8195 \SpecialChar ~
8196 \SpecialChar ~
8197 mov\SpecialChar ~
8198  _test_pdata_ptr,#0xFE
8199 \newline 
8200 78 FE\SpecialChar ~
8201 \SpecialChar ~
8202 \SpecialChar ~
8203 \SpecialChar ~
8204 \SpecialChar ~
8205 \SpecialChar ~
8206 mov\SpecialChar ~
8207  r0,#0xFE 
8208 \newline 
8209 74 01\SpecialChar ~
8210 \SpecialChar ~
8211 \SpecialChar ~
8212 \SpecialChar ~
8213 \SpecialChar ~
8214 \SpecialChar ~
8215 mov\SpecialChar ~
8216  a,#0x01
8217 \newline 
8218 F2\SpecialChar ~
8219 \SpecialChar ~
8220 \SpecialChar ~
8221 \SpecialChar ~
8222 \SpecialChar ~
8223 \SpecialChar ~
8224 \SpecialChar ~
8225 \SpecialChar ~
8226 \SpecialChar ~
8227 movx @r0,a 
8228 \layout Standard
8229
8230 Be extremely carefull if you use pdata together with the -
8231 \begin_inset ERT
8232 status Collapsed
8233
8234 \layout Standard
8235
8236 \backslash 
8237 /
8238 \end_inset 
8239
8240 -xstack
8241 \begin_inset LatexCommand \index{-\/-xstack}
8242
8243 \end_inset 
8244
8245  option.
8246 \layout Subsubsection
8247
8248 code
8249 \begin_inset LatexCommand \index{code}
8250
8251 \end_inset 
8252
8253
8254 \layout Standard
8255
8256 'Variables' declared with this storage class will be placed in the code
8257  memory:
8258 \layout Verse
8259
8260
8261 \family typewriter 
8262 code unsigned char test_code;
8263 \layout Standard
8264
8265 Read access to this variable generates the assembly code:
8266 \layout Verse
8267
8268
8269 \family typewriter 
8270 90s00r6F\SpecialChar ~
8271 \SpecialChar ~
8272 \SpecialChar ~
8273 mov dptr,#_test_code
8274 \newline 
8275 E4\SpecialChar ~
8276 \SpecialChar ~
8277 \SpecialChar ~
8278 \SpecialChar ~
8279 \SpecialChar ~
8280 \SpecialChar ~
8281 \SpecialChar ~
8282 \SpecialChar ~
8283 \SpecialChar ~
8284 clr a
8285 \newline 
8286 93\SpecialChar ~
8287 \SpecialChar ~
8288 \SpecialChar ~
8289 \SpecialChar ~
8290 \SpecialChar ~
8291 \SpecialChar ~
8292 \SpecialChar ~
8293 \SpecialChar ~
8294 \SpecialChar ~
8295 movc a,@a+dptr 
8296 \layout Standard
8297
8298
8299 \family typewriter 
8300 char
8301 \family default 
8302  indexed arrays of characters in code memory can be accessed efficiently:
8303 \layout Verse
8304
8305
8306 \family typewriter 
8307 code char test_array[] = {'c','h','e','a','p'}; 
8308 \layout Standard
8309
8310 Read access to this array using an 8-bit unsigned index generates the assembly
8311  code:
8312 \layout Verse
8313
8314
8315 \family typewriter 
8316 E5*00\SpecialChar ~
8317 \SpecialChar ~
8318 \SpecialChar ~
8319 \SpecialChar ~
8320 \SpecialChar ~
8321 \SpecialChar ~
8322 mov a,_index 
8323 \layout Verse
8324
8325
8326 \family typewriter 
8327 90s00r41\SpecialChar ~
8328 \SpecialChar ~
8329 \SpecialChar ~
8330 mov dptr,#_test_array
8331 \layout Verse
8332
8333
8334 \family typewriter 
8335 93\SpecialChar ~
8336 \SpecialChar ~
8337 \SpecialChar ~
8338 \SpecialChar ~
8339 \SpecialChar ~
8340 \SpecialChar ~
8341 \SpecialChar ~
8342 \SpecialChar ~
8343 \SpecialChar ~
8344 movc a,@a+dptr 
8345 \layout Subsubsection
8346
8347 bit
8348 \begin_inset LatexCommand \index{bit}
8349
8350 \end_inset 
8351
8352
8353 \layout Standard
8354
8355 This is a data-type and a storage class specifier.
8356  When a variable is declared as a bit, it is allocated into the bit addressable
8357  memory of 8051, e.g.:
8358 \layout Verse
8359
8360
8361 \family typewriter 
8362 bit test_bit;
8363 \layout Standard
8364
8365 Writing 1 to this variable generates the assembly code:
8366 \layout Verse
8367
8368
8369 \family typewriter 
8370 D2*00\SpecialChar ~
8371 \SpecialChar ~
8372 \SpecialChar ~
8373 \SpecialChar ~
8374 \SpecialChar ~
8375 \SpecialChar ~
8376 \SpecialChar ~
8377 setb\SpecialChar ~
8378 _test_bit
8379 \layout Standard
8380
8381 The bit addressable memory consists of 128 bits which are located from 0x20
8382  to 0x2f in data memory.
8383  
8384 \newline 
8385 Apart from this 8051 specific storage class most architectures support ANSI-C
8386  bitfields
8387 \begin_inset LatexCommand \index{bitfields}
8388
8389 \end_inset 
8390
8391
8392 \begin_inset Foot
8393 collapsed false
8394
8395 \layout Standard
8396
8397 Not really meant as examples, but nevertheless showing what bitfields are
8398  about: device/include/mc68hc908qy.h and support/regression/tests/bitfields.c
8399 \end_inset 
8400
8401 .
8402  In accordance with ISO/IEC 9899 bits and bitfields without an explicit
8403  signed modifier are implemented as unsigned.
8404 \layout Subsubsection
8405
8406 sfr
8407 \begin_inset LatexCommand \index{sfr}
8408
8409 \end_inset 
8410
8411  / sbit
8412 \begin_inset LatexCommand \index{sbit}
8413
8414 \end_inset 
8415
8416
8417 \layout Standard
8418
8419 Like the bit keyword, 
8420 \emph on 
8421 sfr / sbit 
8422 \emph default 
8423 signifies both a data-type and storage class, they are used to describe
8424  the 
8425 \emph on 
8426 s
8427 \emph default 
8428 pecial 
8429 \emph on 
8430 f
8431 \emph default 
8432 unction 
8433 \emph on 
8434 r
8435 \emph default 
8436 egisters and 
8437 \emph on 
8438 s
8439 \emph default 
8440 pecial 
8441 \emph on 
8442 bit
8443 \emph default 
8444  variables of a 8051, eg:
8445 \layout Verse
8446
8447
8448 \family typewriter 
8449 sfr at
8450 \begin_inset LatexCommand \index{at}
8451
8452 \end_inset 
8453
8454  0x80 P0;\SpecialChar ~
8455  /* special function register P0 at location 0x80 */
8456 \newline 
8457 sbit at 0xd7 CY; /* CY (Carry Flag
8458 \begin_inset LatexCommand \index{Flags}
8459
8460 \end_inset 
8461
8462
8463 \begin_inset LatexCommand \index{Carry flag}
8464
8465 \end_inset 
8466
8467 ) */
8468 \layout Standard
8469
8470 Special function registers which are located on an address dividable by
8471  8 are bit-addressable, an
8472 \emph on 
8473  sbit
8474 \emph default 
8475  addresses a specific bit within these sfr.
8476 \layout Subsubsection
8477
8478 Pointers
8479 \begin_inset LatexCommand \index{Pointer}
8480
8481 \end_inset 
8482
8483  to MCS51/DS390 specific memory spaces
8484 \layout Standard
8485
8486 SDCC allows (via language extensions) pointers to explicitly point to any
8487  of the memory spaces
8488 \begin_inset LatexCommand \index{Memory model}
8489
8490 \end_inset 
8491
8492  of the 8051.
8493  In addition to the explicit pointers, the compiler uses (by default) generic
8494  pointers which can be used to point to any of the memory spaces.
8495 \newline 
8496
8497 \newline 
8498 Pointer declaration examples:
8499 \layout Verse
8500
8501
8502 \family typewriter 
8503 /* pointer physically in internal ram pointing to object in external ram
8504  */ 
8505 \newline 
8506 xdata unsigned char * data p;
8507 \newline 
8508
8509 \newline 
8510 /* pointer physically in external ram pointing to object in internal ram
8511  */ 
8512 \newline 
8513 data unsigned char * xdata p;
8514 \newline 
8515
8516 \newline 
8517 /* pointer physically in code rom pointing to data in xdata space */ 
8518 \newline 
8519 xdata unsigned char * code p;
8520 \newline 
8521
8522 \newline 
8523 /* pointer physically in code space pointing to data in code space */ 
8524 \newline 
8525 code unsigned char * code p;
8526 \newline 
8527
8528 \newline 
8529 /* the following is a generic pointer physically located in xdata space
8530  */
8531 \newline 
8532 char * xdata p;
8533 \layout Standard
8534
8535 Well you get the idea.
8536  
8537 \newline 
8538
8539 \newline 
8540 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
8541 \emph on 
8542 generic
8543 \emph default 
8544  pointers.
8545  
8546 \size small 
8547
8548 \newline 
8549
8550 \newline 
8551
8552 \size default 
8553 The highest order byte of the 
8554 \emph on 
8555 generic
8556 \emph default 
8557  pointers contains the data space information.
8558  Assembler support routines are called whenever data is stored or retrieved
8559  using 
8560 \emph on 
8561 generic
8562 \emph default 
8563  pointers.
8564  These are useful for developing reusable library
8565 \begin_inset LatexCommand \index{Libraries}
8566
8567 \end_inset 
8568
8569  routines.
8570  Explicitly specifying the pointer type will generate the most efficient
8571  code.
8572 \layout Subsubsection
8573
8574 Notes on MCS51 memory
8575 \begin_inset LatexCommand \index{MCS51 memory}
8576
8577 \end_inset 
8578
8579  layout
8580 \layout Standard
8581
8582 The 8051 family of microcontrollers have a minimum of 128 bytes of internal
8583  RAM memory which is structured as follows:
8584 \newline 
8585
8586 \newline 
8587 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R0 to R7,
8588  
8589 \newline 
8590 - Bytes 20-2F - 16 bytes to hold 128 bit
8591 \begin_inset LatexCommand \index{bit}
8592
8593 \end_inset 
8594
8595  variables and, 
8596 \newline 
8597 - Bytes 30-7F - 80 bytes for general purpose use.
8598 \newline 
8599
8600 \layout Standard
8601
8602 Additionally some members of the MCS51 family may have up to 128 bytes of
8603  additional, indirectly addressable, internal RAM memory (
8604 \emph on 
8605 idata
8606 \emph default 
8607
8608 \begin_inset LatexCommand \index{idata (mcs51, ds390 storage class)}
8609
8610 \end_inset 
8611
8612 ).
8613  Furthermore, some chips may have some built in external memory (
8614 \emph on 
8615 xdata
8616 \emph default 
8617
8618 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
8619
8620 \end_inset 
8621
8622 ) which should not be confused with the internal, directly addressable RAM
8623  memory (
8624 \emph on 
8625 data
8626 \emph default 
8627
8628 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
8629
8630 \end_inset 
8631
8632 ).
8633  Sometimes this built in 
8634 \emph on 
8635 xdata
8636 \emph default 
8637  memory has to be activated before using it (you can probably find this
8638  information on the datasheet of the microcontroller your are using, see
8639  also section 
8640 \begin_inset LatexCommand \ref{sub:Startup-Code}
8641
8642 \end_inset 
8643
8644 \SpecialChar ~
8645 Startup-Code).
8646 \layout Standard
8647
8648 Normally SDCC will only use the first bank
8649 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
8650
8651 \end_inset 
8652
8653  of registers (register bank 0), but it is possible to specify that other
8654  banks of registers should be used in interrupt
8655 \begin_inset LatexCommand \index{interrupt}
8656
8657 \end_inset 
8658
8659  routines.
8660  By default, the compiler will place the stack after the last byte of allocated
8661  memory for variables.
8662  For example, if the first 2 banks of registers are used, and only four
8663  bytes are used for 
8664 \emph on 
8665 data
8666 \emph default 
8667  variables, it will position the base of the internal stack at address 20
8668  (0x14).
8669  This implies that as the stack
8670 \begin_inset LatexCommand \index{stack}
8671
8672 \end_inset 
8673
8674  grows, it will use up the remaining register banks, and the 16 bytes used
8675  by the 128 bit variables, and 80 bytes for general purpose use.
8676  If any bit variables are used, the data variables will be placed after
8677  the byte holding the last bit variable.
8678  For example, if register banks 0 and 1 are used, and there are 9 bit variables
8679  (two bytes used), 
8680 \emph on 
8681 data
8682 \emph default 
8683  variables will be placed starting at address 0x22.
8684  You can also use -
8685 \begin_inset ERT
8686 status Collapsed
8687
8688 \layout Standard
8689
8690 \backslash 
8691 /
8692 \end_inset 
8693
8694 -data-loc
8695 \begin_inset LatexCommand \index{-\/-data-loc<Value>}
8696
8697 \end_inset 
8698
8699  to specify the start address of the 
8700 \emph on 
8701 data
8702 \emph default 
8703  and -
8704 \begin_inset ERT
8705 status Collapsed
8706
8707 \layout Standard
8708
8709 \backslash 
8710 /
8711 \end_inset 
8712
8713 -iram-size to specify the size of the total internal RAM (
8714 \emph on 
8715 data
8716 \emph default 
8717 +
8718 \emph on 
8719 idata
8720 \emph default 
8721 ).
8722  
8723 \layout Standard
8724
8725 By default the 8051 linker will place the stack after the last byte of data
8726  variables.
8727  Option -
8728 \begin_inset ERT
8729 status Collapsed
8730
8731 \layout Standard
8732
8733 \backslash 
8734 /
8735 \end_inset 
8736
8737 -stack-loc
8738 \begin_inset LatexCommand \index{-\/-stack-loc<Value>}
8739
8740 \end_inset 
8741
8742  allows you to specify the start of the stack, i.e.
8743  you could start it after any data in the general purpose area.
8744  If your microcontroller has additional indirectly addressable internal
8745  RAM (
8746 \emph on 
8747 idata
8748 \emph default 
8749 ) you can place the stack on it.
8750  You may also need to use -
8751 \begin_inset ERT
8752 status Collapsed
8753
8754 \layout Standard
8755
8756 \backslash 
8757 /
8758 \end_inset 
8759
8760 -xdata-loc
8761 \begin_inset LatexCommand \index{-\/-xdata-loc<Value>}
8762
8763 \end_inset 
8764
8765  to set the start address of the external RAM (
8766 \emph on 
8767 xdata
8768 \emph default 
8769 ) and -
8770 \begin_inset ERT
8771 status Collapsed
8772
8773 \layout Standard
8774
8775 \backslash 
8776 /
8777 \end_inset 
8778
8779 -xram-size
8780 \begin_inset LatexCommand \index{-\/-data-loc}
8781
8782 \end_inset 
8783
8784  to specify its size.
8785  Same goes for the code memory, using -
8786 \begin_inset ERT
8787 status Collapsed
8788
8789 \layout Standard
8790
8791 \backslash 
8792 /
8793 \end_inset 
8794
8795 -code-loc
8796 \begin_inset LatexCommand \index{-\/-data-loc}
8797
8798 \end_inset 
8799
8800  and -
8801 \begin_inset ERT
8802 status Collapsed
8803
8804 \layout Standard
8805
8806 \backslash 
8807 /
8808 \end_inset 
8809
8810 -code-size
8811 \begin_inset LatexCommand \index{-\/-data-loc}
8812
8813 \end_inset 
8814
8815 .
8816  If in doubt, don't specify any options and see if the resulting memory
8817  layout is appropriate, then you can adjust it.
8818 \layout Standard
8819
8820 The linker generates two files with memory allocation information.
8821  The first, with extension .map
8822 \begin_inset LatexCommand \index{<file>.map}
8823
8824 \end_inset 
8825
8826  shows all the variables and segments.
8827  The second with extension .mem
8828 \begin_inset LatexCommand \index{<file>.mem}
8829
8830 \end_inset 
8831
8832  shows the final memory layout.
8833  The linker will complain either if memory segments overlap, there is not
8834  enough memory, or there is not enough space for stack.
8835  If you get any linking warnings and/or errors related to stack or segments
8836  allocation, take a look at either the .map or .mem files to find out what
8837  the problem is.
8838  The .mem file may even suggest a solution to the problem.
8839 \layout Subsection
8840
8841 Z80/Z180 Storage Class
8842 \begin_inset LatexCommand \index{Storage class}
8843
8844 \end_inset 
8845
8846  Language Extensions
8847 \layout Subsubsection
8848
8849 sfr
8850 \begin_inset LatexCommand \index{sfr}
8851
8852 \end_inset 
8853
8854  (in/out to 8-bit addresses)
8855 \layout Standard
8856
8857 The Z80
8858 \begin_inset LatexCommand \index{Z80}
8859
8860 \end_inset 
8861
8862  family has separate address spaces for memory and 
8863 \emph on 
8864 i
8865 \emph default 
8866 nput/
8867 \emph on 
8868 o
8869 \emph default 
8870 utput memory.
8871  I/O memory
8872 \begin_inset LatexCommand \index{I/O memory (Z80, Z180)}
8873
8874 \end_inset 
8875
8876  is accessed with special instructions, e.g.:
8877 \layout Verse
8878
8879
8880 \family typewriter 
8881 sfr at 0x78 IoPort;\SpecialChar ~
8882 \SpecialChar ~
8883 /* define a var in I/O space at 78h called IoPort */
8884  
8885 \layout Standard
8886
8887 Writing 0x01 to this variable generates the assembly code:
8888 \layout Verse
8889
8890
8891 \family typewriter 
8892 3E 01\SpecialChar ~
8893 \SpecialChar ~
8894 \SpecialChar ~
8895 \SpecialChar ~
8896 \SpecialChar ~
8897 \SpecialChar ~
8898 ld a,#0x01
8899 \newline 
8900 D3 78\SpecialChar ~
8901 \SpecialChar ~
8902 \SpecialChar ~
8903 \SpecialChar ~
8904 \SpecialChar ~
8905 \SpecialChar ~
8906 out (_IoPort),a 
8907 \layout Subsubsection
8908
8909 banked sfr
8910 \begin_inset LatexCommand \index{sfr}
8911
8912 \end_inset 
8913
8914  (in/out to 16-bit addresses)
8915 \layout Standard
8916
8917 The keyword 
8918 \emph on 
8919 banked
8920 \emph default 
8921  is used to support 16 bit addresses in I/O memory e.g.:
8922 \layout Verse
8923
8924
8925 \family typewriter 
8926 sfr banked at
8927 \begin_inset LatexCommand \index{at}
8928
8929 \end_inset 
8930
8931  0x123 IoPort; 
8932 \layout Standard
8933
8934 Writing 0x01 to this variable generates the assembly code:
8935 \layout Verse
8936
8937
8938 \family typewriter 
8939 01 23 01\SpecialChar ~
8940 \SpecialChar ~
8941 \SpecialChar ~
8942 ld bc,#_IoPort
8943 \newline 
8944 3E 01\SpecialChar ~
8945 \SpecialChar ~
8946 \SpecialChar ~
8947 \SpecialChar ~
8948 \SpecialChar ~
8949 \SpecialChar ~
8950 ld a,#0x01 
8951 \newline 
8952 ED 79\SpecialChar ~
8953 \SpecialChar ~
8954 \SpecialChar ~
8955 \SpecialChar ~
8956 \SpecialChar ~
8957 \SpecialChar ~
8958 out (c),a 
8959 \layout Subsubsection
8960
8961 sfr
8962 \begin_inset LatexCommand \index{sfr}
8963
8964 \end_inset 
8965
8966  (in0/out0 to 8 bit addresses on Z180
8967 \begin_inset LatexCommand \index{Z180}
8968
8969 \end_inset 
8970
8971 /HD64180
8972 \begin_inset LatexCommand \index{HD64180}
8973
8974 \end_inset 
8975
8976 )
8977 \layout Standard
8978
8979 The compiler option -
8980 \begin_inset ERT
8981 status Collapsed
8982
8983 \layout Standard
8984
8985 \backslash 
8986 /
8987 \end_inset 
8988
8989 -portmode=180 (80) and a compiler #pragma\SpecialChar ~
8990 portmode
8991 \begin_inset LatexCommand \index{\#pragma portmode}
8992
8993 \end_inset 
8994
8995 =z180 (z80) is used to turn on (off) the Z180/HD64180 port addressing instructio
8996 ns 
8997 \family typewriter 
8998 in0/out0
8999 \family default 
9000  instead of 
9001 \family typewriter 
9002 in/out
9003 \family default 
9004 .
9005  If you include the file z180.h this will be set automatically.
9006 \layout Subsection
9007
9008 HC08 Storage Class
9009 \begin_inset LatexCommand \index{Storage class}
9010
9011 \end_inset 
9012
9013  Language Extensions
9014 \layout Subsubsection
9015
9016 data
9017 \begin_inset LatexCommand \index{data (mcs51, ds390 storage class)}
9018
9019 \end_inset 
9020
9021
9022 \layout Standard
9023
9024 The data storage class declares a variable that resides in the first 256
9025  bytes of memory (the direct page).
9026  The HC08 is most efficient at accessing variables (especially pointers)
9027  stored here.
9028 \layout Subsubsection
9029
9030 xdata
9031 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9032
9033 \end_inset 
9034
9035
9036 \layout Standard
9037
9038 The xdata storage class declares a variable that can reside anywhere in
9039  memory.
9040  This is the default if no storage class is specified.
9041  
9042 \layout Section
9043
9044 Absolute Addressing
9045 \begin_inset LatexCommand \index{Absolute addressing}
9046
9047 \end_inset 
9048
9049
9050 \layout Standard
9051
9052 Data items can be assigned an absolute address with the 
9053 \emph on 
9054 at
9055 \begin_inset LatexCommand \index{at}
9056
9057 \end_inset 
9058
9059  <address>
9060 \emph default 
9061  keyword, in addition to a storage class, e.g.:
9062 \layout Verse
9063
9064
9065 \family typewriter 
9066 xdata
9067 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9068
9069 \end_inset 
9070
9071  at
9072 \begin_inset LatexCommand \index{at}
9073
9074 \end_inset 
9075
9076  0x7ffe unsigned int chksum;
9077 \layout Standard
9078
9079 In the above example the variable chksum will located at 0x7ffe and 0x7fff
9080  of the external ram.
9081  The compiler does 
9082 \emph on 
9083 not
9084 \emph default 
9085  reserve any space for variables declared in this way (they are implemented
9086  with an equate in the assembler).
9087  Thus it is left to the programmer to make sure there are no overlaps with
9088  other variables that are declared without the absolute address.
9089  The assembler listing file (.lst
9090 \begin_inset LatexCommand \index{<file>.lst}
9091
9092 \end_inset 
9093
9094 ) and the linker output files (.rst
9095 \begin_inset LatexCommand \index{<file>.rst}
9096
9097 \end_inset 
9098
9099 ) and (.map
9100 \begin_inset LatexCommand \index{<file>.map}
9101
9102 \end_inset 
9103
9104 ) are good places to look for such overlaps.
9105  Variables with an absolute address are 
9106 \emph on 
9107 not
9108 \emph default 
9109  initialized
9110 \begin_inset LatexCommand \index{Variable initialization}
9111
9112 \end_inset 
9113
9114 .
9115 \layout Standard
9116
9117 In case of memory mapped I/O devices the keyword 
9118 \emph on 
9119 volatile
9120 \emph default 
9121  have to be used to tell the compiler that accesses might not be optimized
9122  away:
9123 \layout Verse
9124
9125
9126 \family typewriter 
9127 volatile
9128 \begin_inset LatexCommand \index{volatile}
9129
9130 \end_inset 
9131
9132  xdata
9133 \begin_inset LatexCommand \index{xdata (mcs51, ds390 storage class)}
9134
9135 \end_inset 
9136
9137  at
9138 \begin_inset LatexCommand \index{at}
9139
9140 \end_inset 
9141
9142  0x8000 unsigned char PORTA_8255;
9143 \layout Standard
9144
9145 For some architectures (mcs51) array accesses are more efficient if an (xdata/fa
9146 r) array
9147 \family typewriter 
9148 \size footnotesize 
9149
9150 \begin_inset LatexCommand \index{Aligned array}
9151
9152 \end_inset 
9153
9154
9155 \family default 
9156 \size default 
9157  starts at a block (256 byte) boundary
9158 \begin_inset LatexCommand \index{block boundary}
9159
9160 \end_inset 
9161
9162  (section 
9163 \begin_inset LatexCommand \ref{sub:A-Step-by Assembler Introduction}
9164
9165 \end_inset 
9166
9167  has an example).
9168 \newline 
9169 Absolute addresses can be specified for variables in all storage classes,
9170  e.g.:
9171 \layout Verse
9172
9173
9174 \family typewriter 
9175 bit
9176 \begin_inset LatexCommand \index{bit}
9177
9178 \end_inset 
9179
9180  at
9181 \begin_inset LatexCommand \index{at}
9182
9183 \end_inset 
9184
9185  0x02 bvar;
9186 \layout Standard
9187
9188 The above example will allocate the variable at offset 0x02 in the bit-addressab
9189 le space.
9190  There is no real advantage to assigning absolute addresses to variables
9191  in this manner, unless you want strict control over all the variables allocated.
9192  One possible use would be to write hardware portable code.
9193  For example, if you have a routine that uses one or more of the microcontroller
9194  I/O pins, and such pins are different for two different hardwares, you
9195  can declare the I/O pins in your routine using:
9196 \layout Verse
9197
9198
9199 \family typewriter 
9200 extern volatile bit MOSI;\SpecialChar ~
9201 \SpecialChar ~
9202 \SpecialChar ~
9203 \SpecialChar ~
9204 /* master out, slave in */
9205 \newline 
9206 extern volatile bit MISO;\SpecialChar ~
9207 \SpecialChar ~
9208 \SpecialChar ~
9209 \SpecialChar ~
9210 /* master in, slave out */
9211 \newline 
9212 extern volatile bit MCLK;\SpecialChar ~
9213 \SpecialChar ~
9214 \SpecialChar ~
9215 \SpecialChar ~
9216 /* master clock */
9217 \newline 
9218
9219 \newline 
9220 /* Input and Output of a byte on a 3-wire serial bus.
9221 \newline 
9222 \SpecialChar ~
9223 \SpecialChar ~
9224 \SpecialChar ~
9225 If needed adapt polarity of clock, polarity of data and bit order
9226 \newline 
9227 \SpecialChar ~
9228 */
9229 \newline 
9230 unsigned char spi_io(unsigned char out_byte) 
9231 \newline 
9232
9233 \newline 
9234 \SpecialChar ~
9235 \SpecialChar ~
9236 \SpecialChar ~
9237 \SpecialChar ~
9238 unsigned char i=8;
9239 \newline 
9240 \SpecialChar ~
9241 \SpecialChar ~
9242 \SpecialChar ~
9243 \SpecialChar ~
9244 do { 
9245 \newline 
9246 \SpecialChar ~
9247 \SpecialChar ~
9248 \SpecialChar ~
9249 \SpecialChar ~
9250 \SpecialChar ~
9251 \SpecialChar ~
9252 \SpecialChar ~
9253 \SpecialChar ~
9254 MOSI = out_byte & 0x80; 
9255 \newline 
9256 \SpecialChar ~
9257 \SpecialChar ~
9258 \SpecialChar ~
9259 \SpecialChar ~
9260 \SpecialChar ~
9261 \SpecialChar ~
9262 \SpecialChar ~
9263 \SpecialChar ~
9264 out_byte <<= 1;
9265 \newline 
9266 \SpecialChar ~
9267 \SpecialChar ~
9268 \SpecialChar ~
9269 \SpecialChar ~
9270 \SpecialChar ~
9271 \SpecialChar ~
9272 \SpecialChar ~
9273 \SpecialChar ~
9274 MCLK = 1; 
9275 \newline 
9276 \SpecialChar ~
9277 \SpecialChar ~
9278 \SpecialChar ~
9279 \SpecialChar ~
9280 \SpecialChar ~
9281 \SpecialChar ~
9282 \SpecialChar ~
9283 \SpecialChar ~
9284 /* _asm nop _endasm; */\SpecialChar ~
9285 \SpecialChar ~
9286 \SpecialChar ~
9287 \SpecialChar ~
9288 \SpecialChar ~
9289 \SpecialChar ~
9290 \SpecialChar ~
9291 \SpecialChar ~
9292 /* for slow peripherals */
9293 \newline 
9294 \SpecialChar ~
9295 \SpecialChar ~
9296 \SpecialChar ~
9297 \SpecialChar ~
9298 \SpecialChar ~
9299 \SpecialChar ~
9300 \SpecialChar ~
9301 \SpecialChar ~
9302 if(MISO) 
9303 \newline 
9304 \SpecialChar ~
9305 \SpecialChar ~
9306 \SpecialChar ~
9307 \SpecialChar ~
9308 \SpecialChar ~
9309 \SpecialChar ~
9310 \SpecialChar ~
9311 \SpecialChar ~
9312 \SpecialChar ~
9313 \SpecialChar ~
9314 \SpecialChar ~
9315 \SpecialChar ~
9316 out_byte += 1; 
9317 \newline 
9318 \SpecialChar ~
9319 \SpecialChar ~
9320 \SpecialChar ~
9321 \SpecialChar ~
9322 \SpecialChar ~
9323 \SpecialChar ~
9324 \SpecialChar ~
9325 \SpecialChar ~
9326 MCLK = 0; 
9327 \newline 
9328 \SpecialChar ~
9329 \SpecialChar ~
9330 \SpecialChar ~
9331 \SpecialChar ~
9332 } while(--i);
9333 \newline 
9334 \SpecialChar ~
9335 \SpecialChar ~
9336 \SpecialChar ~
9337 \SpecialChar ~
9338 return out_byte; 
9339 \newline 
9340 }
9341 \layout Standard
9342
9343 Then, someplace in the code for the first hardware you would use
9344 \layout Verse
9345
9346
9347 \family typewriter 
9348 bit at 0x80 MOSI;\SpecialChar ~
9349 \SpecialChar ~
9350 \SpecialChar ~
9351 \SpecialChar ~
9352 /* I/O port 0, bit 0 */
9353 \newline 
9354 bit at 0x81 MISO;\SpecialChar ~
9355 \SpecialChar ~
9356 \SpecialChar ~
9357 \SpecialChar ~
9358 /* I/O port 0, bit 1 */
9359 \newline 
9360 bit at 0x82 MCLK;\SpecialChar ~
9361 \SpecialChar ~
9362 \SpecialChar ~
9363 \SpecialChar ~
9364 /* I/O port 0, bit 2 */
9365 \layout Standard
9366
9367 Similarly, for the second hardware you would use
9368 \layout Verse
9369
9370
9371 \family typewriter 
9372 bit at 0x83 MOSI;\SpecialChar ~
9373 \SpecialChar ~
9374 \SpecialChar ~
9375 \SpecialChar ~
9376 /* I/O port 0, bit 3 */
9377 \newline 
9378 bit at 0x91 MISO;\SpecialChar ~
9379 \SpecialChar ~
9380 \SpecialChar ~
9381 \SpecialChar ~
9382 /* I/O port 1, bit 1 */
9383 \newline 
9384 bit
9385 \begin_inset LatexCommand \index{bit}
9386
9387 \end_inset 
9388
9389  at 0x92 MCLK;\SpecialChar ~
9390 \SpecialChar ~
9391 \SpecialChar ~
9392 \SpecialChar ~
9393 /* I/O port 1, bit 2 */
9394 \layout Standard
9395
9396 and you can use the same hardware dependent routine without changes, as
9397  for example in a library.
9398  This is somehow similar to sbit, but only one absolute address has to be
9399  specified in the whole project.
9400 \layout Section
9401
9402 Parameters
9403 \begin_inset LatexCommand \index{Parameters}
9404
9405 \end_inset 
9406
9407
9408 \begin_inset LatexCommand \index{function parameter}
9409
9410 \end_inset 
9411
9412  & Local Variables
9413 \begin_inset LatexCommand \index{local variables}
9414
9415 \end_inset 
9416
9417
9418 \begin_inset LatexCommand \label{sec:Parameters-and-Local-Variables}
9419
9420 \end_inset 
9421
9422
9423 \layout Standard
9424
9425 Automatic (local) variables and parameters to functions can either be placed
9426  on the stack or in data-space.
9427  The default action of the compiler is to place these variables in the internal
9428  RAM (for small model) or external RAM (for large model).
9429  This in fact makes them similar to 
9430 \emph on 
9431 static
9432 \begin_inset LatexCommand \index{static}
9433
9434 \end_inset 
9435
9436
9437 \emph default 
9438  so by default functions are non-reentrant
9439 \begin_inset LatexCommand \index{reentrant}
9440
9441 \end_inset 
9442
9443 .
9444  
9445 \newline 
9446
9447 \newline 
9448 They can be placed on the stack
9449 \begin_inset LatexCommand \index{stack}
9450
9451 \end_inset 
9452
9453  by using the
9454 \emph on 
9455  -
9456 \begin_inset ERT
9457 status Collapsed
9458
9459 \layout Standard
9460
9461 \backslash 
9462 /
9463 \end_inset 
9464
9465 -stack-auto
9466 \begin_inset LatexCommand \index{-\/-stack-auto}
9467
9468 \end_inset 
9469
9470
9471 \emph default 
9472  option, by using 
9473 \emph on 
9474 #pragma\SpecialChar ~
9475 stackauto
9476 \emph default 
9477
9478 \begin_inset LatexCommand \index{\#pragma stackauto}
9479
9480 \end_inset 
9481
9482  or by using the 
9483 \emph on 
9484 reentrant
9485 \begin_inset LatexCommand \index{reentrant}
9486
9487 \end_inset 
9488
9489
9490 \emph default 
9491  keyword in the function declaration, e.g.:
9492 \layout Verse
9493
9494
9495 \family typewriter 
9496 unsigned char foo(char i) reentrant 
9497 \newline 
9498
9499 \newline 
9500 \SpecialChar ~
9501 \SpecialChar ~
9502 \SpecialChar ~
9503 \SpecialChar ~
9504 ...
9505  
9506 \newline 
9507 }
9508 \layout Standard
9509
9510 Since stack space on 8051 is limited, the 
9511 \emph on 
9512 reentrant 
9513 \emph default 
9514 keyword or the
9515 \emph on 
9516  -
9517 \begin_inset ERT
9518 status Collapsed
9519
9520 \layout Standard
9521
9522 \backslash 
9523 /
9524 \end_inset 
9525
9526 -stack-auto
9527 \emph default 
9528  option should be used sparingly.
9529  Note that the reentrant keyword just means that the parameters & local
9530  variables will be allocated to the stack, it 
9531 \emph on 
9532 does not
9533 \emph default 
9534  mean that the function is register bank
9535 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
9536
9537 \end_inset 
9538
9539  independent.
9540 \newline 
9541
9542 \newline 
9543 Local variables
9544 \begin_inset LatexCommand \index{local variables}
9545
9546 \end_inset 
9547
9548  can be assigned storage classes and absolute
9549 \begin_inset LatexCommand \index{Absolute addressing}
9550
9551 \end_inset 
9552
9553  addresses, e.g.: 
9554 \layout Verse
9555
9556
9557 \family typewriter 
9558 unsigned char foo() 
9559 \newline 
9560 {
9561 \newline 
9562 \SpecialChar ~
9563 \SpecialChar ~
9564 \SpecialChar ~
9565 \SpecialChar ~
9566 xdata unsigned char i;
9567 \newline 
9568 \SpecialChar ~
9569 \SpecialChar ~
9570 \SpecialChar ~
9571 \SpecialChar ~
9572 bit bvar;
9573 \newline 
9574 \SpecialChar ~
9575 \SpecialChar ~
9576 \SpecialChar ~
9577 \SpecialChar ~
9578 data at
9579 \begin_inset LatexCommand \index{at}
9580
9581 \end_inset 
9582
9583  0x31 unsigned char j;
9584 \newline 
9585 \SpecialChar ~
9586 \SpecialChar ~
9587 \SpecialChar ~
9588 \SpecialChar ~
9589 ...
9590  
9591 \newline 
9592 }
9593 \layout Standard
9594
9595 In the above example the variable 
9596 \emph on 
9597 i
9598 \emph default 
9599  will be allocated in the external ram, 
9600 \emph on 
9601 bvar
9602 \emph default 
9603  in bit addressable space and
9604 \emph on 
9605  j
9606 \emph default 
9607  in internal ram.
9608  When compiled with 
9609 \emph on 
9610 -
9611 \begin_inset ERT
9612 status Collapsed
9613
9614 \layout Standard
9615
9616 \backslash 
9617 /
9618 \end_inset 
9619
9620 -stack-auto
9621 \emph default 
9622  or when a function is declared as 
9623 \emph on 
9624 reentrant
9625 \emph default 
9626  this should only be done for static variables.
9627 \layout Standard
9628
9629 Parameters
9630 \begin_inset LatexCommand \index{function parameter}
9631
9632 \end_inset 
9633
9634  however are not allowed any storage class
9635 \begin_inset LatexCommand \index{Storage class}
9636
9637 \end_inset 
9638
9639 , (storage classes for parameters will be ignored), their allocation is
9640  governed by the memory model in use, and the reentrancy options.
9641 \layout Section
9642
9643 Overlaying
9644 \begin_inset LatexCommand \label{sub:Overlaying}
9645
9646 \end_inset 
9647
9648
9649 \begin_inset LatexCommand \index{Overlaying}
9650
9651 \end_inset 
9652
9653
9654 \layout Standard
9655
9656 For non-reentrant
9657 \begin_inset LatexCommand \index{reentrant}
9658
9659 \end_inset 
9660
9661  functions SDCC will try to reduce internal ram space usage by overlaying
9662  parameters and local variables of a function (if possible).
9663  Parameters and local variables
9664 \begin_inset LatexCommand \index{local variables}
9665
9666 \end_inset 
9667
9668  of a function will be allocated to an overlayable segment if the function
9669  has 
9670 \emph on 
9671 no other function calls and the function is non-reentrant and the memory
9672  model
9673 \begin_inset LatexCommand \index{Memory model}
9674
9675 \end_inset 
9676
9677  is small.
9678
9679 \emph default 
9680  If an explicit storage class
9681 \begin_inset LatexCommand \index{Storage class}
9682
9683 \end_inset 
9684
9685  is specified for a local variable, it will NOT be overlayed.
9686 \layout Standard
9687
9688 Note that the compiler (not the linkage editor) makes the decision for overlayin
9689 g the data items.
9690  Functions that are called from an interrupt service routine should be preceded
9691  by a #pragma\SpecialChar ~
9692 nooverlay
9693 \begin_inset LatexCommand \index{\#pragma nooverlay}
9694
9695 \end_inset 
9696
9697  if they are not reentrant.
9698 \layout Standard
9699
9700 Also note that the compiler does not do any processing of inline assembler
9701  code, so the compiler might incorrectly assign local variables and parameters
9702  of a function into the overlay segment if the inline assembler code calls
9703  other c-functions that might use the overlay.
9704  In that case the #pragma\SpecialChar ~
9705 nooverlay should be used.
9706 \layout Standard
9707
9708 Parameters and local variables of functions that contain 16 or 32 bit multiplica
9709 tion
9710 \begin_inset LatexCommand \index{Multiplication}
9711
9712 \end_inset 
9713
9714  or division
9715 \begin_inset LatexCommand \index{Division}
9716
9717 \end_inset 
9718
9719  will NOT be overlayed since these are implemented using external functions,
9720  e.g.:
9721 \layout Verse
9722
9723
9724 \family typewriter 
9725 #pragma save 
9726 \newline 
9727 #pragma nooverlay
9728 \begin_inset LatexCommand \index{\#pragma nooverlay}
9729
9730 \end_inset 
9731
9732  
9733 \newline 
9734 void set_error(unsigned char errcd) 
9735 \newline 
9736 {
9737 \newline 
9738 \SpecialChar ~
9739 \SpecialChar ~
9740 \SpecialChar ~
9741 \SpecialChar ~
9742 P3 = errcd;
9743 \newline 
9744
9745 \newline 
9746 #pragma restore 
9747 \newline 
9748
9749 \newline 
9750 void some_isr () interrupt
9751 \begin_inset LatexCommand \index{interrupt}
9752
9753 \end_inset 
9754
9755  2
9756 \newline 
9757 {
9758 \newline 
9759 \SpecialChar ~
9760 \SpecialChar ~
9761 \SpecialChar ~
9762 \SpecialChar ~
9763 ...
9764 \newline 
9765 \SpecialChar ~
9766 \SpecialChar ~
9767 \SpecialChar ~
9768 \SpecialChar ~
9769 set_error(10);
9770 \newline 
9771 \SpecialChar ~
9772 \SpecialChar ~
9773 \SpecialChar ~
9774 \SpecialChar ~
9775 ...
9776  
9777 \newline 
9778 }
9779 \layout Standard
9780
9781 In the above example the parameter 
9782 \emph on 
9783 errcd
9784 \emph default 
9785  for the function 
9786 \emph on 
9787 set_error
9788 \emph default 
9789  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
9790 nooverlay was
9791  not present, this could cause unpredictable runtime behavior when called
9792  from an interrupt service routine.
9793  The #pragma\SpecialChar ~
9794 nooverlay ensures that the parameters and local variables for
9795  the function are NOT overlayed.
9796 \layout Section
9797
9798 Interrupt Service Routines
9799 \begin_inset LatexCommand \label{sub:Interrupt-Service-Routines}
9800
9801 \end_inset 
9802
9803
9804 \layout Subsection
9805
9806 General Information
9807 \layout Standard
9808
9809 SDCC allows 
9810 \emph on 
9811 i
9812 \emph default 
9813 nterrupt 
9814 \emph on 
9815 s
9816 \emph default 
9817 ervice 
9818 \emph on 
9819 r
9820 \emph default 
9821 outines to be coded in C, with some extended keywords.
9822 \layout Verse
9823
9824
9825 \family typewriter 
9826 void timer_isr (void) interrupt 1 using 1 
9827 \newline 
9828
9829 \newline 
9830 \SpecialChar ~
9831 \SpecialChar ~
9832 \SpecialChar ~
9833 \SpecialChar ~
9834 ...
9835  
9836 \newline 
9837 }
9838 \layout Standard
9839
9840 The optional number following the 
9841 \emph on 
9842 interrupt
9843 \begin_inset LatexCommand \index{interrupt}
9844
9845 \end_inset 
9846
9847
9848 \emph default 
9849  keyword is the interrupt number this routine will service.
9850  When present, the compiler will insert a call to this routine in the interrupt
9851  vector table for the interrupt number specified.
9852  If you have multiple source files in your project, interrupt service routines
9853  can be present in any of them, but a prototype of the isr MUST be present
9854  or included in the file that contains the function 
9855 \emph on 
9856 main
9857 \emph default 
9858 .
9859  The 
9860 \emph on 
9861 using
9862 \emph default 
9863  keyword can be used to tell the compiler to use the specified register
9864  bank (8051 specific) when generating code for this function.
9865  
9866 \newline 
9867
9868 \layout Standard
9869
9870 Interrupt service routines open the door for some very interesting bugs:
9871 \newline 
9872 If an interrupt service routine changes variables which are accessed by
9873  other functions these variables have to be declared 
9874 \emph on 
9875 volatile
9876 \emph default 
9877
9878 \begin_inset LatexCommand \index{volatile}
9879
9880 \end_inset 
9881
9882 .
9883  
9884 \layout Standard
9885
9886 If the access to these variables is not 
9887 \emph on 
9888 atomic
9889 \begin_inset LatexCommand \index{atomic access}
9890
9891 \end_inset 
9892
9893
9894 \emph default 
9895  (i.e.
9896  the processor needs more than one instruction for the access and could
9897  be interrupted while accessing the variable) the interrupt must be disabled
9898  during the access to avoid inconsistent data.
9899  Access to 16 or 32 bit variables is obviously not atomic on 8 bit CPUs
9900  and should be protected by disabling interrupts.
9901  You're not automatically on the safe side if you use 8 bit variables though.
9902  We need an example here: f.e.
9903  on the 8051 the harmless looking 
9904 \begin_inset Quotes srd
9905 \end_inset 
9906
9907
9908 \family typewriter 
9909 flags\SpecialChar ~
9910 |=\SpecialChar ~
9911 0x80;
9912 \family default 
9913
9914 \begin_inset Quotes sld
9915 \end_inset 
9916
9917  is not atomic if 
9918 \family typewriter 
9919 flags
9920 \family default 
9921  resides in xdata.
9922  Setting 
9923 \begin_inset Quotes srd
9924 \end_inset 
9925
9926
9927 \family typewriter 
9928 flags\SpecialChar ~
9929 |=\SpecialChar ~
9930 0x40;
9931 \family default 
9932
9933 \begin_inset Quotes sld
9934 \end_inset 
9935
9936  from within an interrupt routine might get lost if the interrupt occurs
9937  at the wrong time.
9938  
9939 \begin_inset Quotes sld
9940 \end_inset 
9941
9942
9943 \family typewriter 
9944 counter\SpecialChar ~
9945 +=\SpecialChar ~
9946 8;
9947 \family default 
9948
9949 \begin_inset Quotes srd
9950 \end_inset 
9951
9952  is not atomic on the 8051 even if 
9953 \family typewriter 
9954 counter
9955 \family default 
9956  is located in data memory.
9957  Bugs like these are hard to reproduce and can cause a lot of trouble.
9958  
9959 \layout Standard
9960
9961 The return address and the registers used in the interrupt service routine
9962  are saved on the stack
9963 \begin_inset LatexCommand \index{stack}
9964
9965 \end_inset 
9966
9967  so there must be sufficient stack space.
9968  If there isn't variables or registers (or even the return address itself)
9969  will be corrupted.
9970  This 
9971 \emph on 
9972 stack overflow
9973 \emph default 
9974
9975 \begin_inset LatexCommand \index{stack overflow}
9976
9977 \end_inset 
9978
9979  is most likely to happen if the interrupt occurs during the 
9980 \begin_inset Quotes sld
9981 \end_inset 
9982
9983 deepest
9984 \begin_inset Quotes srd
9985 \end_inset 
9986
9987  subroutine when the stack is already in use for f.e.
9988  many return addresses.
9989 \layout Standard
9990
9991 A special note here, int (16 bit) and long (32 bit) integer division
9992 \begin_inset LatexCommand \index{Division}
9993
9994 \end_inset 
9995
9996 , multiplication
9997 \begin_inset LatexCommand \index{Multiplication}
9998
9999 \end_inset 
10000
10001  & modulus
10002 \begin_inset LatexCommand \index{Modulus}
10003
10004 \end_inset 
10005
10006  and floating-point
10007 \begin_inset LatexCommand \index{Floating point support}
10008
10009 \end_inset 
10010
10011  operations are implemented using external support routines developed in
10012  ANSI-C.
10013  If an interrupt service routine needs to do any of these operations then
10014  the support routines (as mentioned in a following section) will have to
10015  be recompiled using the
10016 \emph on 
10017  -
10018 \begin_inset ERT
10019 status Collapsed
10020
10021 \layout Standard
10022
10023 \backslash 
10024 /
10025 \end_inset 
10026
10027 -stack-auto
10028 \begin_inset LatexCommand \index{-\/-stack-auto}
10029
10030 \end_inset 
10031
10032
10033 \emph default 
10034  option and the source file will need to be compiled using the 
10035 \emph on 
10036 -
10037 \begin_inset ERT
10038 status Collapsed
10039
10040 \layout Standard
10041
10042 \backslash 
10043 /
10044 \end_inset 
10045
10046 -int-long-reent
10047 \emph default 
10048
10049 \begin_inset LatexCommand \index{-\/-int-long-reent}
10050
10051 \end_inset 
10052
10053  compiler option.
10054 \layout Standard
10055
10056 Calling other functions from an interrupt service routine is not recommended,
10057  avoid it if possible.
10058  Note that when some function is called from an interrupt service routine
10059  it should be preceded by a #pragma\SpecialChar ~
10060 nooverlay
10061 \begin_inset LatexCommand \index{\#pragma nooverlay}
10062
10063 \end_inset 
10064
10065  if it is not reentrant.
10066  Furthermore nonreentrant functions should not be called from the main program
10067  while the interrupt service routine might be active.
10068  
10069 \newline 
10070
10071 \newline 
10072 Also see section 
10073 \begin_inset LatexCommand \ref{sub:Overlaying}
10074
10075 \end_inset 
10076
10077 \SpecialChar ~
10078 about Overlaying and section 
10079 \begin_inset LatexCommand \ref{sub:Functions-using-private-banks}
10080
10081 \end_inset 
10082
10083 \SpecialChar ~
10084 about Functions using private register banks.
10085 \layout Subsection
10086
10087 MCS51/DS390 Interrupt Service Routines
10088 \layout Standard
10089
10090 Interrupt numbers and the corresponding address & descriptions for the Standard
10091  8051/8052 are listed below.
10092  SDCC will automatically adjust the interrupt vector table to the maximum
10093  interrupt number specified.
10094 \newline 
10095
10096 \layout Standard
10097 \align center 
10098
10099 \begin_inset  Tabular
10100 <lyxtabular version="3" rows="7" columns="3">
10101 <features>
10102 <column alignment="center" valignment="top" leftline="true" width="0in">
10103 <column alignment="center" valignment="top" leftline="true" width="0in">
10104 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0in">
10105 <row topline="true" bottomline="true">
10106 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10107 \begin_inset Text
10108
10109 \layout Standard
10110
10111 Interrupt #
10112 \end_inset 
10113 </cell>
10114 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10115 \begin_inset Text
10116
10117 \layout Standard
10118
10119 Description
10120 \end_inset 
10121 </cell>
10122 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10123 \begin_inset Text
10124
10125 \layout Standard
10126
10127 Vector Address
10128 \end_inset 
10129 </cell>
10130 </row>
10131 <row topline="true">
10132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10133 \begin_inset Text
10134
10135 \layout Standard
10136
10137 0
10138 \end_inset 
10139 </cell>
10140 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10141 \begin_inset Text
10142
10143 \layout Standard
10144
10145 External 0
10146 \end_inset 
10147 </cell>
10148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10149 \begin_inset Text
10150
10151 \layout Standard
10152
10153 0x0003
10154 \end_inset 
10155 </cell>
10156 </row>
10157 <row topline="true">
10158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10159 \begin_inset Text
10160
10161 \layout Standard
10162
10163 1
10164 \end_inset 
10165 </cell>
10166 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10167 \begin_inset Text
10168
10169 \layout Standard
10170
10171 Timer 0
10172 \end_inset 
10173 </cell>
10174 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10175 \begin_inset Text
10176
10177 \layout Standard
10178
10179 0x000B
10180 \end_inset 
10181 </cell>
10182 </row>
10183 <row topline="true">
10184 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10185 \begin_inset Text
10186
10187 \layout Standard
10188
10189 2
10190 \end_inset 
10191 </cell>
10192 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10193 \begin_inset Text
10194
10195 \layout Standard
10196
10197 External 1
10198 \end_inset 
10199 </cell>
10200 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10201 \begin_inset Text
10202
10203 \layout Standard
10204
10205 0x0013
10206 \end_inset 
10207 </cell>
10208 </row>
10209 <row topline="true">
10210 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10211 \begin_inset Text
10212
10213 \layout Standard
10214
10215 3
10216 \end_inset 
10217 </cell>
10218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10219 \begin_inset Text
10220
10221 \layout Standard
10222
10223 Timer 1
10224 \end_inset 
10225 </cell>
10226 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10227 \begin_inset Text
10228
10229 \layout Standard
10230
10231 0x001B
10232 \end_inset 
10233 </cell>
10234 </row>
10235 <row topline="true">
10236 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10237 \begin_inset Text
10238
10239 \layout Standard
10240
10241 4
10242 \end_inset 
10243 </cell>
10244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10245 \begin_inset Text
10246
10247 \layout Standard
10248
10249 Serial
10250 \end_inset 
10251 </cell>
10252 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10253 \begin_inset Text
10254
10255 \layout Standard
10256
10257 0x0023
10258 \end_inset 
10259 </cell>
10260 </row>
10261 <row topline="true" bottomline="true">
10262 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10263 \begin_inset Text
10264
10265 \layout Standard
10266
10267 5
10268 \end_inset 
10269 </cell>
10270 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
10271 \begin_inset Text
10272
10273 \layout Standard
10274
10275 Timer 2 (8052)
10276 \end_inset 
10277 </cell>
10278 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
10279 \begin_inset Text
10280
10281 \layout Standard
10282
10283 0x002B
10284 \end_inset 
10285 </cell>
10286 </row>
10287 </lyxtabular>
10288
10289 \end_inset 
10290
10291
10292 \newline 
10293
10294 \layout Standard
10295
10296 If the interrupt service routine is defined without 
10297 \emph on 
10298 using
10299 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10300
10301 \end_inset 
10302
10303
10304 \emph default 
10305  a register bank or with register bank 0 (
10306 \emph on 
10307 using
10308 \emph default 
10309  0), the compiler will save the registers used by itself on the stack upon
10310  entry and restore them at exit, however if such an interrupt service routine
10311  calls another function then the entire register bank will be saved on the
10312  stack.
10313  This scheme may be advantageous for small interrupt service routines which
10314  have low register usage.
10315 \layout Standard
10316
10317 If the interrupt service routine is defined to be using a specific register
10318  bank then only 
10319 \emph on 
10320 a, b, dptr
10321 \emph default 
10322  & psw are saved and restored, if such an interrupt service routine calls
10323  another function (using another register bank) then the entire register
10324  bank of the called function will be saved on the stack.
10325  This scheme is recommended for larger interrupt service routines.
10326 \layout Subsection
10327
10328 HC08 Interrupt Service Routines
10329 \layout Standard
10330
10331 Since the number of interrupts available is chip specific and the interrupt
10332  vector table always ends at the last byte of memory, the interrupt numbers
10333  corresponds to the interrupt vectors in reverse order of address.
10334  For example, interrupt 1 will use the interrupt vector at 0xfffc, interrupt
10335  2 will use the interrupt vector at 0xfffa, and so on.
10336  However, interrupt 0 (the reset vector at 0xfffe) is not redefinable in
10337  this way; instead see section 
10338 \begin_inset LatexCommand \ref{sub:Startup-Code}
10339
10340 \end_inset 
10341
10342  for details on customizing startup.
10343 \layout Subsection
10344
10345 Z80 Interrupt Service Routines
10346 \layout Standard
10347
10348 The Z80 uses several different methods for determining the correct interrupt
10349  vector depending on the hardware implementation.
10350  Therefore, SDCC ignores the optional interrupt number and does not attempt
10351  to generate an interrupt vector table.
10352 \layout Standard
10353
10354 By default, SDCC generates code for a maskable interrupt, which uses an
10355  RETI instruction to return from the interrupt.
10356  To write an interrupt handler for the non-maskable interrupt, which needs
10357  an RETN instruction instead, add the 
10358 \emph on 
10359 critical
10360 \emph default 
10361  keyword:
10362 \layout Verse
10363
10364
10365 \family typewriter 
10366 void nmi_isr (void) critical interrupt
10367 \newline 
10368
10369 \newline 
10370 \SpecialChar ~
10371 \SpecialChar ~
10372 \SpecialChar ~
10373 \SpecialChar ~
10374 ...
10375  
10376 \newline 
10377 }
10378 \layout Section
10379
10380 Enabling and Disabling Interrupts
10381 \layout Subsection
10382
10383 Critical Functions and Critical Statements
10384 \layout Standard
10385
10386 A special keyword may be associated with a block or a function declaring
10387  it as 
10388 \emph on 
10389 critical
10390 \emph default 
10391 .
10392  SDCC will generate code to disable all interrupts
10393 \begin_inset LatexCommand \index{interrupt}
10394
10395 \end_inset 
10396
10397  upon entry to a critical function and restore the interrupt enable to the
10398  previous state before returning.
10399  Nesting critical functions will need one additional byte on the stack
10400 \begin_inset LatexCommand \index{stack}
10401
10402 \end_inset 
10403
10404  for each call.
10405 \layout Verse
10406
10407
10408 \family typewriter 
10409 int foo () critical
10410 \begin_inset LatexCommand \index{critical}
10411
10412 \end_inset 
10413
10414  
10415 \newline 
10416
10417 \newline 
10418 \SpecialChar ~
10419 \SpecialChar ~
10420 \SpecialChar ~
10421 \SpecialChar ~
10422 ...
10423  
10424 \newline 
10425 \SpecialChar ~
10426 \SpecialChar ~
10427 \SpecialChar ~
10428 \SpecialChar ~
10429 ...
10430  
10431 \newline 
10432 }
10433 \layout Standard
10434
10435 The critical attribute maybe used with other attributes like 
10436 \emph on 
10437 reentrant.
10438 \emph default 
10439
10440 \newline 
10441 The keyword 
10442 \emph on 
10443 critical
10444 \emph default 
10445  may also be used to disable interrupts more locally:
10446 \layout Verse
10447
10448
10449 \family typewriter 
10450 critical{ i++; }
10451 \layout Standard
10452
10453 More than one statement could have been included in the block.
10454 \layout Subsection
10455
10456 Enabling and Disabling Interrupts directly
10457 \layout Standard
10458
10459 Interrupts
10460 \begin_inset LatexCommand \index{interrupt}
10461
10462 \end_inset 
10463
10464  can also be disabled and enabled directly (8051):
10465 \layout Verse
10466
10467
10468 \family typewriter 
10469 EA = 0;\SpecialChar ~
10470 \SpecialChar ~
10471 \SpecialChar ~
10472 \SpecialChar ~
10473 \SpecialChar ~
10474 \SpecialChar ~
10475 \SpecialChar ~
10476 \SpecialChar ~
10477 \SpecialChar ~
10478 \SpecialChar ~
10479 \SpecialChar ~
10480 \SpecialChar ~
10481 or:\SpecialChar ~
10482 \SpecialChar ~
10483 \SpecialChar ~
10484 \SpecialChar ~
10485 \SpecialChar ~
10486 \SpecialChar ~
10487 \SpecialChar ~
10488 \SpecialChar ~
10489 \SpecialChar ~
10490 \SpecialChar ~
10491 \SpecialChar ~
10492 EA_SAVE = EA;
10493 \layout Verse
10494
10495
10496 \family typewriter 
10497 ...\SpecialChar ~
10498 \SpecialChar ~
10499 \SpecialChar ~
10500 \SpecialChar ~
10501 \SpecialChar ~
10502 \SpecialChar ~
10503 \SpecialChar ~
10504 \SpecialChar ~
10505 \SpecialChar ~
10506 \SpecialChar ~
10507 \SpecialChar ~
10508 \SpecialChar ~
10509 \SpecialChar ~
10510 \SpecialChar ~
10511 \SpecialChar ~
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 EA = 0;
10528 \layout Verse
10529
10530
10531 \family typewriter 
10532 EA = 1;\SpecialChar ~
10533 \SpecialChar ~
10534 \SpecialChar ~
10535 \SpecialChar ~
10536 \SpecialChar ~
10537 \SpecialChar ~
10538 \SpecialChar ~
10539 \SpecialChar ~
10540 \SpecialChar ~
10541 \SpecialChar ~
10542 \SpecialChar ~
10543 \SpecialChar ~
10544 \SpecialChar ~
10545 \SpecialChar ~
10546 \SpecialChar ~
10547 \SpecialChar ~
10548 \SpecialChar ~
10549 \SpecialChar ~
10550 \SpecialChar ~
10551 \SpecialChar ~
10552 \SpecialChar ~
10553 \SpecialChar ~
10554 \SpecialChar ~
10555 \SpecialChar ~
10556 \SpecialChar ~
10557 \SpecialChar ~
10558 ...
10559 \layout Verse
10560
10561
10562 \family typewriter 
10563 \SpecialChar ~
10564 \SpecialChar ~
10565 \SpecialChar ~
10566 \SpecialChar ~
10567 \SpecialChar ~
10568 \SpecialChar ~
10569 \SpecialChar ~
10570 \SpecialChar ~
10571 \SpecialChar ~
10572 \SpecialChar ~
10573 \SpecialChar ~
10574 \SpecialChar ~
10575 \SpecialChar ~
10576 \SpecialChar ~
10577 \SpecialChar ~
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 EA = EA_SAVE;
10597 \layout Standard
10598
10599 On other architectures which have seperate opcodes for enabling and disabling
10600  interrupts you might want to make use of defines with inline assembly
10601 \begin_inset LatexCommand \index{Assembler routines}
10602
10603 \end_inset 
10604
10605  (HC08):
10606 \layout Verse
10607
10608
10609 \family typewriter 
10610 #define CLI _asm
10611 \begin_inset LatexCommand \index{\_asm}
10612
10613 \end_inset 
10614
10615 \SpecialChar ~
10616 \SpecialChar ~
10617 cli\SpecialChar ~
10618 \SpecialChar ~
10619 _endasm
10620 \begin_inset LatexCommand \index{\_endasm}
10621
10622 \end_inset 
10623
10624
10625 \layout Verse
10626
10627
10628 \family typewriter 
10629 #define SEI _asm\SpecialChar ~
10630 \SpecialChar ~
10631 sei\SpecialChar ~
10632 \SpecialChar ~
10633 _endasm; 
10634 \layout Verse
10635
10636
10637 \family typewriter 
10638 ...
10639 \layout Standard
10640
10641 Note: it is sometimes sufficient to disable only a specific interrupt source
10642  like f.e.
10643  a timer or serial interrupt by manipulating an 
10644 \emph on 
10645 interrupt mask
10646 \begin_inset LatexCommand \index{interrupt mask}
10647
10648 \end_inset 
10649
10650
10651 \emph default 
10652  register.
10653  
10654 \layout Standard
10655
10656 Usually the time during which interrupts are disabled should be kept as
10657  short as possible.
10658  This minimizes both 
10659 \emph on 
10660 interrupt latency
10661 \emph default 
10662
10663 \begin_inset LatexCommand \index{interrupt latency}
10664
10665 \end_inset 
10666
10667  (the time between the occurrence of the interrupt and the execution of
10668  the first code in the interrupt routine) and 
10669 \emph on 
10670 interrupt jitter
10671 \emph default 
10672
10673 \begin_inset LatexCommand \index{interrupt jitter}
10674
10675 \end_inset 
10676
10677  (the difference between the shortest and the longest interrupt latency).
10678  These really are something different, f.e.
10679  a serial interrupt has to be served before its buffer overruns so it cares
10680  for the maximum interrupt latency, whereas it does not care about jitter.
10681  On a loudspeaker driven via a digital to analog converter which is fed
10682  by an interrupt a latency of a few milliseconds might be tolerable, whereas
10683  a much smaller jitter will be very audible.
10684 \layout Standard
10685
10686 You can reenable interrupts within an interrupt routine and on some architecture
10687 s you can make use of two (or more) levels of 
10688 \emph on 
10689 interrupt priorities
10690 \emph default 
10691
10692 \begin_inset LatexCommand \index{interrupt priority}
10693
10694 \end_inset 
10695
10696 .
10697  On some architectures which don't support interrupt priorities these can
10698  be implemented by manipulating the interrupt mask and reenabling interrupts
10699  within the interrupt routine.
10700  Check there is sufficient space on the stack
10701 \begin_inset LatexCommand \index{stack}
10702
10703 \end_inset 
10704
10705  and don't add complexity unless you have to.
10706  
10707 \layout Section
10708
10709 Functions using private register banks
10710 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10711
10712 \end_inset 
10713
10714  (mcs51/ds390)
10715 \layout Standard
10716
10717 Some architectures have support for quickly changing register sets.
10718  SDCC supports this feature with the 
10719 \emph on 
10720 using
10721 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10722
10723 \end_inset 
10724
10725
10726 \emph default 
10727  attribute (which tells the compiler to use a register bank
10728 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10729
10730 \end_inset 
10731
10732  other than the default bank zero).
10733  It should only be applied to 
10734 \emph on 
10735 interrupt
10736 \begin_inset LatexCommand \index{interrupt}
10737
10738 \end_inset 
10739
10740
10741 \emph default 
10742  functions (see footnote below).
10743  This will in most circumstances make the generated ISR code more efficient
10744  since it will not have to save registers on the stack.
10745 \layout Standard
10746
10747 The 
10748 \emph on 
10749 using
10750 \emph default 
10751  attribute will have no effect on the generated code for a 
10752 \emph on 
10753 non-interrupt
10754 \emph default 
10755  function (but may occasionally be useful anyway
10756 \begin_inset Foot
10757 collapsed false
10758
10759 \layout Standard
10760
10761 possible exception: if a function is called ONLY from 'interrupt' functions
10762  using a particular bank, it can be declared with the same 'using' attribute
10763  as the calling 'interrupt' functions.
10764  For instance, if you have several ISRs using bank one, and all of them
10765  call memcpy(), it might make sense to create a specialized version of memcpy()
10766  'using 1', since this would prevent the ISR from having to save bank zero
10767  to the stack on entry and switch to bank zero before calling the function
10768 \end_inset 
10769
10770 ).
10771 \newline 
10772
10773 \emph on 
10774 (pending: I don't think this has been done yet)
10775 \layout Standard
10776
10777 An 
10778 \emph on 
10779 interrupt
10780 \emph default 
10781  function using a non-zero bank will assume that it can trash that register
10782  bank, and will not save it.
10783  Since high-priority interrupts
10784 \begin_inset LatexCommand \index{interrupt priority}
10785
10786 \end_inset 
10787
10788  can interrupt low-priority ones on the 8051 and friends, this means that
10789  if a high-priority ISR 
10790 \emph on 
10791 using
10792 \emph default 
10793  a particular bank occurs while processing a low-priority ISR 
10794 \emph on 
10795 using
10796 \emph default 
10797  the same bank, terrible and bad things can happen.
10798  To prevent this, no single register bank should be 
10799 \emph on 
10800 used
10801 \emph default 
10802  by both a high priority and a low priority ISR.
10803  This is probably most easily done by having all high priority ISRs use
10804  one bank and all low priority ISRs use another.
10805  If you have an ISR which can change priority at runtime, you're on your
10806  own: I suggest using the default bank zero and taking the small performance
10807  hit.
10808 \layout Standard
10809
10810 It is most efficient if your ISR calls no other functions.
10811  If your ISR must call other functions, it is most efficient if those functions
10812  use the same bank as the ISR (see note 1 below); the next best is if the
10813  called functions use bank zero.
10814  It is very inefficient to call a function using a different, non-zero bank
10815  from an ISR.
10816  
10817 \layout Section
10818
10819 Startup Code
10820 \begin_inset LatexCommand \label{sub:Startup-Code}
10821
10822 \end_inset 
10823
10824
10825 \begin_inset LatexCommand \index{Startup code}
10826
10827 \end_inset 
10828
10829
10830 \layout Subsection
10831
10832 MCS51/DS390 Startup Code
10833 \layout Standard
10834
10835 The compiler inserts a call to the C routine 
10836 \emph on 
10837 _sdcc_external_startup()
10838 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
10839
10840 \end_inset 
10841
10842
10843 \series bold 
10844 \emph default 
10845  
10846 \series default 
10847 at the start of the CODE area.
10848  This routine is in the runtime library
10849 \begin_inset LatexCommand \index{Runtime library}
10850
10851 \end_inset 
10852
10853 .
10854  By default this routine returns 0, if this routine returns a non-zero value,
10855  the static & global variable initialization will be skipped and the function
10856  main will be invoked.
10857  Otherwise static & global variables will be initialized before the function
10858  main is invoked.
10859  You could add a 
10860 \emph on 
10861 _sdcc_external_startup()
10862 \emph default 
10863  routine to your program to override the default if you need to setup hardware
10864  or perform some other critical operation prior to static & global variable
10865  initialization.
10866  On some mcs51 variants xdata has to be explicitly enabled before it can
10867  be accessed, this is the place to do it.
10868  The startup code clears the complete 256 byte of idata memory, this might
10869  cause problems for 128 byte devices (endless loop reported for Chipcon
10870  CC1010).
10871 \layout Standard
10872
10873 See also the compiler option 
10874 \emph on 
10875 -
10876 \begin_inset ERT
10877 status Collapsed
10878
10879 \layout Standard
10880
10881 \backslash 
10882 /
10883 \end_inset 
10884
10885 -no-xinit
10886 \emph default 
10887 -
10888 \emph on 
10889 opt
10890 \emph default 
10891
10892 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
10893
10894 \end_inset 
10895
10896  and section 
10897 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10898
10899 \end_inset 
10900
10901 \SpecialChar ~
10902 about MCS51-variants.
10903 \layout Subsection
10904
10905 HC08 Startup Code
10906 \layout Standard
10907
10908 The HC08 startup code follows the same scheme as the MCS51 startup code.
10909 \layout Subsection
10910
10911 Z80 Startup Code
10912 \layout Standard
10913
10914 On the Z80 the startup code is inserted by linking with crt0.o which is generated
10915  from sdcc/device/lib/z80/crt0.s.
10916  If you need a different startup code you can use the compiler option 
10917 \emph on 
10918 -
10919 \series bold 
10920 \emph default 
10921
10922 \begin_inset ERT
10923 status Collapsed
10924
10925 \layout Standard
10926
10927 \backslash 
10928 /
10929 \end_inset 
10930
10931
10932 \series default 
10933 \emph on 
10934 -no-std-crt0
10935 \emph default 
10936
10937 \begin_inset LatexCommand \index{-\/-no-std-crt0}
10938
10939 \end_inset 
10940
10941  and provide your own crt0.o.
10942  
10943 \layout Section
10944
10945 Inline Assembler Code
10946 \begin_inset LatexCommand \index{Assembler routines}
10947
10948 \end_inset 
10949
10950
10951 \layout Subsection
10952
10953 A Step by Step Introduction
10954 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
10955
10956 \end_inset 
10957
10958
10959 \layout Standard
10960
10961 Starting from a small snippet of c-code this example shows for the MCS51
10962  how to use inline assembly, access variables, a function parameter and
10963  an array in xdata memory.
10964  The example uses an MCS51 here but is easily adapted for other architectures.
10965  This is a buffer routine which should be optimized:
10966 \layout Verse
10967
10968
10969 \family typewriter 
10970 \size footnotesize 
10971 unsigned char far
10972 \begin_inset LatexCommand \index{far (storage class)}
10973
10974 \end_inset 
10975
10976  at
10977 \begin_inset LatexCommand \index{at}
10978
10979 \end_inset 
10980
10981  0x7f00 buf[0x100];
10982 \begin_inset LatexCommand \index{Aligned array}
10983
10984 \end_inset 
10985
10986
10987 \newline 
10988 unsigned char head,tail;
10989 \newline 
10990
10991 \newline 
10992 void to_buffer( unsigned char c ) 
10993 \newline 
10994 {
10995 \newline 
10996 \SpecialChar ~
10997 \SpecialChar ~
10998 \SpecialChar ~
10999 \SpecialChar ~
11000 if( head != tail-1 ) 
11001 \newline 
11002 \SpecialChar ~
11003 \SpecialChar ~
11004 \SpecialChar ~
11005 \SpecialChar ~
11006 \SpecialChar ~
11007 \SpecialChar ~
11008 \SpecialChar ~
11009 \SpecialChar ~
11010 buf[ head++ ] = c;\SpecialChar ~
11011 \SpecialChar ~
11012 \SpecialChar ~
11013 \SpecialChar ~
11014 /* access to a 256 byte aligned array */
11015 \newline 
11016
11017 \layout Standard
11018
11019 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
11020  then a corresponding buffer.asm file is generated.
11021  We define a new function 
11022 \family typewriter 
11023 to_buffer_asm()
11024 \family default 
11025  in file buffer.c in which we cut and paste the generated code, removing
11026  unwanted comments and some ':'.
11027  Then add 
11028 \begin_inset Quotes sld
11029 \end_inset 
11030
11031 _asm
11032 \begin_inset Quotes srd
11033 \end_inset 
11034
11035  and 
11036 \begin_inset Quotes sld
11037 \end_inset 
11038
11039 _endasm;
11040 \begin_inset Quotes srd
11041 \end_inset 
11042
11043  to the beginning and the end of the function body:
11044 \layout Verse
11045
11046
11047 \family typewriter 
11048 \size footnotesize 
11049 /* With a cut and paste from the .asm file, we have something to start with.
11050 \newline 
11051 \SpecialChar ~
11052 \SpecialChar ~
11053 \SpecialChar ~
11054 The function is not yet OK! (registers aren't saved) */ 
11055 \newline 
11056 void to_buffer_asm( unsigned char c ) 
11057 \newline 
11058
11059 \newline 
11060 \SpecialChar ~
11061 \SpecialChar ~
11062 \SpecialChar ~
11063 \SpecialChar ~
11064 _asm
11065 \begin_inset LatexCommand \index{\_asm}
11066
11067 \end_inset 
11068
11069
11070 \newline 
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 \SpecialChar ~
11075 mov\SpecialChar ~
11076 \SpecialChar ~
11077 r2,dpl 
11078 \newline 
11079 ;buffer.c if( head != tail-1 ) 
11080 \newline 
11081 \SpecialChar ~
11082 \SpecialChar ~
11083 \SpecialChar ~
11084 \SpecialChar ~
11085 mov\SpecialChar ~
11086 \SpecialChar ~
11087 a,_tail 
11088 \newline 
11089 \SpecialChar ~
11090 \SpecialChar ~
11091 \SpecialChar ~
11092 \SpecialChar ~
11093 dec\SpecialChar ~
11094 \SpecialChar ~
11095
11096 \newline 
11097 \SpecialChar ~
11098 \SpecialChar ~
11099 \SpecialChar ~
11100 \SpecialChar ~
11101 mov\SpecialChar ~
11102 \SpecialChar ~
11103 r3,a 
11104 \newline 
11105 \SpecialChar ~
11106 \SpecialChar ~
11107 \SpecialChar ~
11108 \SpecialChar ~
11109 mov\SpecialChar ~
11110 \SpecialChar ~
11111 a,_head 
11112 \newline 
11113 \SpecialChar ~
11114 \SpecialChar ~
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 cjne a,ar3,00106$ 
11118 \newline 
11119 \SpecialChar ~
11120 \SpecialChar ~
11121 \SpecialChar ~
11122 \SpecialChar ~
11123 ret
11124 \newline 
11125 00106$: 
11126 \newline 
11127 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
11128 \begin_inset LatexCommand \index{Aligned array}
11129
11130 \end_inset 
11131
11132
11133 \newline 
11134 \SpecialChar ~
11135 \SpecialChar ~
11136 \SpecialChar ~
11137 \SpecialChar ~
11138 mov\SpecialChar ~
11139 \SpecialChar ~
11140 r3,_head 
11141 \newline 
11142 \SpecialChar ~
11143 \SpecialChar ~
11144 \SpecialChar ~
11145 \SpecialChar ~
11146 inc\SpecialChar ~
11147 \SpecialChar ~
11148 _head 
11149 \newline 
11150 \SpecialChar ~
11151 \SpecialChar ~
11152 \SpecialChar ~
11153 \SpecialChar ~
11154 mov\SpecialChar ~
11155 \SpecialChar ~
11156 dpl,r3 
11157 \newline 
11158 \SpecialChar ~
11159 \SpecialChar ~
11160 \SpecialChar ~
11161 \SpecialChar ~
11162 mov\SpecialChar ~
11163 \SpecialChar ~
11164 dph,#(_buf >> 8) 
11165 \newline 
11166 \SpecialChar ~
11167 \SpecialChar ~
11168 \SpecialChar ~
11169 \SpecialChar ~
11170 mov\SpecialChar ~
11171 \SpecialChar ~
11172 a,r2 
11173 \newline 
11174 \SpecialChar ~
11175 \SpecialChar ~
11176 \SpecialChar ~
11177 \SpecialChar ~
11178 movx @dptr,a 
11179 \newline 
11180 00103$: 
11181 \newline 
11182 \SpecialChar ~
11183 \SpecialChar ~
11184 \SpecialChar ~
11185 \SpecialChar ~
11186 ret
11187 \newline 
11188 \SpecialChar ~
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 \SpecialChar ~
11192 _endasm;
11193 \newline 
11194
11195 \layout Standard
11196
11197 The new file buffer.c should compile with only one warning about the unreferenced
11198  function argument 'c'.
11199  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
11200  (1) and finally have:
11201 \layout Verse
11202
11203
11204 \family typewriter 
11205 \size footnotesize 
11206 unsigned char far at 0x7f00 buf[0x100];
11207 \newline 
11208 unsigned char head,tail;
11209 \newline 
11210 #define USE_ASSEMBLY (1)
11211 \newline 
11212
11213 \newline 
11214 #if !USE_ASSEMBLY
11215 \newline 
11216
11217 \newline 
11218 void to_buffer( unsigned char c )
11219 \newline 
11220 {
11221 \newline 
11222 \SpecialChar ~
11223 \SpecialChar ~
11224 \SpecialChar ~
11225 \SpecialChar ~
11226 if( head != tail-1 )
11227 \newline 
11228 \SpecialChar ~
11229 \SpecialChar ~
11230 \SpecialChar ~
11231 \SpecialChar ~
11232 \SpecialChar ~
11233 \SpecialChar ~
11234 \SpecialChar ~
11235 \SpecialChar ~
11236 buf[ head++ ] = c;
11237 \newline 
11238 }
11239 \newline 
11240
11241 \newline 
11242 #else
11243 \newline 
11244
11245 \newline 
11246 void to_buffer( unsigned char c )
11247 \newline 
11248 {
11249 \newline 
11250 \SpecialChar ~
11251 \SpecialChar ~
11252 \SpecialChar ~
11253 \SpecialChar ~
11254 c; // to avoid warning: unreferenced function argument
11255 \newline 
11256 \SpecialChar ~
11257 \SpecialChar ~
11258 \SpecialChar ~
11259 \SpecialChar ~
11260 _asm
11261 \begin_inset LatexCommand \index{\_asm}
11262
11263 \end_inset 
11264
11265
11266 \newline 
11267 \SpecialChar ~
11268 \SpecialChar ~
11269 \SpecialChar ~
11270 \SpecialChar ~
11271 \SpecialChar ~
11272 \SpecialChar ~
11273 \SpecialChar ~
11274 \SpecialChar ~
11275 ; save used registers here.
11276  
11277 \newline 
11278 \SpecialChar ~
11279 \SpecialChar ~
11280 \SpecialChar ~
11281 \SpecialChar ~
11282 \SpecialChar ~
11283 \SpecialChar ~
11284 \SpecialChar ~
11285 \SpecialChar ~
11286 ; If we were still using r2,r3 we would have to push them here.
11287  
11288 \newline 
11289 ; if( head != tail-1 )
11290 \newline 
11291 \SpecialChar ~
11292 \SpecialChar ~
11293 \SpecialChar ~
11294 \SpecialChar ~
11295 \SpecialChar ~
11296 \SpecialChar ~
11297 \SpecialChar ~
11298 \SpecialChar ~
11299 mov\SpecialChar ~
11300  a,_tail
11301 \newline 
11302 \SpecialChar ~
11303 \SpecialChar ~
11304 \SpecialChar ~
11305 \SpecialChar ~
11306 \SpecialChar ~
11307 \SpecialChar ~
11308 \SpecialChar ~
11309 \SpecialChar ~
11310 dec\SpecialChar ~
11311  a
11312 \newline 
11313 \SpecialChar ~
11314 \SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 \SpecialChar ~
11319 \SpecialChar ~
11320 \SpecialChar ~
11321 xrl\SpecialChar ~
11322  a,_head
11323 \newline 
11324 \SpecialChar ~
11325 \SpecialChar ~
11326 \SpecialChar ~
11327 \SpecialChar ~
11328 \SpecialChar ~
11329 \SpecialChar ~
11330 \SpecialChar ~
11331 \SpecialChar ~
11332 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11333 \newline 
11334 \SpecialChar ~
11335 \SpecialChar ~
11336 \SpecialChar ~
11337 \SpecialChar ~
11338 \SpecialChar ~
11339 \SpecialChar ~
11340 \SpecialChar ~
11341 \SpecialChar ~
11342 jz\SpecialChar ~
11343 \SpecialChar ~
11344  t_b_end$
11345 \newline 
11346 \SpecialChar ~
11347 \SpecialChar ~
11348 \SpecialChar ~
11349 \SpecialChar ~
11350 \SpecialChar ~
11351 \SpecialChar ~
11352 \SpecialChar ~
11353 \SpecialChar ~
11354 ;
11355 \newline 
11356 ; buf[ head++ ] = c;
11357 \newline 
11358 \SpecialChar ~
11359 \SpecialChar ~
11360 \SpecialChar ~
11361 \SpecialChar ~
11362 \SpecialChar ~
11363 \SpecialChar ~
11364 \SpecialChar ~
11365 \SpecialChar ~
11366 mov\SpecialChar ~
11367  a,dpl \SpecialChar ~
11368 \SpecialChar ~
11369 \SpecialChar ~
11370 \SpecialChar ~
11371 \SpecialChar ~
11372 \SpecialChar ~
11373 \SpecialChar ~
11374 ; dpl holds lower byte of function argument
11375 \newline 
11376 \SpecialChar ~
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 \SpecialChar ~
11380 \SpecialChar ~
11381 \SpecialChar ~
11382 \SpecialChar ~
11383 \SpecialChar ~
11384 mov\SpecialChar ~
11385  dpl,_head \SpecialChar ~
11386 \SpecialChar ~
11387 \SpecialChar ~
11388 ; buf is 0x100 byte aligned so head can be used directly
11389 \newline 
11390 \SpecialChar ~
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 \SpecialChar ~
11394 \SpecialChar ~
11395 \SpecialChar ~
11396 \SpecialChar ~
11397 \SpecialChar ~
11398 mov\SpecialChar ~
11399  dph,#(_buf>>8)
11400 \newline 
11401 \SpecialChar ~
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 \SpecialChar ~
11405 \SpecialChar ~
11406 \SpecialChar ~
11407 \SpecialChar ~
11408 \SpecialChar ~
11409 movx @dptr,a
11410 \newline 
11411 \SpecialChar ~
11412 \SpecialChar ~
11413 \SpecialChar ~
11414 \SpecialChar ~
11415 \SpecialChar ~
11416 \SpecialChar ~
11417 \SpecialChar ~
11418 \SpecialChar ~
11419 inc \SpecialChar ~
11420 _head
11421 \newline 
11422 \SpecialChar ~
11423 \SpecialChar ~
11424 \SpecialChar ~
11425 \SpecialChar ~
11426 \SpecialChar ~
11427 \SpecialChar ~
11428 \SpecialChar ~
11429 \SpecialChar ~
11430 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11431 \newline 
11432 t_b_end$:
11433 \newline 
11434 \SpecialChar ~
11435 \SpecialChar ~
11436 \SpecialChar ~
11437 \SpecialChar ~
11438 \SpecialChar ~
11439 \SpecialChar ~
11440 \SpecialChar ~
11441 \SpecialChar ~
11442 ; restore used registers here 
11443 \newline 
11444 \SpecialChar ~
11445 \SpecialChar ~
11446 \SpecialChar ~
11447 \SpecialChar ~
11448 _endasm;
11449 \newline 
11450 }
11451 \newline 
11452 #endif
11453 \layout Standard
11454
11455 The inline assembler code can contain any valid code understood by the assembler
11456 , this includes any assembler directives and comment lines
11457 \begin_inset Foot
11458 collapsed false
11459
11460 \layout Standard
11461
11462 The assembler does not like some characters like ':' or ''' in comments.
11463  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11464 \end_inset 
11465
11466 .
11467  The compiler does not do any validation of the code within the 
11468 \family typewriter 
11469 _asm
11470 \begin_inset LatexCommand \index{\_asm}
11471
11472 \end_inset 
11473
11474  ...
11475  _endasm;
11476 \family default 
11477  keyword pair.
11478  Specifically it will not know which registers are used and thus register
11479  pushing/popping
11480 \begin_inset LatexCommand \index{push/pop}
11481
11482 \end_inset 
11483
11484  has to be done manually.
11485  
11486 \layout Standard
11487
11488 It is recommended that each assembly instruction (including labels) be placed
11489  in a separate line (as the example shows).
11490  When the -
11491 \begin_inset ERT
11492 status Collapsed
11493
11494 \layout Standard
11495
11496 \backslash 
11497 /
11498 \end_inset 
11499
11500 -
11501 \emph on 
11502 peep-asm
11503 \begin_inset LatexCommand \index{-\/-peep-asm}
11504
11505 \end_inset 
11506
11507
11508 \emph default 
11509  command line option is used, the inline assembler code will be passed through
11510  the peephole optimizer
11511 \begin_inset LatexCommand \index{Peephole optimizer}
11512
11513 \end_inset 
11514
11515 .
11516  There are only a few (if any) cases where this option makes sense, it might
11517  cause some unexpected changes in the inline assembler code.
11518  Please go through the peephole optimizer rules defined in file 
11519 \emph on 
11520 SDCCpeeph.def
11521 \emph default 
11522  before using this option.
11523 \layout Subsection
11524
11525 Naked Functions
11526 \begin_inset LatexCommand \label{sub:Naked-Functions}
11527
11528 \end_inset 
11529
11530
11531 \begin_inset LatexCommand \index{Naked functions}
11532
11533 \end_inset 
11534
11535
11536 \layout Standard
11537
11538 A special keyword may be associated with a function declaring it as 
11539 \emph on 
11540 _naked
11541 \begin_inset LatexCommand \index{\_naked}
11542
11543 \end_inset 
11544
11545 .
11546  
11547 \emph default 
11548 The 
11549 \emph on 
11550 _naked
11551 \emph default 
11552  function modifier attribute prevents the compiler from generating prologue
11553 \begin_inset LatexCommand \index{function prologue}
11554
11555 \end_inset 
11556
11557  and epilogue
11558 \begin_inset LatexCommand \index{function epilogue}
11559
11560 \end_inset 
11561
11562  code for that function.
11563  This means that the user is entirely responsible for such things as saving
11564  any registers that may need to be preserved, selecting the proper register
11565  bank, generating the 
11566 \emph on 
11567 return
11568 \emph default 
11569  instruction at the end, etc.
11570  Practically, this means that the contents of the function must be written
11571  in inline assembler.
11572  This is particularly useful for interrupt functions, which can have a large
11573  (and often unnecessary) prologue/epilogue.
11574  For example, compare the code generated by these two functions:
11575 \layout Verse
11576
11577
11578 \family typewriter 
11579 volatile
11580 \begin_inset LatexCommand \index{volatile}
11581
11582 \end_inset 
11583
11584  data unsigned char counter;
11585 \newline 
11586
11587 \newline 
11588 void simpleInterrupt(void) interrupt
11589 \begin_inset LatexCommand \index{interrupt}
11590
11591 \end_inset 
11592
11593  1
11594 \newline 
11595 {
11596 \newline 
11597 \SpecialChar ~
11598 \SpecialChar ~
11599 \SpecialChar ~
11600 \SpecialChar ~
11601 counter++;
11602 \newline 
11603 }
11604 \newline 
11605
11606 \newline 
11607 void nakedInterrupt(void) interrupt 2 _naked
11608 \newline 
11609 {
11610 \newline 
11611 \SpecialChar ~
11612 \SpecialChar ~
11613 \SpecialChar ~
11614 \SpecialChar ~
11615 _asm
11616 \begin_inset LatexCommand \index{\_asm}
11617
11618 \end_inset 
11619
11620
11621 \newline 
11622 \SpecialChar ~
11623 \SpecialChar ~
11624 \SpecialChar ~
11625 \SpecialChar ~
11626 \SpecialChar ~
11627 \SpecialChar ~
11628 inc\SpecialChar ~
11629 \SpecialChar ~
11630 \SpecialChar ~
11631 \SpecialChar ~
11632 \SpecialChar ~
11633 _counter ; does not change flags, no need to save psw
11634 \newline 
11635 \SpecialChar ~
11636 \SpecialChar ~
11637 \SpecialChar ~
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 reti\SpecialChar ~
11642 \SpecialChar ~
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 ; MUST explicitly include ret or reti in _naked function.
11646 \newline 
11647 \SpecialChar ~
11648 \SpecialChar ~
11649 \SpecialChar ~
11650 \SpecialChar ~
11651 _endasm
11652 \begin_inset LatexCommand \index{\_endasm}
11653
11654 \end_inset 
11655
11656 ;
11657 \newline 
11658 }
11659 \layout Standard
11660
11661 For an 8051 target, the generated simpleInterrupt looks like:
11662 \layout Verse
11663
11664
11665 \family typewriter 
11666 _simpleInterrupt:
11667 \newline 
11668 \SpecialChar ~
11669 \SpecialChar ~
11670 \SpecialChar ~
11671 \SpecialChar ~
11672 push\SpecialChar ~
11673 \SpecialChar ~
11674 \SpecialChar ~
11675 \SpecialChar ~
11676 acc
11677 \newline 
11678 \SpecialChar ~
11679 \SpecialChar ~
11680 \SpecialChar ~
11681 \SpecialChar ~
11682 push\SpecialChar ~
11683 \SpecialChar ~
11684 \SpecialChar ~
11685 \SpecialChar ~
11686 b
11687 \newline 
11688 \SpecialChar ~
11689 \SpecialChar ~
11690 \SpecialChar ~
11691 \SpecialChar ~
11692 push\SpecialChar ~
11693 \SpecialChar ~
11694 \SpecialChar ~
11695 \SpecialChar ~
11696 dpl
11697 \newline 
11698 \SpecialChar ~
11699 \SpecialChar ~
11700 \SpecialChar ~
11701 \SpecialChar ~
11702 push\SpecialChar ~
11703 \SpecialChar ~
11704 \SpecialChar ~
11705 \SpecialChar ~
11706 dph
11707 \newline 
11708 \SpecialChar ~
11709 \SpecialChar ~
11710 \SpecialChar ~
11711 \SpecialChar ~
11712 push\SpecialChar ~
11713 \SpecialChar ~
11714 \SpecialChar ~
11715 \SpecialChar ~
11716 psw
11717 \newline 
11718 \SpecialChar ~
11719 \SpecialChar ~
11720 \SpecialChar ~
11721 \SpecialChar ~
11722 mov\SpecialChar ~
11723 \SpecialChar ~
11724 \SpecialChar ~
11725 \SpecialChar ~
11726 \SpecialChar ~
11727 psw,#0x00
11728 \newline 
11729 \SpecialChar ~
11730 \SpecialChar ~
11731 \SpecialChar ~
11732 \SpecialChar ~
11733 inc\SpecialChar ~
11734 \SpecialChar ~
11735 \SpecialChar ~
11736 \SpecialChar ~
11737 \SpecialChar ~
11738 _counter
11739 \newline 
11740 \SpecialChar ~
11741 \SpecialChar ~
11742 \SpecialChar ~
11743 \SpecialChar ~
11744 pop\SpecialChar ~
11745 \SpecialChar ~
11746 \SpecialChar ~
11747 \SpecialChar ~
11748 \SpecialChar ~
11749 psw
11750 \newline 
11751 \SpecialChar ~
11752 \SpecialChar ~
11753 \SpecialChar ~
11754 \SpecialChar ~
11755 pop\SpecialChar ~
11756 \SpecialChar ~
11757 \SpecialChar ~
11758 \SpecialChar ~
11759 \SpecialChar ~
11760 dph
11761 \newline 
11762 \SpecialChar ~
11763 \SpecialChar ~
11764 \SpecialChar ~
11765 \SpecialChar ~
11766 pop\SpecialChar ~
11767 \SpecialChar ~
11768 \SpecialChar ~
11769 \SpecialChar ~
11770 \SpecialChar ~
11771 dpl
11772 \newline 
11773 \SpecialChar ~
11774 \SpecialChar ~
11775 \SpecialChar ~
11776 \SpecialChar ~
11777 pop\SpecialChar ~
11778 \SpecialChar ~
11779 \SpecialChar ~
11780 \SpecialChar ~
11781 \SpecialChar ~
11782 b
11783 \newline 
11784 \SpecialChar ~
11785 \SpecialChar ~
11786 \SpecialChar ~
11787 \SpecialChar ~
11788 pop\SpecialChar ~
11789 \SpecialChar ~
11790 \SpecialChar ~
11791 \SpecialChar ~
11792 \SpecialChar ~
11793 acc
11794 \newline 
11795 \SpecialChar ~
11796 \SpecialChar ~
11797 \SpecialChar ~
11798 \SpecialChar ~
11799 reti
11800 \layout Standard
11801
11802 whereas nakedInterrupt looks like:
11803 \layout Verse
11804
11805
11806 \family typewriter 
11807 _nakedInterrupt:
11808 \newline 
11809 \SpecialChar ~
11810 \SpecialChar ~
11811 \SpecialChar ~
11812 \SpecialChar ~
11813 inc\SpecialChar ~
11814 \SpecialChar ~
11815 \SpecialChar ~
11816 \SpecialChar ~
11817 _counter ; does not change flags, no need to save psw
11818 \newline 
11819 \SpecialChar ~
11820 \SpecialChar ~
11821 \SpecialChar ~
11822 \SpecialChar ~
11823 reti\SpecialChar ~
11824 \SpecialChar ~
11825 \SpecialChar ~
11826 \SpecialChar ~
11827 \SpecialChar ~
11828 \SpecialChar ~
11829 \SpecialChar ~
11830 \SpecialChar ~
11831 \SpecialChar ~
11832 \SpecialChar ~
11833 \SpecialChar ~
11834 \SpecialChar ~
11835 ; MUST explicitly include ret or reti in _naked function
11836 \layout Standard
11837
11838 The related directive #pragma exclude
11839 \begin_inset LatexCommand \index{\#pragma exclude}
11840
11841 \end_inset 
11842
11843  allows a more fine grained control over pushing & popping
11844 \begin_inset LatexCommand \index{push/pop}
11845
11846 \end_inset 
11847
11848  the registers.
11849 \layout Standard
11850
11851 While there is nothing preventing you from writing C code inside a 
11852 \family typewriter 
11853 _naked
11854 \family default 
11855  function, there are many ways to shoot yourself in the foot doing this,
11856  and it is recommended that you stick to inline assembler.
11857 \layout Subsection
11858
11859 Use of Labels within Inline Assembler
11860 \layout Standard
11861
11862 SDCC allows the use of in-line assembler with a few restrictions regarding
11863  labels.
11864  In older versions of the compiler all labels defined within inline assembler
11865  code 
11866 \emph on 
11867 had to be
11868 \emph default 
11869  of the form 
11870 \emph on 
11871 nnnnn$
11872 \emph default 
11873  where nnnn is a number less than 100 (which implies a limit of utmost 100
11874  inline assembler labels 
11875 \emph on 
11876 per function
11877 \emph default 
11878 \noun on 
11879 )
11880 \noun default 
11881 .
11882  
11883 \layout Verse
11884
11885
11886 \family typewriter 
11887 _asm
11888 \begin_inset LatexCommand \index{\_asm}
11889
11890 \end_inset 
11891
11892  
11893 \newline 
11894 \SpecialChar ~
11895 \SpecialChar ~
11896 \SpecialChar ~
11897 \SpecialChar ~
11898 mov\SpecialChar ~
11899 \SpecialChar ~
11900 \SpecialChar ~
11901 \SpecialChar ~
11902 \SpecialChar ~
11903 b,#10 
11904 \newline 
11905 00001$: 
11906 \newline 
11907 \SpecialChar ~
11908 \SpecialChar ~
11909 \SpecialChar ~
11910 \SpecialChar ~
11911 djnz\SpecialChar ~
11912 \SpecialChar ~
11913 \SpecialChar ~
11914 \SpecialChar ~
11915 b,00001$ 
11916 \newline 
11917 _endasm
11918 \begin_inset LatexCommand \index{\_endasm}
11919
11920 \end_inset 
11921
11922  ;
11923 \layout Standard
11924
11925 Inline assembler code cannot reference any C-Labels, however it can reference
11926  labels
11927 \begin_inset LatexCommand \index{Labels}
11928
11929 \end_inset 
11930
11931  defined by the inline assembler, e.g.:
11932 \layout Verse
11933
11934
11935 \family typewriter 
11936 foo() { 
11937 \newline 
11938 \SpecialChar ~
11939 \SpecialChar ~
11940 \SpecialChar ~
11941 \SpecialChar ~
11942 /* some c code */ 
11943 \newline 
11944 \SpecialChar ~
11945 \SpecialChar ~
11946 \SpecialChar ~
11947 \SpecialChar ~
11948 _asm 
11949 \newline 
11950 \SpecialChar ~
11951 \SpecialChar ~
11952 \SpecialChar ~
11953 \SpecialChar ~
11954 \SpecialChar ~
11955 \SpecialChar ~
11956 ; some assembler code 
11957 \newline 
11958 \SpecialChar ~
11959 \SpecialChar ~
11960 \SpecialChar ~
11961 \SpecialChar ~
11962 \SpecialChar ~
11963 \SpecialChar ~
11964 ljmp $0003 
11965 \newline 
11966 \SpecialChar ~
11967 \SpecialChar ~
11968 \SpecialChar ~
11969 \SpecialChar ~
11970 _endasm; 
11971 \newline 
11972 \SpecialChar ~
11973 \SpecialChar ~
11974 \SpecialChar ~
11975 \SpecialChar ~
11976 /* some more c code */ 
11977 \newline 
11978 clabel:\SpecialChar ~
11979 \SpecialChar ~
11980 /* inline assembler cannot reference this label */ 
11981 \newline 
11982 \SpecialChar ~
11983 \SpecialChar ~
11984 \SpecialChar ~
11985 \SpecialChar ~
11986 _asm
11987 \newline 
11988 \SpecialChar ~
11989 \SpecialChar ~
11990 \SpecialChar ~
11991 \SpecialChar ~
11992 $0003: ;label (can be referenced by inline assembler only) 
11993 \newline 
11994 \SpecialChar ~
11995 \SpecialChar ~
11996 \SpecialChar ~
11997 \SpecialChar ~
11998 _endasm ; 
11999 \newline 
12000 \SpecialChar ~
12001 \SpecialChar ~
12002 \SpecialChar ~
12003 \SpecialChar ~
12004 /* some more c code */
12005 \newline 
12006 }
12007 \layout Standard
12008
12009 In other words inline assembly code can access labels defined in inline
12010  assembly within the scope of the function.
12011  The same goes the other way, i.e.
12012  labels defines in inline assembly can not be accessed by C statements.
12013 \layout Section
12014
12015 Interfacing with Assembler Code
12016 \begin_inset LatexCommand \index{Assembler routines}
12017
12018 \end_inset 
12019
12020
12021 \layout Subsection
12022
12023 Global Registers used for Parameter Passing
12024 \begin_inset LatexCommand \index{Parameter passing}
12025
12026 \end_inset 
12027
12028
12029 \layout Standard
12030
12031 The compiler always uses the global registers 
12032 \emph on 
12033 DPL, DPH
12034 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12035
12036 \end_inset 
12037
12038
12039 \begin_inset LatexCommand \index{DPTR}
12040
12041 \end_inset 
12042
12043 , B
12044 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
12045
12046 \end_inset 
12047
12048  
12049 \emph default 
12050 and
12051 \emph on 
12052  ACC
12053 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
12054
12055 \end_inset 
12056
12057
12058 \emph default 
12059  to pass the first parameter to a routine.
12060  The second parameter onwards is either allocated on the stack (for reentrant
12061  routines or if -
12062 \begin_inset ERT
12063 status Collapsed
12064
12065 \layout Standard
12066
12067 \backslash 
12068 /
12069 \end_inset 
12070
12071 -stack-auto is used) or in data / xdata memory (depending on the memory
12072  model).
12073  
12074 \layout Subsection
12075
12076 Assembler Routine (non-reentrant)
12077 \layout Standard
12078
12079 In the following example
12080 \begin_inset LatexCommand \index{reentrant}
12081
12082 \end_inset 
12083
12084
12085 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12086
12087 \end_inset 
12088
12089  the function c_func calls an assembler routine asm_func, which takes two
12090  parameters
12091 \begin_inset LatexCommand \index{function parameter}
12092
12093 \end_inset 
12094
12095 .
12096 \layout Verse
12097
12098
12099 \family typewriter 
12100 extern int asm_func(unsigned char, unsigned char);
12101 \newline 
12102
12103 \newline 
12104 int c_func (unsigned char i, unsigned char j)
12105 \newline 
12106 {
12107 \newline 
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 \SpecialChar ~
12111 \SpecialChar ~
12112 return asm_func(i,j);
12113 \newline 
12114 }
12115 \newline 
12116
12117 \newline 
12118 int main()
12119 \newline 
12120 {
12121 \newline 
12122 \SpecialChar ~
12123 \SpecialChar ~
12124 \SpecialChar ~
12125 \SpecialChar ~
12126 return c_func(10,9);
12127 \newline 
12128 }
12129 \layout Standard
12130
12131 The corresponding assembler function is:
12132 \layout Verse
12133
12134
12135 \family typewriter 
12136 .globl _asm_func_PARM_2 
12137 \newline 
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 \SpecialChar ~
12141 \SpecialChar ~
12142 \SpecialChar ~
12143 \SpecialChar ~
12144 \SpecialChar ~
12145 \SpecialChar ~
12146 .globl _asm_func 
12147 \newline 
12148 \SpecialChar ~
12149 \SpecialChar ~
12150 \SpecialChar ~
12151 \SpecialChar ~
12152 \SpecialChar ~
12153 \SpecialChar ~
12154 \SpecialChar ~
12155 \SpecialChar ~
12156 .area OSEG 
12157 \newline 
12158 _asm_func_PARM_2:
12159 \newline 
12160 \SpecialChar ~
12161 \SpecialChar ~
12162 \SpecialChar ~
12163 \SpecialChar ~
12164 \SpecialChar ~
12165 \SpecialChar ~
12166 \SpecialChar ~
12167 \SpecialChar ~
12168 .ds    1 
12169 \newline 
12170 \SpecialChar ~
12171 \SpecialChar ~
12172 \SpecialChar ~
12173 \SpecialChar ~
12174 \SpecialChar ~
12175 \SpecialChar ~
12176 \SpecialChar ~
12177 \SpecialChar ~
12178 .area CSEG 
12179 \newline 
12180 _asm_func: 
12181 \newline 
12182 \SpecialChar ~
12183 \SpecialChar ~
12184 \SpecialChar ~
12185 \SpecialChar ~
12186 \SpecialChar ~
12187 \SpecialChar ~
12188 \SpecialChar ~
12189 \SpecialChar ~
12190 mov\SpecialChar ~
12191 \SpecialChar ~
12192 \SpecialChar ~
12193 \SpecialChar ~
12194 a,dpl 
12195 \newline 
12196 \SpecialChar ~
12197 \SpecialChar ~
12198 \SpecialChar ~
12199 \SpecialChar ~
12200 \SpecialChar ~
12201 \SpecialChar ~
12202 \SpecialChar ~
12203 \SpecialChar ~
12204 add\SpecialChar ~
12205 \SpecialChar ~
12206 \SpecialChar ~
12207 \SpecialChar ~
12208 a,_asm_func_PARM_2 
12209 \newline 
12210 \SpecialChar ~
12211 \SpecialChar ~
12212 \SpecialChar ~
12213 \SpecialChar ~
12214 \SpecialChar ~
12215 \SpecialChar ~
12216 \SpecialChar ~
12217 \SpecialChar ~
12218 mov\SpecialChar ~
12219 \SpecialChar ~
12220 \SpecialChar ~
12221 \SpecialChar ~
12222 dpl,a 
12223 \newline 
12224 \SpecialChar ~
12225 \SpecialChar ~
12226 \SpecialChar ~
12227 \SpecialChar ~
12228 \SpecialChar ~
12229 \SpecialChar ~
12230 \SpecialChar ~
12231 \SpecialChar ~
12232 mov\SpecialChar ~
12233 \SpecialChar ~
12234 \SpecialChar ~
12235 \SpecialChar ~
12236 dph
12237 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12238
12239 \end_inset 
12240
12241 ,#0x00 
12242 \newline 
12243 \SpecialChar ~
12244 \SpecialChar ~
12245 \SpecialChar ~
12246 \SpecialChar ~
12247 \SpecialChar ~
12248 \SpecialChar ~
12249 \SpecialChar ~
12250 \SpecialChar ~
12251 ret
12252 \layout Standard
12253
12254 Note here that the return values
12255 \begin_inset LatexCommand \index{return value}
12256
12257 \end_inset 
12258
12259  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
12260  two byte values.
12261  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12262 b' & 'acc' for four byte values.
12263 \layout Standard
12264
12265 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12266  the parameter number starting from 1, and counting from the left.
12267  The first parameter is passed in 
12268 \begin_inset Quotes eld
12269 \end_inset 
12270
12271 dpl
12272 \begin_inset Quotes erd
12273 \end_inset 
12274
12275  for a one byte parameter, 
12276 \begin_inset Quotes eld
12277 \end_inset 
12278
12279 dptr
12280 \begin_inset Quotes erd
12281 \end_inset 
12282
12283  for two bytes, 
12284 \begin_inset Quotes eld
12285 \end_inset 
12286
12287 b,dptr
12288 \begin_inset Quotes erd
12289 \end_inset 
12290
12291  for three bytes and 
12292 \begin_inset Quotes eld
12293 \end_inset 
12294
12295 acc,b,dptr
12296 \begin_inset Quotes erd
12297 \end_inset 
12298
12299  for a four bytes parameter.
12300  The variable name for the second parameter will be _<function_name>_PARM_2.
12301 \newline 
12302
12303 \newline 
12304 Assemble the assembler routine with the following command:
12305 \newline 
12306
12307 \newline 
12308
12309 \family sans 
12310 \series bold 
12311 asx8051 -losg asmfunc.asm
12312 \newline 
12313
12314 \newline 
12315
12316 \family default 
12317 \series default 
12318 Then compile and link the assembler routine to the C source file with the
12319  following command:
12320 \newline 
12321
12322 \newline 
12323
12324 \family sans 
12325 \series bold 
12326 sdcc cfunc.c asmfunc.rel
12327 \layout Subsection
12328
12329 Assembler Routine (reentrant)
12330 \layout Standard
12331
12332 In this case
12333 \begin_inset LatexCommand \index{reentrant}
12334
12335 \end_inset 
12336
12337
12338 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12339
12340 \end_inset 
12341
12342  the second parameter
12343 \begin_inset LatexCommand \index{function parameter}
12344
12345 \end_inset 
12346
12347  onwards will be passed on the stack, the parameters are pushed from right
12348  to left i.e.
12349  after the call the leftmost parameter will be on the top of the stack.
12350  Here is an example:
12351 \layout Verse
12352
12353
12354 \family typewriter 
12355 extern int asm_func(unsigned char, unsigned char);
12356 \newline 
12357
12358 \newline 
12359 int c_func (unsigned char i, unsigned char j) reentrant 
12360 \newline 
12361
12362 \newline 
12363 \SpecialChar ~
12364 \SpecialChar ~
12365 \SpecialChar ~
12366 \SpecialChar ~
12367 return asm_func(i,j); 
12368 \newline 
12369
12370 \newline 
12371
12372 \newline 
12373 int main() 
12374 \newline 
12375
12376 \newline 
12377 \SpecialChar ~
12378 \SpecialChar ~
12379 \SpecialChar ~
12380 \SpecialChar ~
12381 return c_func(10,9); 
12382 \newline 
12383 }
12384 \layout Standard
12385
12386 The corresponding assembler routine is:
12387 \layout Verse
12388
12389
12390 \family typewriter 
12391 .globl _asm_func 
12392 \newline 
12393 _asm_func: 
12394 \newline 
12395 \SpecialChar ~
12396 \SpecialChar ~
12397 \SpecialChar ~
12398 \SpecialChar ~
12399 push  _bp 
12400 \newline 
12401 \SpecialChar ~
12402 \SpecialChar ~
12403 \SpecialChar ~
12404 \SpecialChar ~
12405 mov _bp,sp 
12406 \newline 
12407 \SpecialChar ~
12408 \SpecialChar ~
12409 \SpecialChar ~
12410 \SpecialChar ~
12411 mov r2,dpl
12412 \newline 
12413 \SpecialChar ~
12414 \SpecialChar ~
12415 \SpecialChar ~
12416 \SpecialChar ~
12417 mov a,_bp 
12418 \newline 
12419 \SpecialChar ~
12420 \SpecialChar ~
12421 \SpecialChar ~
12422 \SpecialChar ~
12423 add a,#0xfd 
12424 \newline 
12425 \SpecialChar ~
12426 \SpecialChar ~
12427 \SpecialChar ~
12428 \SpecialChar ~
12429 mov r0,a 
12430 \newline 
12431 \SpecialChar ~
12432 \SpecialChar ~
12433 \SpecialChar ~
12434 \SpecialChar ~
12435 add  a,#0xfc ;?
12436 \newline 
12437 \SpecialChar ~
12438 \SpecialChar ~
12439 \SpecialChar ~
12440 \SpecialChar ~
12441 mov  r1,a 
12442 \newline 
12443 \SpecialChar ~
12444 \SpecialChar ~
12445 \SpecialChar ~
12446 \SpecialChar ~
12447 mov  a,@r0 
12448 \newline 
12449 \SpecialChar ~
12450 \SpecialChar ~
12451 \SpecialChar ~
12452 \SpecialChar ~
12453 add  a,r2 ;?
12454 \newline 
12455 \SpecialChar ~
12456 \SpecialChar ~
12457 \SpecialChar ~
12458 \SpecialChar ~
12459 mov  dpl,a 
12460 \newline 
12461 \SpecialChar ~
12462 \SpecialChar ~
12463 \SpecialChar ~
12464 \SpecialChar ~
12465 mov  dph,#0x00 
12466 \newline 
12467 \SpecialChar ~
12468 \SpecialChar ~
12469 \SpecialChar ~
12470 \SpecialChar ~
12471 mov  sp,_bp 
12472 \newline 
12473 \SpecialChar ~
12474 \SpecialChar ~
12475 \SpecialChar ~
12476 \SpecialChar ~
12477 pop  _bp 
12478 \newline 
12479 \SpecialChar ~
12480 \SpecialChar ~
12481 \SpecialChar ~
12482 \SpecialChar ~
12483 ret
12484 \layout Standard
12485
12486 The compiling and linking procedure remains the same, however note the extra
12487  entry & exit linkage required for the assembler code, _bp is the stack
12488  frame pointer and is used to compute the offset into the stack for parameters
12489  and local variables.
12490 \layout Section
12491
12492 int (16 bit)
12493 \begin_inset LatexCommand \index{int (16 bit)}
12494
12495 \end_inset 
12496
12497  and long (32 bit)
12498 \begin_inset LatexCommand \index{long (32 bit)}
12499
12500 \end_inset 
12501
12502  Support
12503 \layout Standard
12504
12505 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12506  multiplication and modulus operations are implemented by support routines.
12507  These support routines are all developed in ANSI-C to facilitate porting
12508  to other MCUs, although some model specific assembler optimizations are
12509  used.
12510  The following files contain the described routines, all of them can be
12511  found in <installdir>/share/sdcc/lib.
12512 \newline 
12513
12514 \layout Standard
12515 \align center 
12516
12517 \begin_inset  Tabular
12518 <lyxtabular version="3" rows="11" columns="2">
12519 <features>
12520 <column alignment="center" valignment="top" leftline="true" width="0">
12521 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12522 <row topline="true" bottomline="true">
12523 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12524 \begin_inset Text
12525
12526 \layout Standard
12527
12528
12529 \series bold 
12530 Function
12531 \end_inset 
12532 </cell>
12533 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12534 \begin_inset Text
12535
12536 \layout Standard
12537
12538
12539 \series bold 
12540 Description
12541 \end_inset 
12542 </cell>
12543 </row>
12544 <row topline="true">
12545 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12546 \begin_inset Text
12547
12548 \layout Standard
12549
12550 _mulint.c 
12551 \end_inset 
12552 </cell>
12553 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12554 \begin_inset Text
12555
12556 \layout Standard
12557
12558 16 bit multiplication
12559 \end_inset 
12560 </cell>
12561 </row>
12562 <row topline="true">
12563 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12564 \begin_inset Text
12565
12566 \layout Standard
12567
12568 _divsint.c 
12569 \end_inset 
12570 </cell>
12571 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12572 \begin_inset Text
12573
12574 \layout Standard
12575
12576  signed 16 bit division (calls _divuint)
12577 \end_inset 
12578 </cell>
12579 </row>
12580 <row topline="true">
12581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12582 \begin_inset Text
12583
12584 \layout Standard
12585
12586 _divuint.c 
12587 \end_inset 
12588 </cell>
12589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12590 \begin_inset Text
12591
12592 \layout Standard
12593
12594  unsigned 16 bit division
12595 \end_inset 
12596 </cell>
12597 </row>
12598 <row topline="true">
12599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12600 \begin_inset Text
12601
12602 \layout Standard
12603
12604 _modsint.c
12605 \end_inset 
12606 </cell>
12607 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12608 \begin_inset Text
12609
12610 \layout Standard
12611
12612 signed 16 bit modulus (calls _moduint)
12613 \end_inset 
12614 </cell>
12615 </row>
12616 <row topline="true">
12617 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12618 \begin_inset Text
12619
12620 \layout Standard
12621
12622 _moduint.c
12623 \end_inset 
12624 </cell>
12625 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12626 \begin_inset Text
12627
12628 \layout Standard
12629
12630 unsigned 16 bit modulus
12631 \end_inset 
12632 </cell>
12633 </row>
12634 <row topline="true">
12635 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12636 \begin_inset Text
12637
12638 \layout Standard
12639
12640 _mullong.c
12641 \end_inset 
12642 </cell>
12643 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12644 \begin_inset Text
12645
12646 \layout Standard
12647
12648 32 bit multiplication
12649 \end_inset 
12650 </cell>
12651 </row>
12652 <row topline="true">
12653 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12654 \begin_inset Text
12655
12656 \layout Standard
12657
12658 _divslong.c 
12659 \end_inset 
12660 </cell>
12661 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12662 \begin_inset Text
12663
12664 \layout Standard
12665
12666  signed 32 division (calls _divulong)
12667 \end_inset 
12668 </cell>
12669 </row>
12670 <row topline="true">
12671 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12672 \begin_inset Text
12673
12674 \layout Standard
12675
12676 _divulong.c 
12677 \end_inset 
12678 </cell>
12679 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12680 \begin_inset Text
12681
12682 \layout Standard
12683
12684 unsigned 32 division
12685 \end_inset 
12686 </cell>
12687 </row>
12688 <row topline="true">
12689 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12690 \begin_inset Text
12691
12692 \layout Standard
12693
12694 _modslong.c
12695 \end_inset 
12696 </cell>
12697 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12698 \begin_inset Text
12699
12700 \layout Standard
12701
12702  signed 32 bit modulus (calls _modulong)
12703 \end_inset 
12704 </cell>
12705 </row>
12706 <row topline="true" bottomline="true">
12707 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12708 \begin_inset Text
12709
12710 \layout Standard
12711
12712 _modulong.c
12713 \end_inset 
12714 </cell>
12715 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12716 \begin_inset Text
12717
12718 \layout Standard
12719
12720 unsigned 32 bit modulus
12721 \end_inset 
12722 </cell>
12723 </row>
12724 </lyxtabular>
12725
12726 \end_inset 
12727
12728
12729 \newline 
12730
12731 \layout Standard
12732
12733 Since they are compiled as 
12734 \emph on 
12735 non-reentrant
12736 \emph default 
12737
12738 \begin_inset LatexCommand \index{reentrant}
12739
12740 \end_inset 
12741
12742 , interrupt
12743 \begin_inset LatexCommand \index{interrupt}
12744
12745 \end_inset 
12746
12747  service routines should not do any of the above operations.
12748  If this is unavoidable then the above routines will need to be compiled
12749  with the 
12750 \emph on 
12751 -
12752 \begin_inset ERT
12753 status Collapsed
12754
12755 \layout Standard
12756
12757 \backslash 
12758 /
12759 \end_inset 
12760
12761 -stack-auto
12762 \begin_inset LatexCommand \index{-\/-stack-auto}
12763
12764 \end_inset 
12765
12766
12767 \emph default 
12768  option, after which the source program will have to be compiled with 
12769 \emph on 
12770 -
12771 \begin_inset ERT
12772 status Collapsed
12773
12774 \layout Standard
12775
12776 \backslash 
12777 /
12778 \end_inset 
12779
12780 -int-long-reent
12781 \begin_inset LatexCommand \index{-\/-int-long-reent}
12782
12783 \end_inset 
12784
12785
12786 \emph default 
12787  option.
12788  Notice that you don't have to call these routines directly.
12789  The compiler will use them automatically every time an integer operation
12790  is required.
12791 \layout Section
12792
12793 Floating Point Support
12794 \begin_inset LatexCommand \index{Floating point support}
12795
12796 \end_inset 
12797
12798
12799 \layout Standard
12800
12801 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12802  floating point support routines are derived from gcc's floatlib.c and consist
12803  of the following routines:
12804 \newline 
12805
12806 \layout Standard
12807 \align center 
12808
12809 \size footnotesize 
12810
12811 \begin_inset  Tabular
12812 <lyxtabular version="3" rows="17" columns="2">
12813 <features>
12814 <column alignment="center" valignment="top" leftline="true" width="0">
12815 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12816 <row topline="true" bottomline="true">
12817 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12818 \begin_inset Text
12819
12820 \layout Standard
12821
12822
12823 \family roman 
12824 \series medium 
12825 \shape up 
12826 \size normal 
12827 \emph off 
12828 \bar no 
12829 \noun off 
12830 \color none
12831 Function 
12832 \end_inset 
12833 </cell>
12834 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12835 \begin_inset Text
12836
12837 \layout Standard
12838
12839 Description
12840 \end_inset 
12841 </cell>
12842 </row>
12843 <row topline="true">
12844 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12845 \begin_inset Text
12846
12847 \layout Standard
12848
12849
12850 \family roman 
12851 \series medium 
12852 \shape up 
12853 \size normal 
12854 \emph off 
12855 \bar no 
12856 \noun off 
12857 \color none
12858 _fsadd.c
12859 \end_inset 
12860 </cell>
12861 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12862 \begin_inset Text
12863
12864 \layout Standard
12865
12866
12867 \family roman 
12868 \series medium 
12869 \shape up 
12870 \size normal 
12871 \emph off 
12872 \bar no 
12873 \noun off 
12874 \color none
12875 add floating point numbers
12876 \end_inset 
12877 </cell>
12878 </row>
12879 <row topline="true">
12880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12881 \begin_inset Text
12882
12883 \layout Standard
12884
12885
12886 \family roman 
12887 \series medium 
12888 \shape up 
12889 \size normal 
12890 \emph off 
12891 \bar no 
12892 \noun off 
12893 \color none
12894 _fssub.c 
12895 \end_inset 
12896 </cell>
12897 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12898 \begin_inset Text
12899
12900 \layout Standard
12901
12902
12903 \family roman 
12904 \series medium 
12905 \shape up 
12906 \size normal 
12907 \emph off 
12908 \bar no 
12909 \noun off 
12910 \color none
12911 subtract floating point numbers 
12912 \end_inset 
12913 </cell>
12914 </row>
12915 <row topline="true">
12916 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12917 \begin_inset Text
12918
12919 \layout Standard
12920
12921
12922 \family roman 
12923 \series medium 
12924 \shape up 
12925 \size normal 
12926 \emph off 
12927 \bar no 
12928 \noun off 
12929 \color none
12930 _fsdiv.c 
12931 \end_inset 
12932 </cell>
12933 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12934 \begin_inset Text
12935
12936 \layout Standard
12937
12938
12939 \family roman 
12940 \series medium 
12941 \shape up 
12942 \size normal 
12943 \emph off 
12944 \bar no 
12945 \noun off 
12946 \color none
12947 divide floating point numbers 
12948 \end_inset 
12949 </cell>
12950 </row>
12951 <row topline="true">
12952 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12953 \begin_inset Text
12954
12955 \layout Standard
12956
12957
12958 \family roman 
12959 \series medium 
12960 \shape up 
12961 \size normal 
12962 \emph off 
12963 \bar no 
12964 \noun off 
12965 \color none
12966 _fsmul.c 
12967 \end_inset 
12968 </cell>
12969 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12970 \begin_inset Text
12971
12972 \layout Standard
12973
12974
12975 \family roman 
12976 \series medium 
12977 \shape up 
12978 \size normal 
12979 \emph off 
12980 \bar no 
12981 \noun off 
12982 \color none
12983 multiply floating point numbers 
12984 \end_inset 
12985 </cell>
12986 </row>
12987 <row topline="true">
12988 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12989 \begin_inset Text
12990
12991 \layout Standard
12992
12993
12994 \family roman 
12995 \series medium 
12996 \shape up 
12997 \size normal 
12998 \emph off 
12999 \bar no 
13000 \noun off 
13001 \color none
13002 _fs2uchar.c
13003 \end_inset 
13004 </cell>
13005 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13006 \begin_inset Text
13007
13008 \layout Standard
13009
13010
13011 \family roman 
13012 \series medium 
13013 \shape up 
13014 \size normal 
13015 \emph off 
13016 \bar no 
13017 \noun off 
13018 \color none
13019 convert floating point to unsigned char
13020 \end_inset 
13021 </cell>
13022 </row>
13023 <row topline="true">
13024 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13025 \begin_inset Text
13026
13027 \layout Standard
13028
13029
13030 \family roman 
13031 \series medium 
13032 \shape up 
13033 \size normal 
13034 \emph off 
13035 \bar no 
13036 \noun off 
13037 \color none
13038 _fs2char.c
13039 \end_inset 
13040 </cell>
13041 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13042 \begin_inset Text
13043
13044 \layout Standard
13045
13046
13047 \family roman 
13048 \series medium 
13049 \shape up 
13050 \size normal 
13051 \emph off 
13052 \bar no 
13053 \noun off 
13054 \color none
13055 convert floating point to signed char
13056 \end_inset 
13057 </cell>
13058 </row>
13059 <row topline="true">
13060 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13061 \begin_inset Text
13062
13063 \layout Standard
13064
13065
13066 \family roman 
13067 \series medium 
13068 \shape up 
13069 \size normal 
13070 \emph off 
13071 \bar no 
13072 \noun off 
13073 \color none
13074 _fs2uint.c
13075 \end_inset 
13076 </cell>
13077 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13078 \begin_inset Text
13079
13080 \layout Standard
13081
13082
13083 \family roman 
13084 \series medium 
13085 \shape up 
13086 \size normal 
13087 \emph off 
13088 \bar no 
13089 \noun off 
13090 \color none
13091 convert floating point to unsigned int
13092 \end_inset 
13093 </cell>
13094 </row>
13095 <row topline="true">
13096 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13097 \begin_inset Text
13098
13099 \layout Standard
13100
13101
13102 \family roman 
13103 \series medium 
13104 \shape up 
13105 \size normal 
13106 \emph off 
13107 \bar no 
13108 \noun off 
13109 \color none
13110 _fs2int.c
13111 \end_inset 
13112 </cell>
13113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13114 \begin_inset Text
13115
13116 \layout Standard
13117
13118
13119 \family roman 
13120 \series medium 
13121 \shape up 
13122 \size normal 
13123 \emph off 
13124 \bar no 
13125 \noun off 
13126 \color none
13127 convert floating point to signed int
13128 \end_inset 
13129 </cell>
13130 </row>
13131 <row topline="true">
13132 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13133 \begin_inset Text
13134
13135 \layout Standard
13136
13137
13138 \family roman 
13139 \series medium 
13140 \shape up 
13141 \size normal 
13142 \emph off 
13143 \bar no 
13144 \noun off 
13145 \color none
13146 _fs2ulong.
13147 \family default 
13148 \series default 
13149 \shape default 
13150 \size default 
13151 \emph default 
13152 \bar default 
13153 \noun default 
13154 \color default
13155 c
13156 \end_inset 
13157 </cell>
13158 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13159 \begin_inset Text
13160
13161 \layout Standard
13162
13163
13164 \family roman 
13165 \series medium 
13166 \shape up 
13167 \size normal 
13168 \emph off 
13169 \bar no 
13170 \noun off 
13171 \color none
13172 convert floating point to unsigned long
13173 \end_inset 
13174 </cell>
13175 </row>
13176 <row topline="true">
13177 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13178 \begin_inset Text
13179
13180 \layout Standard
13181
13182
13183 \family roman 
13184 \series medium 
13185 \shape up 
13186 \size normal 
13187 \emph off 
13188 \bar no 
13189 \noun off 
13190 \color none
13191 _fs2long.c
13192 \end_inset 
13193 </cell>
13194 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13195 \begin_inset Text
13196
13197 \layout Standard
13198
13199
13200 \family roman 
13201 \series medium 
13202 \shape up 
13203 \size normal 
13204 \emph off 
13205 \bar no 
13206 \noun off 
13207 \color none
13208 convert floating point to signed long
13209 \end_inset 
13210 </cell>
13211 </row>
13212 <row topline="true">
13213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13214 \begin_inset Text
13215
13216 \layout Standard
13217
13218
13219 \family roman 
13220 \series medium 
13221 \shape up 
13222 \size normal 
13223 \emph off 
13224 \bar no 
13225 \noun off 
13226 \color none
13227 _uchar2fs.c
13228 \end_inset 
13229 </cell>
13230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13231 \begin_inset Text
13232
13233 \layout Standard
13234
13235
13236 \family roman 
13237 \series medium 
13238 \shape up 
13239 \size normal 
13240 \emph off 
13241 \bar no 
13242 \noun off 
13243 \color none
13244 convert unsigned char to floating point
13245 \end_inset 
13246 </cell>
13247 </row>
13248 <row topline="true">
13249 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13250 \begin_inset Text
13251
13252 \layout Standard
13253
13254
13255 \family roman 
13256 \series medium 
13257 \shape up 
13258 \size normal 
13259 \emph off 
13260 \bar no 
13261 \noun off 
13262 \color none
13263 _char2fs.c
13264 \end_inset 
13265 </cell>
13266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13267 \begin_inset Text
13268
13269 \layout Standard
13270
13271
13272 \family roman 
13273 \series medium 
13274 \shape up 
13275 \size normal 
13276 \emph off 
13277 \bar no 
13278 \noun off 
13279 \color none
13280 convert char to floating point number
13281 \end_inset 
13282 </cell>
13283 </row>
13284 <row topline="true">
13285 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13286 \begin_inset Text
13287
13288 \layout Standard
13289
13290
13291 \family roman 
13292 \series medium 
13293 \shape up 
13294 \size normal 
13295 \emph off 
13296 \bar no 
13297 \noun off 
13298 \color none
13299 _uint2fs.c
13300 \end_inset 
13301 </cell>
13302 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13303 \begin_inset Text
13304
13305 \layout Standard
13306
13307
13308 \family roman 
13309 \series medium 
13310 \shape up 
13311 \size normal 
13312 \emph off 
13313 \bar no 
13314 \noun off 
13315 \color none
13316 convert unsigned int to floating point
13317 \end_inset 
13318 </cell>
13319 </row>
13320 <row topline="true">
13321 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13322 \begin_inset Text
13323
13324 \layout Standard
13325
13326
13327 \family roman 
13328 \series medium 
13329 \shape up 
13330 \size normal 
13331 \emph off 
13332 \bar no 
13333 \noun off 
13334 \color none
13335 _int2fs.c
13336 \end_inset 
13337 </cell>
13338 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13339 \begin_inset Text
13340
13341 \layout Standard
13342
13343
13344 \family roman 
13345 \series medium 
13346 \shape up 
13347 \size normal 
13348 \emph off 
13349 \bar no 
13350 \noun off 
13351 \color none
13352 convert int to floating point numbers
13353 \end_inset 
13354 </cell>
13355 </row>
13356 <row topline="true">
13357 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13358 \begin_inset Text
13359
13360 \layout Standard
13361
13362
13363 \family roman 
13364 \series medium 
13365 \shape up 
13366 \size normal 
13367 \emph off 
13368 \bar no 
13369 \noun off 
13370 \color none
13371 _ulong2fs.c
13372 \end_inset 
13373 </cell>
13374 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13375 \begin_inset Text
13376
13377 \layout Standard
13378
13379
13380 \family roman 
13381 \series medium 
13382 \shape up 
13383 \size normal 
13384 \emph off 
13385 \bar no 
13386 \noun off 
13387 \color none
13388 convert unsigned long to floating point number
13389 \end_inset 
13390 </cell>
13391 </row>
13392 <row topline="true" bottomline="true">
13393 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13394 \begin_inset Text
13395
13396 \layout Standard
13397
13398
13399 \family roman 
13400 \series medium 
13401 \shape up 
13402 \size normal 
13403 \emph off 
13404 \bar no 
13405 \noun off 
13406 \color none
13407 _long2fs.c
13408 \end_inset 
13409 </cell>
13410 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13411 \begin_inset Text
13412
13413 \layout Standard
13414
13415
13416 \family roman 
13417 \series medium 
13418 \shape up 
13419 \size normal 
13420 \emph off 
13421 \bar no 
13422 \noun off 
13423 \color none
13424 convert long to floating point number
13425 \end_inset 
13426 </cell>
13427 </row>
13428 </lyxtabular>
13429
13430 \end_inset 
13431
13432
13433 \newline 
13434
13435 \layout Standard
13436
13437 These support routines are developed in ANSI-C so there is room for space
13438  and speed improvement.
13439  Note if all these routines are used simultaneously the data space might
13440  overflow.
13441  For serious floating point usage it is recommended that the large model
13442  be used.
13443  Also notice that you don't have to call this routines directly.
13444  The compiler will use them automatically every time a floating point operation
13445  is required.
13446 \layout Section
13447
13448 Library Routines
13449 \begin_inset LatexCommand \index{Libraries}
13450
13451 \end_inset 
13452
13453
13454 \layout Standard
13455
13456
13457 \emph on 
13458 <pending: this is messy and incomplete - a little more information is in
13459  sdcc/doc/libdoc.txt
13460 \emph default 
13461  >
13462 \layout Subsection
13463
13464 Compiler support routines (_gptrget, _mulint etc.)
13465 \layout Subsection
13466
13467 Stdclib functions (puts, printf, strcat etc.)
13468 \layout Subsubsection
13469
13470 <stdio.h>
13471 \layout Standard
13472
13473
13474 \begin_inset LatexCommand \index{<stdio.h>}
13475
13476 \end_inset 
13477
13478 As usual on embedded systems you have to provide your own 
13479 \family typewriter 
13480 getchar()
13481 \begin_inset LatexCommand \index{getchar()}
13482
13483 \end_inset 
13484
13485  
13486 \family default 
13487 and 
13488 \family typewriter 
13489 putchar()
13490 \begin_inset LatexCommand \index{putchar()}
13491
13492 \end_inset 
13493
13494
13495 \family default 
13496  routines.
13497  SDCC does not know whether the system connects to a serial line with or
13498  without handshake, LCD, keyboard or other device.
13499  You'll find examples for serial routines f.e.
13500  in sdcc/device/lib.
13501 \layout Standard
13502
13503 If you're short on memory you might want to use 
13504 \family typewriter 
13505 printf_small()
13506 \family default 
13507  
13508 \emph on 
13509 instead
13510 \emph default 
13511  of
13512 \family typewriter 
13513  printf()
13514 \begin_inset LatexCommand \index{printf()}
13515
13516 \end_inset 
13517
13518 .
13519
13520 \family default 
13521  For the mcs51 there is an assembly version 
13522 \family typewriter 
13523 printf_fast()
13524 \family default 
13525  which should fit the requirements of many embedded systems (by unsetting
13526  #defines it can be customized to 
13527 \emph on 
13528 not
13529 \emph default 
13530  support long variables and field widths).
13531 \layout Subsection
13532
13533 Math functions (sin, pow, sqrt etc.)
13534 \layout Subsection
13535
13536 Other libraries
13537 \layout Standard
13538
13539 Libraries
13540 \begin_inset LatexCommand \index{Libraries}
13541
13542 \end_inset 
13543
13544  included in SDCC should have a license at least as liberal as the GNU Lesser
13545  General Public License
13546 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13547
13548 \end_inset 
13549
13550  
13551 \emph on 
13552 LGPL
13553 \emph default 
13554 .
13555 \layout Comment
13556
13557 license statements for the libraries are missing.
13558  sdcc/device/lib/ser_ir.c
13559 \layout Comment
13560
13561 or _decdptr f.e.
13562  come with a GPL (as opposed to LGPL) License - this will not be liberal
13563  enough for many embedded programmers.
13564 \layout Standard
13565
13566 If you have ported some library or want to share experience about some code
13567  which f.e.
13568  falls into any of these categories Busses (I
13569 \begin_inset Formula $^{\textrm{2}}$
13570 \end_inset 
13571
13572 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13573  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13574  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
13575 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13576
13577 \end_inset 
13578
13579 \SpecialChar ~
13580 would certainly like to hear about it.
13581  Programmers coding for embedded systems are not especially famous for being
13582  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13583 e these references are very valuable.
13584  Let's help to create a climate where information is shared.
13585 \layout Section
13586
13587 Memory Models
13588 \layout Subsection
13589
13590 MCS51 Memory Models
13591 \begin_inset LatexCommand \index{Memory model}
13592
13593 \end_inset 
13594
13595
13596 \begin_inset LatexCommand \index{MCS51 memory model}
13597
13598 \end_inset 
13599
13600
13601 \layout Subsubsection
13602
13603 Small and Large
13604 \layout Standard
13605
13606 SDCC allows two memory models for MCS51 code, 
13607 \shape slanted 
13608 small
13609 \shape default 
13610  and 
13611 \shape slanted 
13612 large
13613 \shape default 
13614 .
13615  Modules compiled with different memory models should 
13616 \emph on 
13617 never
13618 \emph default 
13619  be combined together or the results would be unpredictable.
13620  The library routines supplied with the compiler are compiled as both small
13621  and large.
13622  The compiled library modules are contained in separate directories as small
13623  and large so that you can link to either set.
13624  
13625 \layout Standard
13626
13627 When the large model is used all variables declared without a storage class
13628  will be allocated into the external ram, this includes all parameters and
13629  local variables (for non-reentrant
13630 \begin_inset LatexCommand \index{reentrant}
13631
13632 \end_inset 
13633
13634  functions).
13635  When the small model is used variables without storage class are allocated
13636  in the internal ram.
13637 \layout Standard
13638
13639 Judicious usage of the processor specific storage classes
13640 \begin_inset LatexCommand \index{Storage class}
13641
13642 \end_inset 
13643
13644  and the 'reentrant' function type will yield much more efficient code,
13645  than using the large model.
13646  Several optimizations are disabled when the program is compiled using the
13647  large model, it is therefore recommended that the small model be used unless
13648  absolutely required.
13649 \layout Subsubsection
13650
13651 External Stack
13652 \begin_inset LatexCommand \label{sub:External-Stack}
13653
13654 \end_inset 
13655
13656
13657 \begin_inset LatexCommand \index{stack}
13658
13659 \end_inset 
13660
13661
13662 \begin_inset LatexCommand \index{External stack (mcs51)}
13663
13664 \end_inset 
13665
13666
13667 \layout Standard
13668
13669
13670 \series bold 
13671 Attention
13672 \series default 
13673 : this option wasn't maintained for a long time and is quite buggy.
13674  Small programs might work.
13675  You've been warned!
13676 \layout Standard
13677
13678 The external stack (-
13679 \begin_inset ERT
13680 status Collapsed
13681
13682 \layout Standard
13683
13684 \backslash 
13685 /
13686 \end_inset 
13687
13688 -xstack option
13689 \begin_inset LatexCommand \index{-\/-xstack}
13690
13691 \end_inset 
13692
13693 ) is located in pdata
13694 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13695
13696 \end_inset 
13697
13698  memory (usually at the start of the external ram segment) and is 256 bytes
13699  in size.
13700  When -
13701 \begin_inset ERT
13702 status Collapsed
13703
13704 \layout Standard
13705
13706 \backslash 
13707 /
13708 \end_inset 
13709
13710 -xstack option is used to compile the program, the parameters and local
13711  variables
13712 \begin_inset LatexCommand \index{local variables}
13713
13714 \end_inset 
13715
13716  of all reentrant functions are allocated in this area.
13717  This option is provided for programs with large stack space requirements.
13718  When used with the -
13719 \begin_inset ERT
13720 status Collapsed
13721
13722 \layout Standard
13723
13724 \backslash 
13725 /
13726 \end_inset 
13727
13728 -stack-auto
13729 \begin_inset LatexCommand \index{-\/-stack-auto}
13730
13731 \end_inset 
13732
13733  option, all parameters and local variables are allocated on the external
13734  stack (note: support libraries will need to be recompiled with the same
13735  options).
13736 \layout Standard
13737
13738 The compiler outputs the higher order address byte of the external ram segment
13739  into port P2
13740 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13741
13742 \end_inset 
13743
13744  (see also section 
13745 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13746
13747 \end_inset 
13748
13749 ), therefore when using the External Stack option, this port 
13750 \emph on 
13751 may not
13752 \emph default 
13753  be used by the application program.
13754 \layout Subsection
13755
13756 DS390 Memory Model
13757 \begin_inset LatexCommand \index{Memory model}
13758
13759 \end_inset 
13760
13761
13762 \begin_inset LatexCommand \index{DS390 memory model}
13763
13764 \end_inset 
13765
13766
13767 \layout Standard
13768
13769 The only model supported is Flat 24
13770 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13771
13772 \end_inset 
13773
13774 .
13775  This generates code for the 24 bit contiguous addressing mode of the Dallas
13776  DS80C390 part.
13777  In this mode, up to four meg of external RAM or code space can be directly
13778  addressed.
13779  See the data sheets at www.dalsemi.com for further information on this part.
13780 \newline 
13781
13782 \newline 
13783 Note that the compiler does not generate any code to place the processor
13784  into 24 bitmode (although 
13785 \emph on 
13786 tinibios
13787 \emph default 
13788  in the ds390 libraries will do that for you).
13789  If you don't use 
13790 \emph on 
13791 tinibios
13792 \emph default 
13793
13794 \begin_inset LatexCommand \index{Tinibios (DS390)}
13795
13796 \end_inset 
13797
13798 , the boot loader or similar code must ensure that the processor is in 24
13799  bit contiguous addressing mode before calling the SDCC startup code.
13800 \newline 
13801
13802 \newline 
13803 Like the 
13804 \emph on 
13805 -
13806 \begin_inset ERT
13807 status Collapsed
13808
13809 \layout Standard
13810
13811 \backslash 
13812 /
13813 \end_inset 
13814
13815 -model-large
13816 \emph default 
13817  option, variables will by default be placed into the XDATA segment.
13818  
13819 \newline 
13820
13821 \newline 
13822 Segments may be placed anywhere in the 4 meg address space using the usual
13823  -
13824 \begin_inset ERT
13825 status Collapsed
13826
13827 \layout Standard
13828
13829 \backslash 
13830 /
13831 \end_inset 
13832
13833 -*-loc options.
13834  Note that if any segments are located above 64K, the -r flag must be passed
13835  to the linker to generate the proper segment relocations, and the Intel
13836  HEX output format must be used.
13837  The -r flag can be passed to the linker by using the option 
13838 \emph on 
13839 -Wl-r
13840 \emph default 
13841  on the SDCC command line.
13842  However, currently the linker can not handle code segments > 64k.
13843 \layout Section
13844
13845 Pragmas
13846 \begin_inset LatexCommand \index{Pragmas}
13847
13848 \end_inset 
13849
13850
13851 \layout Standard
13852
13853 SDCC supports the following #pragma directives:
13854 \layout Itemize
13855
13856 save
13857 \begin_inset LatexCommand \index{\#pragma save}
13858
13859 \end_inset 
13860
13861  - this will save all current options to the save/restore stack.
13862  See #pragma\SpecialChar ~
13863 restore.
13864 \layout Itemize
13865
13866 restore
13867 \begin_inset LatexCommand \index{\#pragma restore}
13868
13869 \end_inset 
13870
13871  - will restore saved options from the last save.
13872  saves & restores can be nested.
13873  SDCC uses a save/restore stack: save pushes current options to the stack,
13874  restore pulls current options from the stack.
13875  See #pragma\SpecialChar ~
13876 save.
13877 \newline 
13878
13879 \layout Itemize
13880
13881 callee_saves
13882 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13883
13884 \end_inset 
13885
13886
13887 \begin_inset LatexCommand \index{function prologue}
13888
13889 \end_inset 
13890
13891  function1[,function2[,function3...]] - The compiler by default uses a caller
13892  saves convention for register saving across function calls, however this
13893  can cause unnecessary register pushing & popping
13894 \begin_inset LatexCommand \index{push/pop}
13895
13896 \end_inset 
13897
13898  when calling small functions from larger functions.
13899  This option can be used to switch off the register saving convention for
13900  the function names specified.
13901  The compiler will not save registers when calling these functions, extra
13902  code need to be manually inserted at the entry & exit for these functions
13903  to save & restore the registers used by these functions, this can SUBSTANTIALLY
13904  reduce code & improve run time performance of the generated code.
13905  In the future the compiler (with inter procedural analysis) may be able
13906  to determine the appropriate scheme to use for each function call.
13907  If -
13908 \begin_inset ERT
13909 status Collapsed
13910
13911 \layout Standard
13912
13913 \backslash 
13914 /
13915 \end_inset 
13916
13917 -callee-saves command line option is used, the function names specified
13918  in #pragma\SpecialChar ~
13919 callee_saves
13920 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13921
13922 \end_inset 
13923
13924  is appended to the list of functions specified in the command line.
13925 \layout Itemize
13926
13927 exclude
13928 \begin_inset LatexCommand \index{\#pragma exclude}
13929
13930 \end_inset 
13931
13932  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
13933  of pairs of push/pop
13934 \begin_inset LatexCommand \index{push/pop}
13935
13936 \end_inset 
13937
13938  instructions in 
13939 \emph on 
13940 I
13941 \emph default 
13942 nterrupt
13943 \begin_inset LatexCommand \index{interrupt}
13944
13945 \end_inset 
13946
13947  
13948 \emph on 
13949 S
13950 \emph default 
13951 ervice 
13952 \emph on 
13953 R
13954 \emph default 
13955 outines.
13956  The directive should be placed immediately before the ISR function definition
13957  and it affects ALL ISR functions following it.
13958  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
13959 exclude\SpecialChar ~
13960 none
13961 \begin_inset LatexCommand \index{\#pragma exclude}
13962
13963 \end_inset 
13964
13965 .
13966  See also the related keyword _naked
13967 \begin_inset LatexCommand \index{\_naked}
13968
13969 \end_inset 
13970
13971 .
13972 \layout Itemize
13973
13974 less_pedantic
13975 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
13976
13977 \end_inset 
13978
13979  - the compiler will not warn you anymore for obvious mistakes, you'r on
13980  your own now ;-(
13981 \layout Itemize
13982
13983 nogcse
13984 \begin_inset LatexCommand \index{\#pragma nogcse}
13985
13986 \end_inset 
13987
13988  - will stop global common subexpression elimination.
13989 \layout Itemize
13990
13991 noinduction
13992 \begin_inset LatexCommand \index{\#pragma noinduction}
13993
13994 \end_inset 
13995
13996  - will stop loop induction optimizations.
13997 \layout Itemize
13998
13999 noinvariant
14000 \begin_inset LatexCommand \index{\#pragma noinvariant}
14001
14002 \end_inset 
14003
14004  - will not do loop invariant optimizations.
14005  For more details see Loop Invariants in section
14006 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
14007
14008 \end_inset 
14009
14010 .
14011 \layout Itemize
14012
14013 noiv
14014 \begin_inset LatexCommand \index{\#pragma noiv}
14015
14016 \end_inset 
14017
14018  - Do not generate interrupt
14019 \begin_inset LatexCommand \index{interrupt}
14020
14021 \end_inset 
14022
14023  vector table entries for all ISR functions defined after the pragma.
14024  This is useful in cases where the interrupt vector table must be defined
14025  manually, or when there is a secondary, manually defined interrupt vector
14026  table (e.g.
14027  for the autovector feature of the Cypress EZ-USB FX2).
14028  More elegantly this can be achieved by obmitting the optional interrupt
14029  number after the interrupt keyword, see section 
14030 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
14031
14032 \end_inset 
14033
14034 \SpecialChar ~
14035 about interrupts.
14036 \layout Itemize
14037
14038 nojtbound
14039 \begin_inset LatexCommand \index{\#pragma nojtbound}
14040
14041 \end_inset 
14042
14043  - will not generate code for boundary value checking, when switch statements
14044  are turned into jump-tables (dangerous).
14045  For more details see section 
14046 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
14047
14048 \end_inset 
14049
14050 .
14051 \layout Itemize
14052
14053 noloopreverse
14054 \begin_inset LatexCommand \index{\#pragma noloopreverse}
14055
14056 \end_inset 
14057
14058  - Will not do loop reversal optimization
14059 \layout Itemize
14060
14061 nooverlay
14062 \begin_inset LatexCommand \index{\#pragma nooverlay}
14063
14064 \end_inset 
14065
14066  - the compiler will not overlay the parameters and local variables of a
14067  function.
14068 \layout Itemize
14069
14070 stackauto
14071 \begin_inset LatexCommand \index{\#pragma stackauto}
14072
14073 \end_inset 
14074
14075 - See option -
14076 \begin_inset ERT
14077 status Collapsed
14078
14079 \layout Standard
14080
14081 \backslash 
14082 /
14083 \end_inset 
14084
14085 -stack-auto
14086 \begin_inset LatexCommand \index{-\/-stack-auto}
14087
14088 \end_inset 
14089
14090  and section 
14091 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
14092
14093 \end_inset 
14094
14095  Parameters and Local Variables.
14096 \layout Standard
14097
14098 SDCPP supports the following #pragma directives:
14099 \layout Itemize
14100
14101 preproc_asm
14102 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
14103
14104 \end_inset 
14105
14106  (+ | -) - switch _asm _endasm block preprocessing on / off.
14107  Default is on.
14108 \layout Standard
14109
14110 The pragma's are intended to be used to turn-on or off certain optimizations
14111  which might cause the compiler to generate extra stack / data space to
14112  store compiler generated temporary variables.
14113  This usually happens in large functions.
14114  Pragma directives should be used as shown in the following example, they
14115  are used to control options & optimizations for a given function; pragmas
14116  should be placed before and/or after a function, placing pragma's inside
14117  a function body could have unpredictable results.
14118 \layout Verse
14119
14120
14121 \family typewriter 
14122 #pragma save
14123 \begin_inset LatexCommand \index{\#pragma save}
14124
14125 \end_inset 
14126
14127  \SpecialChar ~
14128 \SpecialChar ~
14129 \SpecialChar ~
14130 \SpecialChar ~
14131 \SpecialChar ~
14132 \SpecialChar ~
14133 \SpecialChar ~
14134 /* save the current settings */ 
14135 \newline 
14136 #pragma nogcse
14137 \begin_inset LatexCommand \index{\#pragma nogcse}
14138
14139 \end_inset 
14140
14141  \SpecialChar ~
14142 \SpecialChar ~
14143 \SpecialChar ~
14144 \SpecialChar ~
14145 \SpecialChar ~
14146 /* turnoff global subexpression elimination */ 
14147 \newline 
14148 #pragma noinduction
14149 \begin_inset LatexCommand \index{\#pragma noinduction}
14150
14151 \end_inset 
14152
14153  /* turn off induction optimizations */ 
14154 \newline 
14155 int foo () 
14156 \newline 
14157
14158 \newline 
14159 \SpecialChar ~
14160  \SpecialChar ~
14161  ...
14162  
14163 \newline 
14164 \SpecialChar ~
14165  \SpecialChar ~
14166  /* large code */ 
14167 \newline 
14168 \SpecialChar ~
14169  \SpecialChar ~
14170  ...
14171  
14172 \newline 
14173
14174 \newline 
14175 #pragma restore
14176 \begin_inset LatexCommand \index{\#pragma restore}
14177
14178 \end_inset 
14179
14180  /* turn the optimizations back on */
14181 \layout Standard
14182
14183 The compiler will generate a warning message when extra space is allocated.
14184  It is strongly recommended that the save and restore pragma's be used when
14185  changing options for a function.
14186 \layout Section
14187
14188 Defines Created by the Compiler
14189 \layout Standard
14190
14191 The compiler creates the following #defines
14192 \begin_inset LatexCommand \index{\#defines}
14193
14194 \end_inset 
14195
14196
14197 \begin_inset LatexCommand \index{Defines created by the compiler}
14198
14199 \end_inset 
14200
14201 :
14202 \newline 
14203
14204 \layout Standard
14205
14206
14207 \begin_inset  Tabular
14208 <lyxtabular version="3" rows="10" columns="2">
14209 <features>
14210 <column alignment="center" valignment="top" leftline="true" width="0">
14211 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14212 <row topline="true" bottomline="true">
14213 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14214 \begin_inset Text
14215
14216 \layout Standard
14217
14218
14219 \series bold 
14220 #define
14221 \end_inset 
14222 </cell>
14223 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14224 \begin_inset Text
14225
14226 \layout Standard
14227
14228
14229 \series bold 
14230 Description
14231 \end_inset 
14232 </cell>
14233 </row>
14234 <row topline="true">
14235 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14236 \begin_inset Text
14237
14238 \layout Standard
14239
14240 SDCC
14241 \begin_inset LatexCommand \index{SDCC}
14242
14243 \end_inset 
14244
14245  
14246 \end_inset 
14247 </cell>
14248 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14249 \begin_inset Text
14250
14251 \layout Standard
14252
14253 this Symbol is always defined
14254 \end_inset 
14255 </cell>
14256 </row>
14257 <row topline="true">
14258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14259 \begin_inset Text
14260
14261 \layout Standard
14262
14263 SDCC_mcs51
14264 \begin_inset LatexCommand \index{SDCC\_mcs51}
14265
14266 \end_inset 
14267
14268  or SDCC_ds390
14269 \begin_inset LatexCommand \index{SDCC\_ds390}
14270
14271 \end_inset 
14272
14273  or SDCC_z80
14274 \begin_inset LatexCommand \index{SDCC\_z80}
14275
14276 \end_inset 
14277
14278 , etc
14279 \end_inset 
14280 </cell>
14281 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14282 \begin_inset Text
14283
14284 \layout Standard
14285
14286 depending on the model used (e.g.: -mds390
14287 \end_inset 
14288 </cell>
14289 </row>
14290 <row topline="true">
14291 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14292 \begin_inset Text
14293
14294 \layout Standard
14295
14296 __mcs51
14297 \begin_inset LatexCommand \index{\_\_mcs51}
14298
14299 \end_inset 
14300
14301 , __ds390
14302 \begin_inset LatexCommand \index{\_\_ds390}
14303
14304 \end_inset 
14305
14306 , __hc08
14307 \begin_inset LatexCommand \index{\_\_hc08}
14308
14309 \end_inset 
14310
14311 , __z80
14312 \begin_inset LatexCommand \index{\_\_z80}
14313
14314 \end_inset 
14315
14316 , etc
14317 \end_inset 
14318 </cell>
14319 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14320 \begin_inset Text
14321
14322 \layout Standard
14323
14324 depending on the model used (e.g.
14325  -mz80)
14326 \end_inset 
14327 </cell>
14328 </row>
14329 <row topline="true">
14330 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14331 \begin_inset Text
14332
14333 \layout Standard
14334
14335 SDCC_STACK_AUTO
14336 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
14337
14338 \end_inset 
14339
14340
14341 \end_inset 
14342 </cell>
14343 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14344 \begin_inset Text
14345
14346 \layout Standard
14347
14348 when 
14349 \emph on 
14350 -
14351 \begin_inset ERT
14352 status Collapsed
14353
14354 \layout Standard
14355
14356 \backslash 
14357 /
14358 \end_inset 
14359
14360 -stack-auto
14361 \emph default 
14362  option is used
14363 \end_inset 
14364 </cell>
14365 </row>
14366 <row topline="true">
14367 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14368 \begin_inset Text
14369
14370 \layout Standard
14371
14372 SDCC_MODEL_SMALL
14373 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
14374
14375 \end_inset 
14376
14377
14378 \end_inset 
14379 </cell>
14380 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14381 \begin_inset Text
14382
14383 \layout Standard
14384
14385 when 
14386 \emph on 
14387 -
14388 \begin_inset ERT
14389 status Collapsed
14390
14391 \layout Standard
14392
14393 \backslash 
14394 /
14395 \end_inset 
14396
14397 -model-small
14398 \emph default 
14399  is used
14400 \end_inset 
14401 </cell>
14402 </row>
14403 <row topline="true">
14404 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14405 \begin_inset Text
14406
14407 \layout Standard
14408
14409 SDCC_MODEL_LARGE
14410 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14411
14412 \end_inset 
14413
14414
14415 \end_inset 
14416 </cell>
14417 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14418 \begin_inset Text
14419
14420 \layout Standard
14421
14422 when 
14423 \emph on 
14424 -
14425 \begin_inset ERT
14426 status Collapsed
14427
14428 \layout Standard
14429
14430 \backslash 
14431 /
14432 \end_inset 
14433
14434 -model-large
14435 \emph default 
14436  is used
14437 \end_inset 
14438 </cell>
14439 </row>
14440 <row topline="true">
14441 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14442 \begin_inset Text
14443
14444 \layout Standard
14445
14446 SDCC_USE_XSTACK
14447 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14448
14449 \end_inset 
14450
14451
14452 \end_inset 
14453 </cell>
14454 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14455 \begin_inset Text
14456
14457 \layout Standard
14458
14459 when 
14460 \emph on 
14461 -
14462 \begin_inset ERT
14463 status Collapsed
14464
14465 \layout Standard
14466
14467 \backslash 
14468 /
14469 \end_inset 
14470
14471 -xstack
14472 \emph default 
14473  option is used
14474 \end_inset 
14475 </cell>
14476 </row>
14477 <row topline="true">
14478 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14479 \begin_inset Text
14480
14481 \layout Standard
14482
14483 SDCC_STACK_TENBIT
14484 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14485
14486 \end_inset 
14487
14488  
14489 \end_inset 
14490 </cell>
14491 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14492 \begin_inset Text
14493
14494 \layout Standard
14495
14496 when 
14497 \emph on 
14498 -mds390
14499 \emph default 
14500  is used
14501 \end_inset 
14502 </cell>
14503 </row>
14504 <row topline="true" bottomline="true">
14505 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14506 \begin_inset Text
14507
14508 \layout Standard
14509
14510 SDCC_MODEL_FLAT24
14511 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14512
14513 \end_inset 
14514
14515
14516 \end_inset 
14517 </cell>
14518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14519 \begin_inset Text
14520
14521 \layout Standard
14522
14523 when 
14524 \emph on 
14525 -mds390
14526 \emph default 
14527  is used
14528 \end_inset 
14529 </cell>
14530 </row>
14531 </lyxtabular>
14532
14533 \end_inset 
14534
14535
14536 \layout Chapter
14537
14538 Notes on supported Processors
14539 \layout Section
14540
14541 MCS51 variants
14542 \begin_inset LatexCommand \label{sub:MCS51-variants}
14543
14544 \end_inset 
14545
14546
14547 \begin_inset LatexCommand \index{MCS51 variants}
14548
14549 \end_inset 
14550
14551
14552 \layout Standard
14553
14554 MCS51 processors are available from many vendors and come in many different
14555  flavours.
14556  While they might differ considerably in respect to Special Function Registers
14557  the core MCS51 is usually not modified or is kept compatible.
14558  
14559 \layout Subsection
14560
14561 pdata access by SFR 
14562 \layout Standard
14563
14564 With the upcome of devices with internal xdata and flash memory devices
14565  using port P2
14566 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14567
14568 \end_inset 
14569
14570  as dedicated I/O port is becoming more popular.
14571  Switching the high byte for pdata
14572 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14573
14574 \end_inset 
14575
14576  access which was formerly done by port P2 is then achieved by a Special
14577  Function Register
14578 \begin_inset LatexCommand \index{sfr}
14579
14580 \end_inset 
14581
14582 .
14583  In well-established MCS51 tradition the address of this 
14584 \emph on 
14585 sfr
14586 \emph default 
14587  is where the chip designers decided to put it.
14588  Needless to say that they didn't agree on a common name either.
14589  So that the startup code can correctly initialize xdata variables, you
14590  should define an sfr with the name _XPAGE
14591 \family typewriter 
14592
14593 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
14594
14595 \end_inset 
14596
14597
14598 \family default 
14599  at the appropriate location if the default, port P2, is not used for this.
14600  Some examples are:
14601 \layout Verse
14602
14603
14604 \family typewriter 
14605 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
14606 \layout Verse
14607
14608
14609 \family typewriter 
14610 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
14611 \layout Verse
14612
14613
14614 \family typewriter 
14615 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
14616 \layout Standard
14617
14618 For more exotic implementations further customizations may be needed.
14619  See section 
14620 \begin_inset LatexCommand \ref{sub:Startup-Code}
14621
14622 \end_inset 
14623
14624  for other possibilities.
14625 \layout Subsection
14626
14627 Other Features available by SFR
14628 \layout Standard
14629
14630 Some MCS51 variants offer features like Double DPTR
14631 \begin_inset LatexCommand \index{DPTR}
14632
14633 \end_inset 
14634
14635 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14636  These are currently not used for the MCS51 port.
14637  If you absolutely need them you can fall back to inline assembly or submit
14638  a patch to SDCC.
14639 \layout Section
14640
14641 DS400 port
14642 \layout Standard
14643
14644 The DS80C400 microcontroller has a rich set of peripherals.
14645  In its built-in ROM library it includes functions to access some of the
14646  features, among them is a TCP stack with IP4 and IP6 support.
14647  Library headers (currently in beta status) and other files are provided
14648  at 
14649 \size footnotesize 
14650
14651 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
14652
14653 \end_inset 
14654
14655 .
14656  
14657 \layout Section
14658
14659 The Z80 and gbz80 port
14660 \layout Standard
14661
14662 SDCC can target both the Zilog 
14663 \begin_inset LatexCommand \index{Z80}
14664
14665 \end_inset 
14666
14667  and the Nintendo Gameboy's Z80-like gbz80
14668 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14669
14670 \end_inset 
14671
14672 .
14673  The Z80 port is passed through the same 
14674 \emph on 
14675 regressions tests
14676 \begin_inset LatexCommand \index{Regression test}
14677
14678 \end_inset 
14679
14680
14681 \emph default 
14682  as the MCS51 and DS390 ports, so floating point support, support for long
14683  variables and bitfield support is fine.
14684  See mailing lists and forums about interrupt routines.
14685 \layout Standard
14686
14687 As always, the code is the authoritative reference - see z80/ralloc.c and
14688  z80/gen.c.
14689  The stack
14690 \begin_inset LatexCommand \index{stack}
14691
14692 \end_inset 
14693
14694  frame is similar to that generated by the IAR Z80 compiler.
14695  IX is used as the base pointer, HL and IY are used as a temporary registers,
14696  and BC and DE are available for holding variables.
14697  Return values
14698 \begin_inset LatexCommand \index{return value}
14699
14700 \end_inset 
14701
14702  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
14703  bytes).
14704  The gbz80 port use the same set of registers for the return values, but
14705  in a different order of significance: E (one byte), DE (two bytes), or
14706  HLDE (four bytes).
14707 \layout Section
14708
14709 The HC08 port
14710 \layout Standard
14711
14712 The port to the Motorola HC08
14713 \begin_inset LatexCommand \index{HC08}
14714
14715 \end_inset 
14716
14717  family has been added in October 2003, and is still undergoing some basic
14718  development.
14719  The code generator is complete, but the register allocation is still quite
14720  unoptimized.
14721  Some of the SDCC's standard C library functions have embedded non-HC08
14722  inline assembly and so are not yet usable.
14723 \newline 
14724
14725 \newline 
14726
14727 \layout Section
14728
14729 The PIC14 port
14730 \layout Standard
14731
14732 The 14bit PIC
14733 \begin_inset LatexCommand \index{PIC14}
14734
14735 \end_inset 
14736
14737  port still requires a major effort from the development community.
14738  However it can work for very simple code.
14739 \layout Subsection
14740
14741 C code and 14bit PIC code page
14742 \begin_inset LatexCommand \index{code page (pic14)}
14743
14744 \end_inset 
14745
14746  and RAM banks
14747 \begin_inset LatexCommand \index{RAM bank (pic14)}
14748
14749 \end_inset 
14750
14751
14752 \layout Standard
14753
14754 The linker organizes allocation for the code page and RAM banks.
14755  It does not have intimate knowledge of the code flow.
14756  It will put all the code section of a single asm file into a single code
14757  page.
14758  In order to make use of multiple code pages, separate asm files must be
14759  used.
14760  The compiler treats all functions of a single C file as being in the same
14761  code page unless it is non static.
14762  The compiler treats all local variables of a single C file as being in
14763  the same RAM bank unless it is an extern.
14764 \newline 
14765
14766 \newline 
14767 To get the best follow these guide lines:
14768 \layout Enumerate
14769
14770 make local functions static, as non static functions require code page selection
14771  overhead.
14772 \layout Enumerate
14773
14774 Make local variables static as extern variables require RAM bank selection
14775  overhead.
14776 \layout Enumerate
14777
14778 For devices that have multiple code pages it is more efficient to use the
14779  same number of files as pages, i.e.
14780  for the 16F877 use 4 separate files and i.e.
14781  for the 16F874 use 2 separate files.
14782  This way the linker can put the code for each file into different code
14783  pages and the compiler can allocate reusable variables more efficiently
14784  and there's less page selection overhead.
14785  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
14786  instruction set) use 'unsigned char' whereever possible instead of 'int'.
14787 \layout Subsection
14788
14789 Creating a device include file 
14790 \layout Standard
14791
14792 For generating a device include file use the support perl script inc2h.pl
14793  kept in directory support/script.
14794 \layout Subsection
14795
14796 Interrupt code
14797 \layout Standard
14798
14799 For the interrupt function, use the keyword 'interrupt'
14800 \begin_inset LatexCommand \index{interrupt}
14801
14802 \end_inset 
14803
14804  with level number of 0 (PIC14 only has 1 interrupt so this number is only
14805  there to avoid a syntax error - it ought to be fixed).
14806  E.g.:
14807 \layout Verse
14808
14809
14810 \family typewriter 
14811 void Intr(void) interrupt 0
14812 \newline 
14813 {
14814 \newline 
14815 \SpecialChar ~
14816 \SpecialChar ~
14817 T0IF = 0; /* Clear timer interrupt */
14818 \newline 
14819 }
14820 \layout Subsection
14821
14822 Linking and assembling
14823 \layout Standard
14824
14825 For assembling you can use either GPUTILS'
14826 \begin_inset LatexCommand \index{gputils (pic tools)}
14827
14828 \end_inset 
14829
14830  gpasm.exe or MPLAB's mpasmwin.exe.
14831  GPUTILS is available from 
14832 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
14833
14834 \end_inset 
14835
14836 .
14837  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
14838  If you use MPLAB and an interrupt function then the linker script file
14839  vectors section will need to be enlarged to link with mplink.
14840 \newline 
14841
14842 \newline 
14843 Here is a 
14844 \family typewriter 
14845 Makefile
14846 \family default 
14847  using GPUTILS:
14848 \layout Verse
14849
14850
14851 \family typewriter 
14852 .c.o:
14853 \newline 
14854 \SpecialChar ~
14855 \SpecialChar ~
14856 \SpecialChar ~
14857 \SpecialChar ~
14858 \SpecialChar ~
14859 \SpecialChar ~
14860 \SpecialChar ~
14861 \SpecialChar ~
14862 sdcc -S -V -mpic14 -p16F877 $< 
14863 \newline 
14864 \SpecialChar ~
14865 \SpecialChar ~
14866 \SpecialChar ~
14867 \SpecialChar ~
14868 \SpecialChar ~
14869 \SpecialChar ~
14870 \SpecialChar ~
14871 \SpecialChar ~
14872 gpasm -c $*.asm
14873 \newline 
14874
14875 \newline 
14876 $(PRJ).hex: $(OBJS) 
14877 \newline 
14878 \SpecialChar ~
14879 \SpecialChar ~
14880 \SpecialChar ~
14881 \SpecialChar ~
14882 \SpecialChar ~
14883 \SpecialChar ~
14884 \SpecialChar ~
14885 \SpecialChar ~
14886 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
14887 \layout Standard
14888
14889 Here is a 
14890 \family typewriter 
14891 Makefile
14892 \family default 
14893  using MPLAB:
14894 \layout Verse
14895
14896
14897 \family typewriter 
14898 .c.o: 
14899 \newline 
14900 \SpecialChar ~
14901 \SpecialChar ~
14902 \SpecialChar ~
14903 \SpecialChar ~
14904 \SpecialChar ~
14905 \SpecialChar ~
14906 \SpecialChar ~
14907 \SpecialChar ~
14908 sdcc -S -V -mpic14 -p16F877 $< 
14909 \newline 
14910 \SpecialChar ~
14911 \SpecialChar ~
14912 \SpecialChar ~
14913 \SpecialChar ~
14914 \SpecialChar ~
14915 \SpecialChar ~
14916 \SpecialChar ~
14917 \SpecialChar ~
14918 mpasmwin /q /o $*.asm
14919 \newline 
14920
14921 \newline 
14922 $(PRJ).hex: $(OBJS) 
14923 \newline 
14924 \SpecialChar ~
14925 \SpecialChar ~
14926 \SpecialChar ~
14927 \SpecialChar ~
14928 \SpecialChar ~
14929 \SpecialChar ~
14930 \SpecialChar ~
14931 \SpecialChar ~
14932 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
14933 \layout Standard
14934
14935 Please note that indentations within a
14936 \family typewriter 
14937  Makefile
14938 \family default 
14939  have to be done with a tabulator character.
14940 \layout Section
14941
14942 The PIC16
14943 \begin_inset LatexCommand \index{PIC16}
14944
14945 \end_inset 
14946
14947  port
14948 \layout Standard
14949
14950 The PIC16
14951 \begin_inset LatexCommand \index{PIC16}
14952
14953 \end_inset 
14954
14955  port is the portion of SDCC that is responsible to produce code for the
14956  Microchip
14957 \begin_inset LatexCommand \index{Microchip}
14958
14959 \end_inset 
14960
14961 (TM) microcontrollers with 16 bit core.
14962  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
14963 \layout Subsection
14964
14965 Global Options
14966 \layout Standard
14967
14968 PIC16 port supports the standard command line arguments as supposed, with
14969  the exception of certain cases that will be mentioned in the following
14970  list:
14971 \layout List
14972 \labelwidthstring 00.00.0000
14973
14974 -
14975 \begin_inset ERT
14976 status Collapsed
14977
14978 \layout Standard
14979
14980 \backslash 
14981 /
14982 \end_inset 
14983
14984 -stack-auto Auto variables that are function parameters, will be saved on
14985  stack by default.
14986  
14987 \emph on 
14988 There is no need to specify this in the command line.
14989 \layout List
14990 \labelwidthstring 00.00.0000
14991
14992 -
14993 \begin_inset ERT
14994 status Collapsed
14995
14996 \layout Standard
14997
14998 \backslash 
14999 /
15000 \end_inset 
15001
15002 -float-reent All floating point functions are reentrant by default.
15003  
15004 \emph on 
15005 There is no need to specifiy this in the command line.
15006 \layout List
15007 \labelwidthstring 00.00.0000
15008
15009 -
15010 \begin_inset ERT
15011 status Collapsed
15012
15013 \layout Standard
15014
15015 \backslash 
15016 /
15017 \end_inset 
15018
15019 -callee-saves See -
15020 \begin_inset ERT
15021 status Collapsed
15022
15023 \layout Standard
15024
15025 \backslash 
15026 /
15027 \end_inset 
15028
15029 -all-callee-saves
15030 \layout List
15031 \labelwidthstring 00.00.0000
15032
15033 -
15034 \begin_inset ERT
15035 status Collapsed
15036
15037 \layout Standard
15038
15039 \backslash 
15040 /
15041 \end_inset 
15042
15043 -all-callee-saves All function arguments are passed on stack by default.
15044  
15045 \emph on 
15046 There is no need to specify this in the command line.
15047 \layout List
15048 \labelwidthstring 00.00.0000
15049
15050 -
15051 \begin_inset ERT
15052 status Collapsed
15053
15054 \layout Standard
15055
15056 \backslash 
15057 /
15058 \end_inset 
15059
15060 -fommit-frame-pointer Frame pointer will be omitted when the function uses
15061  no local variables.
15062 \layout Subsection
15063
15064 Port Specific Options
15065 \begin_inset LatexCommand \index{Options PIC16}
15066
15067 \end_inset 
15068
15069
15070 \layout Standard
15071
15072 The port specific options appear after the global options in the sdcc --help
15073  output.
15074 \layout Subsubsection
15075
15076 General Options
15077 \layout Standard
15078
15079 General options enable certain port features and optimizations.
15080 \layout List
15081 \labelwidthstring 00.00.0000
15082
15083 -
15084 \begin_inset ERT
15085 status Collapsed
15086
15087 \layout Standard
15088
15089 \backslash 
15090 /
15091 \end_inset 
15092
15093 -pgen-bank Instructs the port to insert BANKSEL directives before instructions
15094  that use the Bank Select Register (BSR).
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 -pomit-config-words Instructs the port to omit the generation of the configurati
15109 on words.
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-ivt Instructs the port to omit the generation of the interrupt vectors
15124 \layout List
15125 \labelwidthstring 00.00.0000
15126
15127 -
15128 \begin_inset ERT
15129 status Collapsed
15130
15131 \layout Standard
15132
15133 \backslash 
15134 /
15135 \end_inset 
15136
15137 -pleave-reset-vector Used in conjuction with the previous command, instructs
15138  the port NOT to omit the reset vector.
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 -stack-model=[model] Used in conjuction with the command above.
15153  Defines the stack model to be used, valid stack models are : 
15154 \begin_deeper 
15155 \layout List
15156 \labelwidthstring 00.00.0000
15157
15158
15159 \emph on 
15160 small
15161 \emph default 
15162  Selects small stack model.
15163  8 bit stack and frame pointers.
15164  Supports 256 bytes stack size.
15165 \layout List
15166 \labelwidthstring 00.00.0000
15167
15168
15169 \emph on 
15170 large
15171 \emph default 
15172  Selects large stack model.
15173  16 bit stack and frame pointers.
15174  Supports 65536 bytes stack size.
15175 \end_deeper 
15176 \layout List
15177 \labelwidthstring 00.00.0000
15178
15179 -
15180 \begin_inset ERT
15181 status Collapsed
15182
15183 \layout Standard
15184
15185 \backslash 
15186 /
15187 \end_inset 
15188
15189 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
15190  unitialized data variables with [kword].
15191  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
15192 \layout List
15193 \labelwidthstring 00.00.0000
15194
15195 -
15196 \begin_inset ERT
15197 status Collapsed
15198
15199 \layout Standard
15200
15201 \backslash 
15202 /
15203 \end_inset 
15204
15205 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
15206  Useful for bootloaders.
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 -asm= sets the full path and name of an external assembler to call.
15221 \layout List
15222 \labelwidthstring 00.00.0000
15223
15224 -
15225 \begin_inset ERT
15226 status Collapsed
15227
15228 \layout Standard
15229
15230 \backslash 
15231 /
15232 \end_inset 
15233
15234 -link= sets the full path and name of an external linker to call.
15235 \layout Subsubsection
15236
15237 Debugging Options
15238 \layout Standard
15239
15240 Debugging options enable extra debugging information in the output files.
15241 \layout List
15242 \labelwidthstring 00.00.0000
15243
15244 -
15245 \begin_inset ERT
15246 status Collapsed
15247
15248 \layout Standard
15249
15250 \backslash 
15251 /
15252 \end_inset 
15253
15254 -debug-xtra Similar to -
15255 \begin_inset ERT
15256 status Collapsed
15257
15258 \layout Standard
15259
15260 \backslash 
15261 /
15262 \end_inset 
15263
15264 -debug
15265 \begin_inset LatexCommand \index{-\/-debug}
15266
15267 \end_inset 
15268
15269 , but dumps more information.
15270 \layout List
15271 \labelwidthstring 00.00.0000
15272
15273 -
15274 \begin_inset ERT
15275 status Collapsed
15276
15277 \layout Standard
15278
15279 \backslash 
15280 /
15281 \end_inset 
15282
15283 -debug-ralloc Force register allocator to dump <source>.d file with debugging
15284  information.
15285  <source> is the name of the file compiled.
15286 \layout List
15287 \labelwidthstring 00.00.0000
15288
15289 -
15290 \begin_inset ERT
15291 status Collapsed
15292
15293 \layout Standard
15294
15295 \backslash 
15296 /
15297 \end_inset 
15298
15299 -pcode-verbose Enable pcode debugging information in translation.
15300 \layout Subsection
15301
15302 Preprocessor Macros
15303 \layout Standard
15304
15305 PIC16 port defines the following preprocessor macros while translating a
15306  source.
15307 \layout Standard
15308 \align center 
15309
15310 \begin_inset  Tabular
15311 <lyxtabular version="3" rows="2" columns="2">
15312 <features>
15313 <column alignment="center" valignment="top" leftline="true" width="0">
15314 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15315 <row topline="true" bottomline="true">
15316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15317 \begin_inset Text
15318
15319 \layout Standard
15320
15321 Macro
15322 \end_inset 
15323 </cell>
15324 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15325 \begin_inset Text
15326
15327 \layout Standard
15328
15329 Description
15330 \end_inset 
15331 </cell>
15332 </row>
15333 <row topline="true" bottomline="true">
15334 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15335 \begin_inset Text
15336
15337 \layout Standard
15338
15339 pic18fxxxx
15340 \end_inset 
15341 </cell>
15342 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15343 \begin_inset Text
15344
15345 \layout Standard
15346
15347 MCU Identification.
15348  
15349 \emph on 
15350 xxxx
15351 \emph default 
15352  is the microcontrol identification number, i.e.
15353  452, 6620, etc
15354 \end_inset 
15355 </cell>
15356 </row>
15357 </lyxtabular>
15358
15359 \end_inset 
15360
15361
15362 \layout Subsection
15363
15364 Directories
15365 \layout Standard
15366
15367 PIC16
15368 \begin_inset LatexCommand \index{PIC16}
15369
15370 \end_inset 
15371
15372  port uses the following directories for searching header files and libraries.
15373 \layout Standard
15374 \align center 
15375
15376 \begin_inset  Tabular
15377 <lyxtabular version="3" rows="3" columns="4">
15378 <features>
15379 <column alignment="center" valignment="top" leftline="true" width="0">
15380 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15381 <column alignment="center" valignment="top" width="0">
15382 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15383 <row topline="true" bottomline="true">
15384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15385 \begin_inset Text
15386
15387 \layout Standard
15388
15389 Directory
15390 \end_inset 
15391 </cell>
15392 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15393 \begin_inset Text
15394
15395 \layout Standard
15396
15397 Description
15398 \end_inset 
15399 </cell>
15400 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15401 \begin_inset Text
15402
15403 \layout Standard
15404
15405 Target
15406 \end_inset 
15407 </cell>
15408 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15409 \begin_inset Text
15410
15411 \layout Standard
15412
15413 Command prefix
15414 \end_inset 
15415 </cell>
15416 </row>
15417 <row topline="true">
15418 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15419 \begin_inset Text
15420
15421 \layout Standard
15422
15423 PREFIX/sdcc/include/pic16
15424 \end_inset 
15425 </cell>
15426 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15427 \begin_inset Text
15428
15429 \layout Standard
15430
15431 PIC16 specific headers
15432 \end_inset 
15433 </cell>
15434 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15435 \begin_inset Text
15436
15437 \layout Standard
15438
15439 Compiler
15440 \end_inset 
15441 </cell>
15442 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15443 \begin_inset Text
15444
15445 \layout Standard
15446
15447 -I
15448 \end_inset 
15449 </cell>
15450 </row>
15451 <row topline="true" bottomline="true">
15452 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15453 \begin_inset Text
15454
15455 \layout Standard
15456
15457 PREFIX/sdcc/lib/pic16
15458 \end_inset 
15459 </cell>
15460 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15461 \begin_inset Text
15462
15463 \layout Standard
15464
15465 PIC16 specific libraries
15466 \end_inset 
15467 </cell>
15468 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15469 \begin_inset Text
15470
15471 \layout Standard
15472
15473 Linker
15474 \end_inset 
15475 </cell>
15476 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15477 \begin_inset Text
15478
15479 \layout Standard
15480
15481 -L
15482 \end_inset 
15483 </cell>
15484 </row>
15485 </lyxtabular>
15486
15487 \end_inset 
15488
15489
15490 \layout Subsection
15491
15492 Pragmas
15493 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
15494
15495 \end_inset 
15496
15497
15498 \layout Standard
15499
15500 PIC16 port currently supports the following pragmas:
15501 \layout List
15502 \labelwidthstring 00.00.0000
15503
15504 stack pragma stack forces the code generator to initialize the stack & frame
15505  pointers at a specific address.
15506  This is an adhoc solution since gplink does not support yet stack.
15507  When the gplink issue is resolved the pragma will be deprecated
15508 \begin_inset Foot
15509 collapsed true
15510
15511 \layout Standard
15512
15513
15514 \emph on 
15515 It is important to initialize the stack, otherwise strange things can happen.
15516  Stack is not initialized by default because there are some sources that
15517  do not require it.
15518  (like library sources)
15519 \end_inset 
15520
15521 .
15522 \newline 
15523 The stack pragma should be used only once in a project.
15524  Multiple pragmas may result in indeterminate behaviour of the program.
15525 \layout LyX-Code
15526
15527 Example:
15528 \layout LyX-Code
15529
15530 \layout LyX-Code
15531
15532 /* initializes stack at RAM address 0x5ff */
15533 \layout LyX-Code
15534
15535 #pragma stack 0x5ff
15536 \layout List
15537 \labelwidthstring 00.00.0000
15538
15539 udata pragma udata instructs the compiler to emit code so that linker will
15540  place a variable at a specific memory bank
15541 \layout LyX-Code
15542
15543 Example:
15544 \layout LyX-Code
15545
15546 \layout LyX-Code
15547
15548 /* places variable foo at bank2 */
15549 \layout LyX-Code
15550
15551 #pragma udata bank2 foo
15552 \layout LyX-Code
15553
15554 char foo;
15555 \layout Standard
15556
15557 In order for this pragma to work there are some changes that must be made
15558  in the .lkr script used in link stage.
15559  In the following example a sample .lkr file is shown:
15560 \layout LyX-Code
15561
15562 \layout LyX-Code
15563
15564 // Sample linker script for the PIC18F452 processor
15565 \layout LyX-Code
15566
15567 LIBPATH .
15568 \layout LyX-Code
15569
15570 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
15571 \layout LyX-Code
15572
15573 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
15574 \layout LyX-Code
15575
15576 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
15577 \layout LyX-Code
15578
15579 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
15580 \layout LyX-Code
15581
15582 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
15583 \layout LyX-Code
15584
15585 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
15586 \layout LyX-Code
15587
15588 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
15589 \layout LyX-Code
15590
15591 \layout LyX-Code
15592
15593 DATABANK   NAME=gpr0       START=0x80           END=0xFF
15594 \layout LyX-Code
15595
15596 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
15597 \layout LyX-Code
15598
15599 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
15600 \layout LyX-Code
15601
15602 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
15603 \layout LyX-Code
15604
15605 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
15606 \layout LyX-Code
15607
15608 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
15609 \layout LyX-Code
15610
15611 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
15612 \layout LyX-Code
15613
15614 \layout LyX-Code
15615
15616 SECTION    NAME=CONFIG     ROM=config
15617 \layout LyX-Code
15618
15619 \layout LyX-Code
15620
15621 SECTION    NAME=bank0      RAM=gpr0
15622 \layout LyX-Code
15623
15624 SECTION    NAME=bank1      RAM=gpr1
15625 \layout LyX-Code
15626
15627 SECTION    NAME=bank2      RAM=gpr2
15628 \layout LyX-Code
15629
15630 SECTION    NAME=bank3      RAM=gpr3
15631 \layout LyX-Code
15632
15633 SECTION    NAME=bank4      RAM=gpr4
15634 \layout LyX-Code
15635
15636 SECTION    NAME=bank5      RAM=gpr5
15637 \layout Standard
15638
15639 The linker will recognise the section name set in the pragma statement and
15640  will position the variable at the memory bank set with the RAM field at
15641  the SECTION line in the linker script file.
15642 \layout Subsection
15643
15644 Header Files
15645 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
15646
15647 \end_inset 
15648
15649
15650 \layout Standard
15651
15652 There is one main header file that can be included to the source files using
15653  the pic16 port.
15654  That file is the 
15655 \series bold 
15656 pic18fregs.h
15657 \series default 
15658 .
15659  This header file contains the definitions for the processor special registers,
15660  so it is necessary if the source accesses them.
15661  It can be included by adding the following line in the beginning of the
15662  file:
15663 \layout LyX-Code
15664
15665 #include <pic18fregs.h>
15666 \layout Standard
15667
15668 The specific microcontroller is selected within the pic18fregs.h automatically,
15669  so the same source can be used with a variety of devices.
15670 \layout Subsection
15671
15672 Libraries
15673 \layout Standard
15674
15675 The libraries that PIC16
15676 \begin_inset LatexCommand \index{PIC16}
15677
15678 \end_inset 
15679
15680  port depends on are the microcontroller device libraries which contain
15681  the symbol definitions for the microcontroller special function registers.
15682  These libraries have the format pic18fxxxx.lib, where 
15683 \emph on 
15684 xxxx
15685 \emph default 
15686  is the microcontroller identification number.
15687  The specific library is selected automatically by the compiler at link
15688  stage according to the selected device.
15689 \layout Standard
15690
15691 Libraries are created with gplib which is part of the gputils package 
15692 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
15693
15694 \end_inset 
15695
15696 .
15697 \layout Subsection
15698
15699 Memory Models
15700 \layout Standard
15701
15702 The following memory models are supported by the PIC16 port:
15703 \layout Itemize
15704
15705 small model
15706 \layout Itemize
15707
15708 large model
15709 \layout Standard
15710
15711 Memory model affects the default size of pointers within the source.
15712  The sizes are shown in the next table:
15713 \layout Standard
15714 \align center 
15715
15716 \begin_inset  Tabular
15717 <lyxtabular version="3" rows="3" columns="3">
15718 <features>
15719 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15720 <column alignment="center" valignment="top" leftline="true" width="0">
15721 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15722 <row topline="true" bottomline="true">
15723 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15724 \begin_inset Text
15725
15726 \layout Standard
15727
15728 Pointer sizes according to memory model
15729 \end_inset 
15730 </cell>
15731 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15732 \begin_inset Text
15733
15734 \layout Standard
15735
15736 small model
15737 \end_inset 
15738 </cell>
15739 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15740 \begin_inset Text
15741
15742 \layout Standard
15743
15744 large model
15745 \end_inset 
15746 </cell>
15747 </row>
15748 <row topline="true" bottomline="true">
15749 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15750 \begin_inset Text
15751
15752 \layout Standard
15753
15754 code pointers
15755 \end_inset 
15756 </cell>
15757 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15758 \begin_inset Text
15759
15760 \layout Standard
15761
15762 16-bits
15763 \end_inset 
15764 </cell>
15765 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15766 \begin_inset Text
15767
15768 \layout Standard
15769
15770 24-bits
15771 \end_inset 
15772 </cell>
15773 </row>
15774 <row topline="true" bottomline="true">
15775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15776 \begin_inset Text
15777
15778 \layout Standard
15779
15780 data pointers
15781 \end_inset 
15782 </cell>
15783 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
15784 \begin_inset Text
15785
15786 \layout Standard
15787
15788 16-bits
15789 \end_inset 
15790 </cell>
15791 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15792 \begin_inset Text
15793
15794 \layout Standard
15795
15796 16-bits
15797 \end_inset 
15798 </cell>
15799 </row>
15800 </lyxtabular>
15801
15802 \end_inset 
15803
15804
15805 \layout Standard
15806
15807 It is advisable that all sources within a project are compiled with the
15808  same memory model.
15809  If one wants to override the default memory model, this can be done by
15810  declaring a pointer as 
15811 \series bold 
15812 far
15813 \series default 
15814  or 
15815 \series bold 
15816 near
15817 \series default 
15818 .
15819  Far selects large memory model's pointers, while near selects small memory
15820  model's pointers.
15821 \layout Standard
15822
15823 The standard device libraries (see 
15824 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
15825
15826 \end_inset 
15827
15828 ) contain no reference to pointers, so they can be used with both memory
15829  models.
15830 \layout Subsection
15831
15832 Stack
15833 \layout Standard
15834
15835 The stack implementation for the PIC16 port uses two indirect registers,
15836  FSR1 and FSR2.
15837 \layout List
15838 \labelwidthstring 00.00.0000
15839
15840 FSR1 is assigned as stack pointer
15841 \layout List
15842 \labelwidthstring 00.00.0000
15843
15844 FSR2 is assigned as frame pointer
15845 \layout Standard
15846
15847 The following stack models are supported by the PIC16 port
15848 \layout Itemize
15849
15850 small model
15851 \layout Itemize
15852
15853 large model
15854 \layout Standard
15855
15856
15857 \noun on 
15858 Small
15859 \noun default 
15860  model means that only the FSRxL byte is used to access stack and frame,
15861  while 
15862 \emph on 
15863 \noun on 
15864 large
15865 \emph default 
15866 \noun default 
15867  uses both FSRxL and FSRxH registers.
15868  The following table shows the stack/frame pointers sizes according to stack
15869  model and the maximum space they can address:
15870 \layout Standard
15871 \align center 
15872
15873 \begin_inset  Tabular
15874 <lyxtabular version="3" rows="3" columns="3">
15875 <features>
15876 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15877 <column alignment="center" valignment="top" leftline="true" width="0">
15878 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15879 <row topline="true" bottomline="true">
15880 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15881 \begin_inset Text
15882
15883 \layout Standard
15884
15885 Stack & Frame pointer sizes according to stack model
15886 \end_inset 
15887 </cell>
15888 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15889 \begin_inset Text
15890
15891 \layout Standard
15892
15893 small
15894 \end_inset 
15895 </cell>
15896 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15897 \begin_inset Text
15898
15899 \layout Standard
15900
15901 large
15902 \end_inset 
15903 </cell>
15904 </row>
15905 <row topline="true">
15906 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15907 \begin_inset Text
15908
15909 \layout Standard
15910
15911 Stack pointer FSR1
15912 \end_inset 
15913 </cell>
15914 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15915 \begin_inset Text
15916
15917 \layout Standard
15918
15919 8-bits
15920 \end_inset 
15921 </cell>
15922 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15923 \begin_inset Text
15924
15925 \layout Standard
15926
15927 16-bits
15928 \end_inset 
15929 </cell>
15930 </row>
15931 <row topline="true" bottomline="true">
15932 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15933 \begin_inset Text
15934
15935 \layout Standard
15936
15937 Frame pointer FSR2
15938 \end_inset 
15939 </cell>
15940 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15941 \begin_inset Text
15942
15943 \layout Standard
15944
15945 8-bits
15946 \end_inset 
15947 </cell>
15948 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15949 \begin_inset Text
15950
15951 \layout Standard
15952
15953 16-bits
15954 \end_inset 
15955 </cell>
15956 </row>
15957 </lyxtabular>
15958
15959 \end_inset 
15960
15961
15962 \layout Standard
15963
15964
15965 \series bold 
15966 Currently stack and frame pointers should be initialized explicit by the
15967  user at the desired Data RAM position (see 
15968 \begin_inset LatexCommand \ref{sub:PIC16_Pragmas}
15969
15970 \end_inset 
15971
15972  Pragma stack).
15973  Uninitialized stack and frame pointers can result in unexpected behavior
15974  of the resulting binary.
15975 \layout Subsection
15976
15977 Function return values
15978 \layout Standard
15979
15980 Return values from functions are placed to the appropriate registers following
15981  a modified Microchip policy optimized for SDCC.
15982  The following table shows these registers:
15983 \layout Standard
15984 \align center 
15985
15986 \begin_inset  Tabular
15987 <lyxtabular version="3" rows="6" columns="2">
15988 <features>
15989 <column alignment="center" valignment="top" leftline="true" width="0">
15990 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15991 <row topline="true" bottomline="true">
15992 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15993 \begin_inset Text
15994
15995 \layout Standard
15996
15997 size
15998 \end_inset 
15999 </cell>
16000 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16001 \begin_inset Text
16002
16003 \layout Standard
16004
16005 destination register
16006 \end_inset 
16007 </cell>
16008 </row>
16009 <row topline="true">
16010 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16011 \begin_inset Text
16012
16013 \layout Standard
16014
16015 8 bits
16016 \end_inset 
16017 </cell>
16018 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16019 \begin_inset Text
16020
16021 \layout Standard
16022
16023 WREG
16024 \end_inset 
16025 </cell>
16026 </row>
16027 <row topline="true">
16028 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16029 \begin_inset Text
16030
16031 \layout Standard
16032
16033 16 bits
16034 \end_inset 
16035 </cell>
16036 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16037 \begin_inset Text
16038
16039 \layout Standard
16040
16041 PRODL:WREG
16042 \end_inset 
16043 </cell>
16044 </row>
16045 <row topline="true">
16046 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16047 \begin_inset Text
16048
16049 \layout Standard
16050
16051 24 bits
16052 \end_inset 
16053 </cell>
16054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16055 \begin_inset Text
16056
16057 \layout Standard
16058
16059 PRODH:PRODL:WREG
16060 \end_inset 
16061 </cell>
16062 </row>
16063 <row topline="true">
16064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16065 \begin_inset Text
16066
16067 \layout Standard
16068
16069 32 bits
16070 \end_inset 
16071 </cell>
16072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16073 \begin_inset Text
16074
16075 \layout Standard
16076
16077 FSR0L:PRODH:PRODL:WREG
16078 \end_inset 
16079 </cell>
16080 </row>
16081 <row topline="true" bottomline="true">
16082 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16083 \begin_inset Text
16084
16085 \layout Standard
16086
16087 >32 bits
16088 \end_inset 
16089 </cell>
16090 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16091 \begin_inset Text
16092
16093 \layout Standard
16094
16095 on stack, FSR0 points to the beginning
16096 \end_inset 
16097 </cell>
16098 </row>
16099 </lyxtabular>
16100
16101 \end_inset 
16102
16103
16104 \layout Subsection
16105
16106 Interrupts
16107 \layout Standard
16108
16109 When entering an interrupt, currently the PIC16
16110 \begin_inset LatexCommand \index{PIC16}
16111
16112 \end_inset 
16113
16114  port automatically saves the following registers:
16115 \layout Itemize
16116
16117 WREG
16118 \layout Itemize
16119
16120 STATUS
16121 \layout Itemize
16122
16123 BSR
16124 \layout Itemize
16125
16126 PROD (PRODL and PRODH)
16127 \layout Itemize
16128
16129 FSR0 (FSR0L and FSR0H)
16130 \layout Standard
16131
16132 These registers are restored upon return from the interrupt routine.
16133  
16134 \layout Standard
16135
16136 When entering a high priority interrupt WREG, STATUS and BSR are not explicit
16137  saved by software.
16138  The hardware shadow registers for WREG, STATUS and BSR are used in these
16139  cases.
16140 \layout Standard
16141
16142
16143 \begin_inset Foot
16144 collapsed false
16145
16146 \layout Standard
16147
16148 NOTE that when the _naked attribute is specified for an interrupt routine,
16149  then NO registers are stored or restored.
16150 \end_inset 
16151
16152 .
16153 \layout Chapter
16154
16155 Debugging with SDCDB
16156 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
16157
16158 \end_inset 
16159
16160
16161 \begin_inset LatexCommand \index{sdcdb (debugger)}
16162
16163 \end_inset 
16164
16165  
16166 \layout Standard
16167
16168 SDCC is distributed with a source level debugger
16169 \begin_inset LatexCommand \index{Debugger}
16170
16171 \end_inset 
16172
16173 .
16174  The debugger uses a command line interface, the command repertoire of the
16175  debugger has been kept as close to gdb
16176 \begin_inset LatexCommand \index{gdb}
16177
16178 \end_inset 
16179
16180  (the GNU debugger) as possible.
16181  The configuration and build process is part of the standard compiler installati
16182 on, which also builds and installs the debugger in the target directory
16183  specified during configuration.
16184  The debugger allows you debug BOTH at the C source and at the ASM source
16185  level.
16186  Sdcdb is available on Unix platforms only.
16187 \layout Section
16188
16189 Compiling for Debugging
16190 \layout Standard
16191
16192 The -
16193 \begin_inset ERT
16194 status Collapsed
16195
16196 \layout Standard
16197
16198 \backslash 
16199 /
16200 \end_inset 
16201
16202 -debug
16203 \begin_inset LatexCommand \index{-\/-debug}
16204
16205 \end_inset 
16206
16207  option must be specified for all files for which debug information is to
16208  be generated.
16209  The complier generates a .adb file for each of these files.
16210  The linker creates the .cdb
16211 \begin_inset LatexCommand \index{<file>.cdb}
16212
16213 \end_inset 
16214
16215  file from the .adb
16216 \begin_inset LatexCommand \index{<file>.adb}
16217
16218 \end_inset 
16219
16220  files and the address information.
16221  This .cdb is used by the debugger.
16222 \layout Section
16223
16224 How the Debugger Works
16225 \layout Standard
16226
16227 When the -
16228 \begin_inset ERT
16229 status Collapsed
16230
16231 \layout Standard
16232
16233 \backslash 
16234 /
16235 \end_inset 
16236
16237 -debug option is specified the compiler generates extra symbol information
16238  some of which are put into the assembler source and some are put into the
16239  .adb file.
16240   Then the linker creates the .cdb file from the individual .adb files with
16241  the address information for the symbols.
16242  The debugger reads the symbolic information generated by the compiler &
16243  the address information generated by the linker.
16244  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
16245  execution is controlled by the debugger.
16246  When a command is issued for the debugger, it translates it into appropriate
16247  commands for the simulator.
16248 \layout Section
16249
16250 Starting the Debugger
16251 \layout Standard
16252
16253 The debugger can be started using the following command line.
16254  (Assume the file you are debugging has the file name foo).
16255 \newline 
16256
16257 \newline 
16258
16259 \family sans 
16260 \series bold 
16261 sdcdb foo
16262 \newline 
16263
16264 \family default 
16265 \series default 
16266
16267 \newline 
16268 The debugger will look for the following files.
16269 \layout Itemize
16270
16271 foo.c - the source file.
16272 \layout Itemize
16273
16274 foo.cdb - the debugger symbol information file.
16275 \layout Itemize
16276
16277 foo.ihx - the Intel hex format
16278 \begin_inset LatexCommand \index{Intel hex format}
16279
16280 \end_inset 
16281
16282  object file.
16283 \layout Section
16284
16285 Command Line Options.
16286 \layout Itemize
16287
16288 -
16289 \begin_inset ERT
16290 status Collapsed
16291
16292 \layout Standard
16293
16294 \backslash 
16295 /
16296 \end_inset 
16297
16298 -directory=<source file directory> this option can used to specify the directory
16299  search list.
16300  The debugger will look into the directory list specified for source, cdb
16301  & ihx files.
16302  The items in the directory list must be separated by ':', e.g.
16303  if the source files can be in the directories /home/src1 and /home/src2,
16304  the -
16305 \begin_inset ERT
16306 status Collapsed
16307
16308 \layout Standard
16309
16310 \backslash 
16311 /
16312 \end_inset 
16313
16314 -directory option should be -
16315 \begin_inset ERT
16316 status Collapsed
16317
16318 \layout Standard
16319
16320 \backslash 
16321 /
16322 \end_inset 
16323
16324 -directory=/home/src1:/home/src2.
16325  Note there can be no spaces in the option.
16326  
16327 \layout Itemize
16328
16329 -cd <directory> - change to the <directory>.
16330 \layout Itemize
16331
16332 -fullname - used by GUI front ends.
16333 \layout Itemize
16334
16335 -cpu <cpu-type> - this argument is passed to the simulator please see the
16336  simulator docs for details.
16337 \layout Itemize
16338
16339 -X <Clock frequency > this options is passed to the simulator please see
16340  the simulator docs for details.
16341 \layout Itemize
16342
16343 -s <serial port file> passed to simulator see the simulator docs for details.
16344 \layout Itemize
16345
16346 -S <serial in,out> passed to simulator see the simulator docs for details.
16347 \layout Itemize
16348
16349 -k <port number> passed to simulator see the simulator docs for details.
16350 \layout Section
16351
16352 Debugger Commands.
16353 \layout Standard
16354
16355 As mentioned earlier the command interface for the debugger has been deliberatel
16356 y kept as close the GNU debugger gdb, as possible.
16357  This will help the integration with existing graphical user interfaces
16358  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
16359  If you use a graphical user interface for the debugger you can skip the
16360  next sections.
16361 \layout Subsubsection*
16362
16363 break [line | file:line | function | file:function]
16364 \layout Standard
16365
16366 Set breakpoint at specified line or function:
16367 \newline 
16368
16369 \newline 
16370
16371 \family sans 
16372 \series bold 
16373 sdcdb>break 100 
16374 \newline 
16375 sdcdb>break foo.c:100
16376 \newline 
16377 sdcdb>break funcfoo
16378 \newline 
16379 sdcdb>break foo.c:funcfoo
16380 \layout Subsubsection*
16381
16382 clear [line | file:line | function | file:function ]
16383 \layout Standard
16384
16385 Clear breakpoint at specified line or function:
16386 \newline 
16387
16388 \newline 
16389
16390 \family sans 
16391 \series bold 
16392 sdcdb>clear 100
16393 \newline 
16394 sdcdb>clear foo.c:100
16395 \newline 
16396 sdcdb>clear funcfoo
16397 \newline 
16398 sdcdb>clear foo.c:funcfoo
16399 \layout Subsubsection*
16400
16401 continue
16402 \layout Standard
16403
16404 Continue program being debugged, after breakpoint.
16405 \layout Subsubsection*
16406
16407 finish
16408 \layout Standard
16409
16410 Execute till the end of the current function.
16411 \layout Subsubsection*
16412
16413 delete [n]
16414 \layout Standard
16415
16416 Delete breakpoint number 'n'.
16417  If used without any option clear ALL user defined break points.
16418 \layout Subsubsection*
16419
16420 info [break | stack | frame | registers ]
16421 \layout Itemize
16422
16423 info break - list all breakpoints
16424 \layout Itemize
16425
16426 info stack - show the function call stack.
16427 \layout Itemize
16428
16429 info frame - show information about the current execution frame.
16430 \layout Itemize
16431
16432 info registers - show content of all registers.
16433 \layout Subsubsection*
16434
16435 step
16436 \layout Standard
16437
16438 Step program until it reaches a different source line.
16439  Note: pressing <return> repeats the last command.
16440 \layout Subsubsection*
16441
16442 next
16443 \layout Standard
16444
16445 Step program, proceeding through subroutine calls.
16446 \layout Subsubsection*
16447
16448 run
16449 \layout Standard
16450
16451 Start debugged program.
16452 \layout Subsubsection*
16453
16454 ptype variable 
16455 \layout Standard
16456
16457 Print type information of the variable.
16458 \layout Subsubsection*
16459
16460 print variable
16461 \layout Standard
16462
16463 print value of variable.
16464 \layout Subsubsection*
16465
16466 file filename
16467 \layout Standard
16468
16469 load the given file name.
16470  Note this is an alternate method of loading file for debugging.
16471 \layout Subsubsection*
16472
16473 frame
16474 \layout Standard
16475
16476 print information about current frame.
16477 \layout Subsubsection*
16478
16479 set srcmode
16480 \layout Standard
16481
16482 Toggle between C source & assembly source.
16483 \layout Subsubsection*
16484
16485 ! simulator command
16486 \layout Standard
16487
16488 Send the string following '!' to the simulator, the simulator response is
16489  displayed.
16490  Note the debugger does not interpret the command being sent to the simulator,
16491  so if a command like 'go' is sent the debugger can loose its execution
16492  context and may display incorrect values.
16493 \layout Subsubsection*
16494
16495 quit
16496 \layout Standard
16497
16498 "Watch me now.
16499  Iam going Down.
16500  My name is Bobby Brown"
16501 \layout Section
16502
16503 Interfacing with XEmacs
16504 \begin_inset LatexCommand \index{XEmacs}
16505
16506 \end_inset 
16507
16508
16509 \begin_inset LatexCommand \index{Emacs}
16510
16511 \end_inset 
16512
16513 .
16514 \layout Standard
16515
16516 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
16517  sdcdb.el and sdcdbsrc.el.
16518  These two files can be found in the $(prefix)/bin directory after the installat
16519 ion is complete.
16520  These files need to be loaded into XEmacs for the interface to work.
16521  This can be done at XEmacs startup time by inserting the following into
16522  your '.xemacs' file (which can be found in your HOME directory): 
16523 \newline 
16524
16525 \newline 
16526
16527 \family typewriter 
16528 (load-file sdcdbsrc.el) 
16529 \family default 
16530
16531 \newline 
16532
16533 \newline 
16534 .xemacs is a lisp file so the () around the command is REQUIRED.
16535  The files can also be loaded dynamically while XEmacs is running, set the
16536  environment variable 'EMACSLOADPATH' to the installation bin directory
16537  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
16538  To start the interface enter the following command: 
16539 \newline 
16540
16541 \newline 
16542
16543 \family sans 
16544 \series bold 
16545 ESC-x sdcdbsrc
16546 \family default 
16547 \series default 
16548
16549 \newline 
16550
16551 \newline 
16552 You will prompted to enter the file name to be debugged.
16553  
16554 \newline 
16555
16556 \newline 
16557 The command line options that are passed to the simulator directly are bound
16558  to default values in the file sdcdbsrc.el.
16559  The variables are listed below, these values maybe changed as required.
16560 \layout Itemize
16561
16562 sdcdbsrc-cpu-type '51
16563 \layout Itemize
16564
16565 sdcdbsrc-frequency '11059200
16566 \layout Itemize
16567
16568 sdcdbsrc-serial nil
16569 \layout Standard
16570
16571 The following is a list of key mapping for the debugger interface.
16572 \layout Standard
16573
16574 \SpecialChar ~
16575
16576 \family typewriter 
16577
16578 \newline 
16579 ;;\SpecialChar ~
16580 Current Listing :: 
16581 \newline 
16582 ;;key\SpecialChar ~
16583 \SpecialChar ~
16584 \SpecialChar ~
16585 \SpecialChar ~
16586 \SpecialChar ~
16587 \SpecialChar ~
16588 \SpecialChar ~
16589 \SpecialChar ~
16590 \SpecialChar ~
16591 \SpecialChar ~
16592 \SpecialChar ~
16593 \SpecialChar ~
16594 \SpecialChar ~
16595 \SpecialChar ~
16596 binding\SpecialChar ~
16597 \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 \SpecialChar ~
16612 \SpecialChar ~
16613 \SpecialChar ~
16614 \SpecialChar ~
16615 \SpecialChar ~
16616 \SpecialChar ~
16617 \SpecialChar ~
16618 Comment 
16619 \newline 
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 \SpecialChar ~
16634 -------\SpecialChar ~
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 -------
16657 \newline 
16658 ;; 
16659 \newline 
16660 ;;\SpecialChar ~
16661 n\SpecialChar ~
16662 \SpecialChar ~
16663 \SpecialChar ~
16664 \SpecialChar ~
16665 \SpecialChar ~
16666 \SpecialChar ~
16667 \SpecialChar ~
16668 \SpecialChar ~
16669 \SpecialChar ~
16670 \SpecialChar ~
16671 \SpecialChar ~
16672 \SpecialChar ~
16673 \SpecialChar ~
16674 \SpecialChar ~
16675 \SpecialChar ~
16676 sdcdb-next-from-src\SpecialChar ~
16677 \SpecialChar ~
16678 \SpecialChar ~
16679 \SpecialChar ~
16680 \SpecialChar ~
16681 \SpecialChar ~
16682 \SpecialChar ~
16683 \SpecialChar ~
16684 \SpecialChar ~
16685 \SpecialChar ~
16686 SDCDB next command 
16687 \newline 
16688 ;;\SpecialChar ~
16689 b\SpecialChar ~
16690 \SpecialChar ~
16691 \SpecialChar ~
16692 \SpecialChar ~
16693 \SpecialChar ~
16694 \SpecialChar ~
16695 \SpecialChar ~
16696 \SpecialChar ~
16697 \SpecialChar ~
16698 \SpecialChar ~
16699 \SpecialChar ~
16700 \SpecialChar ~
16701 \SpecialChar ~
16702 \SpecialChar ~
16703 \SpecialChar ~
16704 sdcdb-back-from-src\SpecialChar ~
16705 \SpecialChar ~
16706 \SpecialChar ~
16707 \SpecialChar ~
16708 \SpecialChar ~
16709 \SpecialChar ~
16710 \SpecialChar ~
16711 \SpecialChar ~
16712 \SpecialChar ~
16713 \SpecialChar ~
16714 SDCDB back command 
16715 \newline 
16716 ;;\SpecialChar ~
16717 c\SpecialChar ~
16718 \SpecialChar ~
16719 \SpecialChar ~
16720 \SpecialChar ~
16721 \SpecialChar ~
16722 \SpecialChar ~
16723 \SpecialChar ~
16724 \SpecialChar ~
16725 \SpecialChar ~
16726 \SpecialChar ~
16727 \SpecialChar ~
16728 \SpecialChar ~
16729 \SpecialChar ~
16730 \SpecialChar ~
16731 \SpecialChar ~
16732 sdcdb-cont-from-src\SpecialChar ~
16733 \SpecialChar ~
16734 \SpecialChar ~
16735 \SpecialChar ~
16736 \SpecialChar ~
16737 \SpecialChar ~
16738 \SpecialChar ~
16739 \SpecialChar ~
16740 \SpecialChar ~
16741 \SpecialChar ~
16742 SDCDB continue command
16743 \newline 
16744 ;;\SpecialChar ~
16745 s\SpecialChar ~
16746 \SpecialChar ~
16747 \SpecialChar ~
16748 \SpecialChar ~
16749 \SpecialChar ~
16750 \SpecialChar ~
16751 \SpecialChar ~
16752 \SpecialChar ~
16753 \SpecialChar ~
16754 \SpecialChar ~
16755 \SpecialChar ~
16756 \SpecialChar ~
16757 \SpecialChar ~
16758 \SpecialChar ~
16759 \SpecialChar ~
16760 sdcdb-step-from-src\SpecialChar ~
16761 \SpecialChar ~
16762 \SpecialChar ~
16763 \SpecialChar ~
16764 \SpecialChar ~
16765 \SpecialChar ~
16766 \SpecialChar ~
16767 \SpecialChar ~
16768 \SpecialChar ~
16769 \SpecialChar ~
16770 SDCDB step command 
16771 \newline 
16772 ;;\SpecialChar ~
16773 ?\SpecialChar ~
16774 \SpecialChar ~
16775 \SpecialChar ~
16776 \SpecialChar ~
16777 \SpecialChar ~
16778 \SpecialChar ~
16779 \SpecialChar ~
16780 \SpecialChar ~
16781 \SpecialChar ~
16782 \SpecialChar ~
16783 \SpecialChar ~
16784 \SpecialChar ~
16785 \SpecialChar ~
16786 \SpecialChar ~
16787 \SpecialChar ~
16788 sdcdb-whatis-c-sexp\SpecialChar ~
16789 \SpecialChar ~
16790 \SpecialChar ~
16791 \SpecialChar ~
16792 \SpecialChar ~
16793 \SpecialChar ~
16794 \SpecialChar ~
16795 \SpecialChar ~
16796 \SpecialChar ~
16797 \SpecialChar ~
16798 SDCDB ptypecommand for data at 
16799 \newline 
16800 ;;\SpecialChar ~
16801 \SpecialChar ~
16802 \SpecialChar ~
16803 \SpecialChar ~
16804 \SpecialChar ~
16805 \SpecialChar ~
16806 \SpecialChar ~
16807 \SpecialChar ~
16808 \SpecialChar ~
16809 \SpecialChar ~
16810 \SpecialChar ~
16811 \SpecialChar ~
16812 \SpecialChar ~
16813 \SpecialChar ~
16814 \SpecialChar ~
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 buffer point 
16848 \newline 
16849 ;;\SpecialChar ~
16850 x\SpecialChar ~
16851 \SpecialChar ~
16852 \SpecialChar ~
16853 \SpecialChar ~
16854 \SpecialChar ~
16855 \SpecialChar ~
16856 \SpecialChar ~
16857 \SpecialChar ~
16858 \SpecialChar ~
16859 \SpecialChar ~
16860 \SpecialChar ~
16861 \SpecialChar ~
16862 \SpecialChar ~
16863 \SpecialChar ~
16864 \SpecialChar ~
16865 sdcdbsrc-delete\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 SDCDB Delete all breakpoints if no arg 
16880 \newline 
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 \SpecialChar ~
16895 \SpecialChar ~
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 given or delete arg (C-u arg x) 
16929 \newline 
16930 ;;\SpecialChar ~
16931 m\SpecialChar ~
16932 \SpecialChar ~
16933 \SpecialChar ~
16934 \SpecialChar ~
16935 \SpecialChar ~
16936 \SpecialChar ~
16937 \SpecialChar ~
16938 \SpecialChar ~
16939 \SpecialChar ~
16940 \SpecialChar ~
16941 \SpecialChar ~
16942 \SpecialChar ~
16943 \SpecialChar ~
16944 \SpecialChar ~
16945 \SpecialChar ~
16946 sdcdbsrc-frame\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 SDCDB Display current frame if no arg, 
16962 \newline 
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 \SpecialChar ~
16977 \SpecialChar ~
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 given or display frame arg 
17011 \newline 
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 \SpecialChar ~
17026 \SpecialChar ~
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 buffer point 
17060 \newline 
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 \SpecialChar ~
17075 \SpecialChar ~
17076 \SpecialChar ~
17077 sdcdbsrc-goto-sdcdb\SpecialChar ~
17078 \SpecialChar ~
17079 \SpecialChar ~
17080 \SpecialChar ~
17081 \SpecialChar ~
17082 \SpecialChar ~
17083 \SpecialChar ~
17084 \SpecialChar ~
17085 \SpecialChar ~
17086 \SpecialChar ~
17087 Goto the SDCDB output buffer 
17088 \newline 
17089 ;;\SpecialChar ~
17090 p\SpecialChar ~
17091 \SpecialChar ~
17092 \SpecialChar ~
17093 \SpecialChar ~
17094 \SpecialChar ~
17095 \SpecialChar ~
17096 \SpecialChar ~
17097 \SpecialChar ~
17098 \SpecialChar ~
17099 \SpecialChar ~
17100 \SpecialChar ~
17101 \SpecialChar ~
17102 \SpecialChar ~
17103 \SpecialChar ~
17104 \SpecialChar ~
17105 sdcdb-print-c-sexp\SpecialChar ~
17106 \SpecialChar ~
17107 \SpecialChar ~
17108 \SpecialChar ~
17109 \SpecialChar ~
17110 \SpecialChar ~
17111 \SpecialChar ~
17112 \SpecialChar ~
17113 \SpecialChar ~
17114 \SpecialChar ~
17115 \SpecialChar ~
17116 SDCDB print command for data at 
17117 \newline 
17118 ;;\SpecialChar ~
17119 \SpecialChar ~
17120 \SpecialChar ~
17121 \SpecialChar ~
17122 \SpecialChar ~
17123 \SpecialChar ~
17124 \SpecialChar ~
17125 \SpecialChar ~
17126 \SpecialChar ~
17127 \SpecialChar ~
17128 \SpecialChar ~
17129 \SpecialChar ~
17130 \SpecialChar ~
17131 \SpecialChar ~
17132 \SpecialChar ~
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 buffer point 
17166 \newline 
17167 ;;\SpecialChar ~
17168 g\SpecialChar ~
17169 \SpecialChar ~
17170 \SpecialChar ~
17171 \SpecialChar ~
17172 \SpecialChar ~
17173 \SpecialChar ~
17174 \SpecialChar ~
17175 \SpecialChar ~
17176 \SpecialChar ~
17177 \SpecialChar ~
17178 \SpecialChar ~
17179 \SpecialChar ~
17180 \SpecialChar ~
17181 \SpecialChar ~
17182 \SpecialChar ~
17183 sdcdbsrc-goto-sdcdb\SpecialChar ~
17184 \SpecialChar ~
17185 \SpecialChar ~
17186 \SpecialChar ~
17187 \SpecialChar ~
17188 \SpecialChar ~
17189 \SpecialChar ~
17190 \SpecialChar ~
17191 \SpecialChar ~
17192 \SpecialChar ~
17193 Goto the SDCDB output buffer 
17194 \newline 
17195 ;;\SpecialChar ~
17196 t\SpecialChar ~
17197 \SpecialChar ~
17198 \SpecialChar ~
17199 \SpecialChar ~
17200 \SpecialChar ~
17201 \SpecialChar ~
17202 \SpecialChar ~
17203 \SpecialChar ~
17204 \SpecialChar ~
17205 \SpecialChar ~
17206 \SpecialChar ~
17207 \SpecialChar ~
17208 \SpecialChar ~
17209 \SpecialChar ~
17210 \SpecialChar ~
17211 sdcdbsrc-mode\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 \SpecialChar ~
17227 Toggles Sdcdbsrc mode (turns it off) 
17228 \newline 
17229 ;; 
17230 \newline 
17231 ;;\SpecialChar ~
17232 C-c\SpecialChar ~
17233 C-f\SpecialChar ~
17234 \SpecialChar ~
17235 \SpecialChar ~
17236 \SpecialChar ~
17237 \SpecialChar ~
17238 \SpecialChar ~
17239 \SpecialChar ~
17240 \SpecialChar ~
17241 \SpecialChar ~
17242 sdcdb-finish-from-src\SpecialChar ~
17243 \SpecialChar ~
17244 \SpecialChar ~
17245 \SpecialChar ~
17246 \SpecialChar ~
17247 \SpecialChar ~
17248 \SpecialChar ~
17249 \SpecialChar ~
17250 SDCDB finish command 
17251 \newline 
17252 ;; 
17253 \newline 
17254 ;;\SpecialChar ~
17255 C-x\SpecialChar ~
17256 SPC\SpecialChar ~
17257 \SpecialChar ~
17258 \SpecialChar ~
17259 \SpecialChar ~
17260 \SpecialChar ~
17261 \SpecialChar ~
17262 \SpecialChar ~
17263 \SpecialChar ~
17264 \SpecialChar ~
17265 sdcdb-break\SpecialChar ~
17266 \SpecialChar ~
17267 \SpecialChar ~
17268 \SpecialChar ~
17269 \SpecialChar ~
17270 \SpecialChar ~
17271 \SpecialChar ~
17272 \SpecialChar ~
17273 \SpecialChar ~
17274 \SpecialChar ~
17275 \SpecialChar ~
17276 \SpecialChar ~
17277 \SpecialChar ~
17278 \SpecialChar ~
17279 \SpecialChar ~
17280 \SpecialChar ~
17281 \SpecialChar ~
17282 \SpecialChar ~
17283 Set break for line with point 
17284 \newline 
17285 ;;\SpecialChar ~
17286 ESC\SpecialChar ~
17287 t\SpecialChar ~
17288 \SpecialChar ~
17289 \SpecialChar ~
17290 \SpecialChar ~
17291 \SpecialChar ~
17292 \SpecialChar ~
17293 \SpecialChar ~
17294 \SpecialChar ~
17295 \SpecialChar ~
17296 \SpecialChar ~
17297 \SpecialChar ~
17298 sdcdbsrc-mode\SpecialChar ~
17299 \SpecialChar ~
17300 \SpecialChar ~
17301 \SpecialChar ~
17302 \SpecialChar ~
17303 \SpecialChar ~
17304 \SpecialChar ~
17305 \SpecialChar ~
17306 \SpecialChar ~
17307 \SpecialChar ~
17308 \SpecialChar ~
17309 \SpecialChar ~
17310 \SpecialChar ~
17311 \SpecialChar ~
17312 \SpecialChar ~
17313 \SpecialChar ~
17314 Toggle Sdcdbsrc mode 
17315 \newline 
17316 ;;\SpecialChar ~
17317 ESC\SpecialChar ~
17318 m\SpecialChar ~
17319 \SpecialChar ~
17320 \SpecialChar ~
17321 \SpecialChar ~
17322 \SpecialChar ~
17323 \SpecialChar ~
17324 \SpecialChar ~
17325 \SpecialChar ~
17326 \SpecialChar ~
17327 \SpecialChar ~
17328 \SpecialChar ~
17329 sdcdbsrc-srcmode\SpecialChar ~
17330 \SpecialChar ~
17331 \SpecialChar ~
17332 \SpecialChar ~
17333 \SpecialChar ~
17334 \SpecialChar ~
17335 \SpecialChar ~
17336 \SpecialChar ~
17337 \SpecialChar ~
17338 \SpecialChar ~
17339 \SpecialChar ~
17340 \SpecialChar ~
17341 \SpecialChar ~
17342 Toggle list mode 
17343 \newline 
17344 ;; 
17345 \newline 
17346
17347 \layout Chapter
17348 \pagebreak_top 
17349 TIPS
17350 \layout Standard
17351
17352 Here are a few guidelines that will help the compiler generate more efficient
17353  code, some of the tips are specific to this compiler others are generally
17354  good programming practice.
17355 \layout Itemize
17356
17357 Use the smallest data type to represent your data-value.
17358  If it is known in advance that the value is going to be less than 256 then
17359  use an 'unsigned char' instead of a 'short' or 'int'.
17360  Please note, that ANSI C requires both signed and unsigned chars to be
17361  promoted to 'signed int' before doing any operation.
17362  This promotion can be omitted, if the result is the same.
17363  The effect of the promotion rules together with the sign-extension is often
17364  surprising:
17365 \begin_deeper 
17366 \layout Verse
17367
17368
17369 \family typewriter 
17370 unsigned char uc = 0xfe;
17371 \newline 
17372 if (uc * uc < 0) /* this is true! */
17373 \newline 
17374 {
17375 \newline 
17376 \SpecialChar ~
17377 \SpecialChar ~
17378 \SpecialChar ~
17379 \SpecialChar ~
17380 ....
17381 \newline 
17382 }
17383 \layout Standard
17384
17385
17386 \family typewriter 
17387 uc * uc
17388 \family default 
17389  is evaluated as 
17390 \family typewriter 
17391 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
17392 \family default 
17393 .
17394  
17395 \newline 
17396 Another one:
17397 \layout Verse
17398
17399
17400 \family typewriter 
17401 (unsigned char) -12 / (signed char) -3 = ...
17402 \layout Standard
17403
17404 No, the result is not 4:
17405 \layout Verse
17406
17407
17408 \family typewriter 
17409 (int) (unsigned char) -12 / (int) (signed char) -3 =
17410 \newline 
17411 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
17412 \newline 
17413 (int) 0x00f4 / (int) 0xfffd =
17414 \newline 
17415 (int) 0x00f4 / (int) 0xfffd =
17416 \newline 
17417 (int) 244 / (int) -3 =
17418 \newline 
17419 (int) -81 = (int) 0xffaf;
17420 \layout Standard
17421
17422 Don't complain, that gcc gives you a different result.
17423  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
17424  Therefore the results are different.
17425 \newline 
17426 From 
17427 \begin_inset Quotes sld
17428 \end_inset 
17429
17430 comp.lang.c FAQ
17431 \begin_inset Quotes srd
17432 \end_inset 
17433
17434 :
17435 \layout Quote
17436
17437 If well-defined overflow characteristics are important and negative values
17438  are not, or if you want to steer clear of sign-extension problems when
17439  manipulating bits or bytes, use one of the corresponding unsigned types.
17440  (Beware when mixing signed and unsigned values in expressions, though.)
17441 \newline 
17442 Although character types (especially unsigned char) can be used as "tiny"
17443  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
17444 ble sign extension and increased code size.
17445 \end_deeper 
17446 \layout Itemize
17447
17448 Use unsigned when it is known in advance that the value is not going to
17449  be negative.
17450  This helps especially if you are doing division or multiplication, bit-shifting
17451  or are using an array index.
17452 \layout Itemize
17453
17454 NEVER jump into a LOOP.
17455 \layout Itemize
17456
17457 Declare the variables to be local
17458 \begin_inset LatexCommand \index{local variables}
17459
17460 \end_inset 
17461
17462  whenever possible, especially loop control variables (induction).
17463 \layout Itemize
17464
17465 Since the compiler does not always do implicit integral promotion, the programme
17466 r should do an explicit cast when integral promotion is required.
17467 \layout Itemize
17468
17469 Reducing the size of division, multiplication & modulus operations can reduce
17470  code size substantially.
17471  Take the following code for example.
17472 \begin_deeper 
17473 \layout Verse
17474
17475
17476 \family typewriter 
17477 foobar(unsigned int p1, unsigned char ch)
17478 \newline 
17479 {
17480 \newline 
17481 \SpecialChar ~
17482 \SpecialChar ~
17483 \SpecialChar ~
17484 \SpecialChar ~
17485 unsigned char ch1 = p1 % ch ;
17486 \newline 
17487 \SpecialChar ~
17488 \SpecialChar ~
17489 \SpecialChar ~
17490 \SpecialChar ~
17491 ....
17492 \newline 
17493 }
17494 \layout Standard
17495
17496 For the modulus operation the variable ch will be promoted to unsigned int
17497  first then the modulus operation will be performed (this will lead to a
17498  call to support routine _moduint()), and the result will be casted to a
17499  char.
17500  If the code is changed to 
17501 \layout Verse
17502
17503
17504 \family typewriter 
17505 foobar(unsigned int p1, unsigned char ch)
17506 \newline 
17507 {
17508 \newline 
17509 \SpecialChar ~
17510 \SpecialChar ~
17511 \SpecialChar ~
17512 \SpecialChar ~
17513 unsigned char ch1 = (unsigned char)p1 % ch ;
17514 \newline 
17515 \SpecialChar ~
17516 \SpecialChar ~
17517 \SpecialChar ~
17518 \SpecialChar ~
17519 ....
17520 \newline 
17521 }
17522 \layout Standard
17523
17524 It would substantially reduce the code generated (future versions of the
17525  compiler will be smart enough to detect such optimization opportunities).
17526 \end_deeper 
17527 \layout Itemize
17528
17529 Have a look at the assembly listing to get a 
17530 \begin_inset Quotes sld
17531 \end_inset 
17532
17533 feeling
17534 \begin_inset Quotes srd
17535 \end_inset 
17536
17537  for the code generation.
17538 \layout Section
17539
17540 Tools
17541 \begin_inset LatexCommand \index{Tools}
17542
17543 \end_inset 
17544
17545  included in the distribution
17546 \layout Standard
17547 \align center 
17548
17549 \begin_inset  Tabular
17550 <lyxtabular version="3" rows="12" columns="3">
17551 <features>
17552 <column alignment="center" valignment="top" leftline="true" width="0pt">
17553 <column alignment="center" valignment="top" leftline="true" width="0pt">
17554 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17555 <row topline="true" bottomline="true">
17556 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17557 \begin_inset Text
17558
17559 \layout Standard
17560
17561 Name
17562 \end_inset 
17563 </cell>
17564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17565 \begin_inset Text
17566
17567 \layout Standard
17568
17569 Purpose
17570 \end_inset 
17571 </cell>
17572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17573 \begin_inset Text
17574
17575 \layout Standard
17576
17577 Directory
17578 \end_inset 
17579 </cell>
17580 </row>
17581 <row topline="true">
17582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17583 \begin_inset Text
17584
17585 \layout Standard
17586
17587 uCsim
17588 \end_inset 
17589 </cell>
17590 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17591 \begin_inset Text
17592
17593 \layout Standard
17594
17595 Simulator for various architectures
17596 \end_inset 
17597 </cell>
17598 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17599 \begin_inset Text
17600
17601 \layout Standard
17602
17603 sdcc/sim/ucsim
17604 \end_inset 
17605 </cell>
17606 </row>
17607 <row topline="true">
17608 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17609 \begin_inset Text
17610
17611 \layout Standard
17612
17613 keil2sdcc.pl
17614 \end_inset 
17615 </cell>
17616 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17617 \begin_inset Text
17618
17619 \layout Standard
17620
17621 header file conversion
17622 \end_inset 
17623 </cell>
17624 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17625 \begin_inset Text
17626
17627 \layout Standard
17628
17629 sdcc/support/scripts
17630 \end_inset 
17631 </cell>
17632 </row>
17633 <row topline="true">
17634 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17635 \begin_inset Text
17636
17637 \layout Standard
17638
17639 mh2h.c
17640 \end_inset 
17641 </cell>
17642 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17643 \begin_inset Text
17644
17645 \layout Standard
17646
17647 header file conversion
17648 \end_inset 
17649 </cell>
17650 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17651 \begin_inset Text
17652
17653 \layout Standard
17654
17655 sdcc/support/scripts
17656 \end_inset 
17657 </cell>
17658 </row>
17659 <row topline="true">
17660 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17661 \begin_inset Text
17662
17663 \layout Standard
17664
17665 as-gbz80
17666 \end_inset 
17667 </cell>
17668 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17669 \begin_inset Text
17670
17671 \layout Standard
17672
17673 Assembler
17674 \end_inset 
17675 </cell>
17676 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17677 \begin_inset Text
17678
17679 \layout Standard
17680
17681
17682 \family roman 
17683 \series medium 
17684 \shape up 
17685 \size normal 
17686 \emph off 
17687 \bar no 
17688 \noun off 
17689 \color none
17690 sdcc/bin
17691 \end_inset 
17692 </cell>
17693 </row>
17694 <row topline="true">
17695 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17696 \begin_inset Text
17697
17698 \layout Standard
17699
17700 as-z80
17701 \end_inset 
17702 </cell>
17703 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17704 \begin_inset Text
17705
17706 \layout Standard
17707
17708 Assembler
17709 \end_inset 
17710 </cell>
17711 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17712 \begin_inset Text
17713
17714 \layout Standard
17715
17716
17717 \family roman 
17718 \series medium 
17719 \shape up 
17720 \size normal 
17721 \emph off 
17722 \bar no 
17723 \noun off 
17724 \color none
17725 sdcc/bin
17726 \end_inset 
17727 </cell>
17728 </row>
17729 <row topline="true">
17730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17731 \begin_inset Text
17732
17733 \layout Standard
17734
17735 asx8051
17736 \end_inset 
17737 </cell>
17738 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17739 \begin_inset Text
17740
17741 \layout Standard
17742
17743 Assembler
17744 \end_inset 
17745 </cell>
17746 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17747 \begin_inset Text
17748
17749 \layout Standard
17750
17751
17752 \family roman 
17753 \series medium 
17754 \shape up 
17755 \size normal 
17756 \emph off 
17757 \bar no 
17758 \noun off 
17759 \color none
17760 sdcc/bin
17761 \end_inset 
17762 </cell>
17763 </row>
17764 <row topline="true">
17765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17766 \begin_inset Text
17767
17768 \layout Standard
17769
17770 sdcdb
17771 \end_inset 
17772 </cell>
17773 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17774 \begin_inset Text
17775
17776 \layout Standard
17777
17778 Simulator
17779 \end_inset 
17780 </cell>
17781 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17782 \begin_inset Text
17783
17784 \layout Standard
17785
17786
17787 \family roman 
17788 \series medium 
17789 \shape up 
17790 \size normal 
17791 \emph off 
17792 \bar no 
17793 \noun off 
17794 \color none
17795 sdcc/bin
17796 \end_inset 
17797 </cell>
17798 </row>
17799 <row topline="true">
17800 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17801 \begin_inset Text
17802
17803 \layout Standard
17804
17805 aslink
17806 \end_inset 
17807 </cell>
17808 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17809 \begin_inset Text
17810
17811 \layout Standard
17812
17813 Linker
17814 \end_inset 
17815 </cell>
17816 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17817 \begin_inset Text
17818
17819 \layout Standard
17820
17821
17822 \family roman 
17823 \series medium 
17824 \shape up 
17825 \size normal 
17826 \emph off 
17827 \bar no 
17828 \noun off 
17829 \color none
17830 sdcc/bin
17831 \end_inset 
17832 </cell>
17833 </row>
17834 <row topline="true">
17835 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17836 \begin_inset Text
17837
17838 \layout Standard
17839
17840 link-z80
17841 \end_inset 
17842 </cell>
17843 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17844 \begin_inset Text
17845
17846 \layout Standard
17847
17848 Linker
17849 \end_inset 
17850 </cell>
17851 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17852 \begin_inset Text
17853
17854 \layout Standard
17855
17856
17857 \family roman 
17858 \series medium 
17859 \shape up 
17860 \size normal 
17861 \emph off 
17862 \bar no 
17863 \noun off 
17864 \color none
17865 sdcc/bin
17866 \end_inset 
17867 </cell>
17868 </row>
17869 <row topline="true">
17870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17871 \begin_inset Text
17872
17873 \layout Standard
17874
17875 link-gbz80
17876 \end_inset 
17877 </cell>
17878 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17879 \begin_inset Text
17880
17881 \layout Standard
17882
17883 Linker
17884 \end_inset 
17885 </cell>
17886 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17887 \begin_inset Text
17888
17889 \layout Standard
17890
17891
17892 \family roman 
17893 \series medium 
17894 \shape up 
17895 \size normal 
17896 \emph off 
17897 \bar no 
17898 \noun off 
17899 \color none
17900 sdcc/bin
17901 \end_inset 
17902 </cell>
17903 </row>
17904 <row topline="true" bottomline="true">
17905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17906 \begin_inset Text
17907
17908 \layout Standard
17909
17910 packihx
17911 \end_inset 
17912 </cell>
17913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17914 \begin_inset Text
17915
17916 \layout Standard
17917
17918 ihx packer
17919 \end_inset 
17920 </cell>
17921 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17922 \begin_inset Text
17923
17924 \layout Standard
17925
17926
17927 \family roman 
17928 \series medium 
17929 \shape up 
17930 \size normal 
17931 \emph off 
17932 \bar no 
17933 \noun off 
17934 \color none
17935 sdcc/bin
17936 \end_inset 
17937 </cell>
17938 </row>
17939 </lyxtabular>
17940
17941 \end_inset 
17942
17943
17944 \newline 
17945
17946 \layout Section
17947
17948 Documentation
17949 \begin_inset LatexCommand \index{Documentation}
17950
17951 \end_inset 
17952
17953  included in the distribution
17954 \layout Standard
17955 \align center 
17956
17957 \begin_inset  Tabular
17958 <lyxtabular version="3" rows="10" columns="2">
17959 <features>
17960 <column alignment="left" valignment="top" leftline="true" width="0">
17961 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
17962 <row topline="true" bottomline="true">
17963 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17964 \begin_inset Text
17965
17966 \layout Standard
17967
17968 Subject / Title
17969 \end_inset 
17970 </cell>
17971 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17972 \begin_inset Text
17973
17974 \layout Standard
17975
17976 Where to get / filename
17977 \end_inset 
17978 </cell>
17979 </row>
17980 <row topline="true">
17981 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17982 \begin_inset Text
17983
17984 \layout Standard
17985
17986 SDCC Compiler User Guide
17987 \end_inset 
17988 </cell>
17989 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17990 \begin_inset Text
17991
17992 \layout Standard
17993
17994 You're reading it right now
17995 \end_inset 
17996 </cell>
17997 </row>
17998 <row topline="true">
17999 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18000 \begin_inset Text
18001
18002 \layout Standard
18003
18004 Changelog of SDCC
18005 \end_inset 
18006 </cell>
18007 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18008 \begin_inset Text
18009
18010 \layout Standard
18011
18012 sdcc/Changelog
18013 \end_inset 
18014 </cell>
18015 </row>
18016 <row topline="true">
18017 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18018 \begin_inset Text
18019
18020 \layout Standard
18021
18022 ASXXXX Assemblers and ASLINK Relocating Linker
18023 \end_inset 
18024 </cell>
18025 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18026 \begin_inset Text
18027
18028 \layout Standard
18029
18030 sdcc/as/doc/asxhtm.html
18031 \end_inset 
18032 </cell>
18033 </row>
18034 <row topline="true">
18035 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18036 \begin_inset Text
18037
18038 \layout Standard
18039
18040 SDCC regression test
18041 \begin_inset LatexCommand \index{Regression test}
18042
18043 \end_inset 
18044
18045
18046 \end_inset 
18047 </cell>
18048 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18049 \begin_inset Text
18050
18051 \layout Standard
18052
18053 sdcc/doc/test_suite_spec.pdf
18054 \end_inset 
18055 </cell>
18056 </row>
18057 <row topline="true">
18058 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18059 \begin_inset Text
18060
18061 \layout Standard
18062
18063 Various notes
18064 \end_inset 
18065 </cell>
18066 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18067 \begin_inset Text
18068
18069 \layout Standard
18070
18071 sdcc/doc/*
18072 \end_inset 
18073 </cell>
18074 </row>
18075 <row topline="true">
18076 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18077 \begin_inset Text
18078
18079 \layout Standard
18080
18081 Notes on debugging with sdcdb
18082 \begin_inset LatexCommand \index{sdcdb (debugger)}
18083
18084 \end_inset 
18085
18086
18087 \end_inset 
18088 </cell>
18089 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18090 \begin_inset Text
18091
18092 \layout Standard
18093
18094 sdcc/debugger/README
18095 \end_inset 
18096 </cell>
18097 </row>
18098 <row topline="true">
18099 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18100 \begin_inset Text
18101
18102 \layout Standard
18103
18104 Software simulator for microcontrollers
18105 \end_inset 
18106 </cell>
18107 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18108 \begin_inset Text
18109
18110 \layout Standard
18111
18112
18113 \family roman 
18114 \series medium 
18115 \shape up 
18116 \size normal 
18117 \emph off 
18118 \bar no 
18119 \noun off 
18120 \color none
18121 sdcc/sim/ucsim/doc
18122 \family default 
18123 \series default 
18124 \shape default 
18125 \size default 
18126 \emph default 
18127 \bar default 
18128 \noun default 
18129 \color default
18130 /index.html
18131 \end_inset 
18132 </cell>
18133 </row>
18134 <row topline="true">
18135 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18136 \begin_inset Text
18137
18138 \layout Standard
18139
18140 Temporary notes on the pic16
18141 \begin_inset LatexCommand \index{PIC16}
18142
18143 \end_inset 
18144
18145  port
18146 \end_inset 
18147 </cell>
18148 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18149 \begin_inset Text
18150
18151 \layout Standard
18152
18153 sdcc/src/pic16/NOTES
18154 \end_inset 
18155 </cell>
18156 </row>
18157 <row topline="true" bottomline="true">
18158 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18159 \begin_inset Text
18160
18161 \layout Standard
18162
18163 SDCC internal documentation (debugging file format)
18164 \end_inset 
18165 </cell>
18166 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18167 \begin_inset Text
18168
18169 \layout Standard
18170
18171 sdcc/doc/
18172 \family roman 
18173 \series medium 
18174 \shape up 
18175 \size normal 
18176 \emph off 
18177 \bar no 
18178 \noun off 
18179 \color none
18180 cdbfileformat.pd
18181 \family default 
18182 \series default 
18183 \shape default 
18184 \size default 
18185 \emph default 
18186 \bar default 
18187 \noun default 
18188 \color default
18189 f
18190 \end_inset 
18191 </cell>
18192 </row>
18193 </lyxtabular>
18194
18195 \end_inset 
18196
18197
18198 \newline 
18199
18200 \layout Section
18201
18202 Related open source tools
18203 \begin_inset LatexCommand \index{Related tools}
18204
18205 \end_inset 
18206
18207
18208 \layout Standard
18209 \align center 
18210
18211 \begin_inset  Tabular
18212 <lyxtabular version="3" rows="11" columns="3">
18213 <features>
18214 <column alignment="center" valignment="top" leftline="true" width="0pt">
18215 <column alignment="block" valignment="top" leftline="true" width="30line%">
18216 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18217 <row topline="true" bottomline="true">
18218 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18219 \begin_inset Text
18220
18221 \layout Standard
18222
18223 Name
18224 \end_inset 
18225 </cell>
18226 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18227 \begin_inset Text
18228
18229 \layout Standard
18230
18231 Purpose
18232 \end_inset 
18233 </cell>
18234 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18235 \begin_inset Text
18236
18237 \layout Standard
18238
18239 Where to get
18240 \end_inset 
18241 </cell>
18242 </row>
18243 <row topline="true">
18244 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18245 \begin_inset Text
18246
18247 \layout Standard
18248
18249 gpsim
18250 \begin_inset LatexCommand \index{gpsim (pic simulator)}
18251
18252 \end_inset 
18253
18254
18255 \end_inset 
18256 </cell>
18257 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18258 \begin_inset Text
18259
18260 \layout Standard
18261
18262 PIC simulator
18263 \end_inset 
18264 </cell>
18265 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18266 \begin_inset Text
18267
18268 \layout Standard
18269
18270
18271 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
18272
18273 \end_inset 
18274
18275
18276 \end_inset 
18277 </cell>
18278 </row>
18279 <row topline="true">
18280 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18281 \begin_inset Text
18282
18283 \layout Standard
18284
18285 gputils
18286 \begin_inset LatexCommand \index{gputils (pic tools)}
18287
18288 \end_inset 
18289
18290
18291 \end_inset 
18292 </cell>
18293 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18294 \begin_inset Text
18295
18296 \layout Standard
18297
18298 GNU PIC utilities
18299 \end_inset 
18300 </cell>
18301 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18302 \begin_inset Text
18303
18304 \layout Standard
18305
18306
18307 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
18308
18309 \end_inset 
18310
18311
18312 \end_inset 
18313 </cell>
18314 </row>
18315 <row topline="true">
18316 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18317 \begin_inset Text
18318
18319 \layout Standard
18320
18321 flP5
18322 \end_inset 
18323 </cell>
18324 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18325 \begin_inset Text
18326
18327 \layout Standard
18328
18329 PIC programmer
18330 \end_inset 
18331 </cell>
18332 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18333 \begin_inset Text
18334
18335 \layout Standard
18336
18337
18338 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
18339
18340 \end_inset 
18341
18342
18343 \end_inset 
18344 </cell>
18345 </row>
18346 <row topline="true">
18347 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18348 \begin_inset Text
18349
18350 \layout Standard
18351
18352 indent
18353 \begin_inset LatexCommand \index{indent (source formatting tool)}
18354
18355 \end_inset 
18356
18357
18358 \end_inset 
18359 </cell>
18360 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18361 \begin_inset Text
18362
18363 \layout Standard
18364
18365 Formats C source - Master of the white spaces
18366 \end_inset 
18367 </cell>
18368 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18369 \begin_inset Text
18370
18371 \layout Standard
18372
18373
18374 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
18375
18376 \end_inset 
18377
18378
18379 \end_inset 
18380 </cell>
18381 </row>
18382 <row topline="true">
18383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18384 \begin_inset Text
18385
18386 \layout Standard
18387
18388 srecord
18389 \begin_inset LatexCommand \index{srecord (tool)}
18390
18391 \end_inset 
18392
18393
18394 \end_inset 
18395 </cell>
18396 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18397 \begin_inset Text
18398
18399 \layout Standard
18400
18401 Object file conversion, checksumming, ...
18402 \end_inset 
18403 </cell>
18404 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18405 \begin_inset Text
18406
18407 \layout Standard
18408
18409
18410 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
18411
18412 \end_inset 
18413
18414
18415 \end_inset 
18416 </cell>
18417 </row>
18418 <row topline="true">
18419 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18420 \begin_inset Text
18421
18422 \layout Standard
18423
18424 objdump
18425 \begin_inset LatexCommand \index{objdump (tool)}
18426
18427 \end_inset 
18428
18429
18430 \end_inset 
18431 </cell>
18432 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18433 \begin_inset Text
18434
18435 \layout Standard
18436
18437 Object file conversion, ...
18438 \end_inset 
18439 </cell>
18440 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18441 \begin_inset Text
18442
18443 \layout Standard
18444
18445 Part of binutils (should be there anyway)
18446 \end_inset 
18447 </cell>
18448 </row>
18449 <row topline="true">
18450 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18451 \begin_inset Text
18452
18453 \layout Standard
18454
18455 doxygen
18456 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
18457
18458 \end_inset 
18459
18460
18461 \end_inset 
18462 </cell>
18463 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18464 \begin_inset Text
18465
18466 \layout Standard
18467
18468 Source code documentation system
18469 \end_inset 
18470 </cell>
18471 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18472 \begin_inset Text
18473
18474 \layout Standard
18475
18476
18477 \begin_inset LatexCommand \url{http://www.doxygen.org}
18478
18479 \end_inset 
18480
18481
18482 \end_inset 
18483 </cell>
18484 </row>
18485 <row topline="true">
18486 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18487 \begin_inset Text
18488
18489 \layout Standard
18490
18491 kdevelop
18492 \end_inset 
18493 </cell>
18494 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18495 \begin_inset Text
18496
18497 \layout Standard
18498
18499 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
18500 \end_inset 
18501 </cell>
18502 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18503 \begin_inset Text
18504
18505 \layout Standard
18506
18507
18508 \begin_inset LatexCommand \url{http://www.kdevelop.org}
18509
18510 \end_inset 
18511
18512
18513 \end_inset 
18514 </cell>
18515 </row>
18516 <row topline="true">
18517 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18518 \begin_inset Text
18519
18520 \layout Standard
18521
18522 splint
18523 \begin_inset LatexCommand \index{splint (syntax checking tool)}
18524
18525 \end_inset 
18526
18527
18528 \end_inset 
18529 </cell>
18530 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18531 \begin_inset Text
18532
18533 \layout Standard
18534
18535 Statically checks c sources (has anyone adapted splint for SDCC?)
18536 \end_inset 
18537 </cell>
18538 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18539 \begin_inset Text
18540
18541 \layout Standard
18542
18543
18544 \begin_inset LatexCommand \url{http://www.splint.org}
18545
18546 \end_inset 
18547
18548
18549 \end_inset 
18550 </cell>
18551 </row>
18552 <row topline="true" bottomline="true">
18553 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18554 \begin_inset Text
18555
18556 \layout Standard
18557
18558 ddd
18559 \begin_inset LatexCommand \index{ddd (debugger)}
18560
18561 \end_inset 
18562
18563
18564 \end_inset 
18565 </cell>
18566 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18567 \begin_inset Text
18568
18569 \layout Standard
18570
18571 Debugger, serves nicely as GUI to sdcdb
18572 \begin_inset LatexCommand \index{sdcdb (debugger)}
18573
18574 \end_inset 
18575
18576  (Unix only)
18577 \end_inset 
18578 </cell>
18579 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18580 \begin_inset Text
18581
18582 \layout Standard
18583
18584
18585 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
18586
18587 \end_inset 
18588
18589
18590 \end_inset 
18591 </cell>
18592 </row>
18593 </lyxtabular>
18594
18595 \end_inset 
18596
18597
18598 \newline 
18599
18600 \layout Section
18601
18602 Related documentation / recommended reading
18603 \layout Standard
18604 \align center 
18605
18606 \begin_inset  Tabular
18607 <lyxtabular version="3" rows="6" columns="3">
18608 <features>
18609 <column alignment="center" valignment="top" leftline="true" width="0pt">
18610 <column alignment="block" valignment="top" leftline="true" width="30line%">
18611 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18612 <row topline="true" bottomline="true">
18613 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18614 \begin_inset Text
18615
18616 \layout Standard
18617
18618 Name
18619 \end_inset 
18620 </cell>
18621 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18622 \begin_inset Text
18623
18624 \layout Standard
18625
18626 Subject / Title
18627 \end_inset 
18628 </cell>
18629 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18630 \begin_inset Text
18631
18632 \layout Standard
18633
18634 Where to get
18635 \end_inset 
18636 </cell>
18637 </row>
18638 <row topline="true">
18639 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18640 \begin_inset Text
18641
18642 \layout Standard
18643
18644
18645 \family roman 
18646 \series medium 
18647 \shape up 
18648 \size normal 
18649 \emph off 
18650 \bar no 
18651 \noun off 
18652 \color none
18653 c-refcard.pdf
18654 \end_inset 
18655 </cell>
18656 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18657 \begin_inset Text
18658
18659 \layout Standard
18660
18661 C Reference Card
18662 \begin_inset LatexCommand \index{C Reference card}
18663
18664 \end_inset 
18665
18666 , 2 pages
18667 \end_inset 
18668 </cell>
18669 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18670 \begin_inset Text
18671
18672 \layout Standard
18673
18674
18675 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
18676
18677 \end_inset 
18678
18679
18680 \end_inset 
18681 </cell>
18682 </row>
18683 <row topline="true">
18684 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18685 \begin_inset Text
18686
18687 \layout Standard
18688
18689 c-faq
18690 \end_inset 
18691 </cell>
18692 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18693 \begin_inset Text
18694
18695 \layout Standard
18696
18697 C-FAQ-list
18698 \end_inset 
18699 </cell>
18700 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18701 \begin_inset Text
18702
18703 \layout Standard
18704
18705
18706 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
18707
18708 \end_inset 
18709
18710
18711 \end_inset 
18712 </cell>
18713 </row>
18714 <row topline="true">
18715 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18716 \begin_inset Text
18717
18718 \layout Standard
18719
18720 \end_inset 
18721 </cell>
18722 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18723 \begin_inset Text
18724
18725 \layout Standard
18726
18727 Latest datasheet of the target CPU
18728 \end_inset 
18729 </cell>
18730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18731 \begin_inset Text
18732
18733 \layout Standard
18734
18735 vendor
18736 \end_inset 
18737 </cell>
18738 </row>
18739 <row topline="true">
18740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18741 \begin_inset Text
18742
18743 \layout Standard
18744
18745 \end_inset 
18746 </cell>
18747 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18748 \begin_inset Text
18749
18750 \layout Standard
18751
18752 Revision history of datasheet
18753 \end_inset 
18754 </cell>
18755 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18756 \begin_inset Text
18757
18758 \layout Standard
18759
18760 vendor
18761 \end_inset 
18762 </cell>
18763 </row>
18764 <row topline="true" bottomline="true">
18765 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18766 \begin_inset Text
18767
18768 \layout Standard
18769
18770 S.
18771  S.
18772  Muchnick
18773 \end_inset 
18774 </cell>
18775 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18776 \begin_inset Text
18777
18778 \layout Standard
18779
18780 Advanced Compiler Design and Implementation
18781 \end_inset 
18782 </cell>
18783 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18784 \begin_inset Text
18785
18786 \layout Standard
18787
18788 bookstore (very dedicated, probably read other books first)
18789 \end_inset 
18790 </cell>
18791 </row>
18792 </lyxtabular>
18793
18794 \end_inset 
18795
18796
18797 \newline 
18798
18799 \layout Section
18800
18801 Some Questions
18802 \layout Standard
18803
18804 Some questions answered, some pointers given - it might be time to in turn
18805  ask 
18806 \emph on 
18807 you
18808 \emph default 
18809  some questions: 
18810 \layout Itemize
18811
18812 can you solve your project with the selected microcontroller? Would you
18813  find out early or rather late that your target is too small/slow/whatever?
18814  Can you switch to a slightly better device if it doesn't fit?
18815 \layout Itemize
18816
18817 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
18818  and/or another programming language be more adequate? Would an operating
18819  system on the target device help?
18820 \layout Itemize
18821
18822 if you solved the problem, will the marketing department be happy?
18823 \layout Itemize
18824
18825 if the marketing department is happy, will customers be happy?
18826 \layout Itemize
18827
18828 if you're the project manager, marketing department and maybe even the customer
18829  in one person, have you tried to see the project from the outside?
18830 \layout Itemize
18831
18832 is the project done if you think it is done? Or is just that other interface/pro
18833 tocol/feature/configuration/option missing? How about website, manual(s),
18834  internationali(z|s)ation, packaging, labels, 2nd source for components,
18835  electromagnetic compatability/interference, documentation for production,
18836  production test software, update mechanism, patent issues?
18837 \layout Itemize
18838
18839 is your project adequately positioned in that magic triangle: fame, fortune,
18840  fun?
18841 \layout Standard
18842
18843 Maybe not all answers to these questions are known and some answers may
18844  even be 
18845 \emph on 
18846 no
18847 \emph default 
18848 , nevertheless knowing these questions may help you to avoid burnout
18849 \begin_inset Foot
18850 collapsed false
18851
18852 \layout Standard
18853
18854 burnout is bad for electronic devices, programmers and motorcycle tyres
18855 \end_inset 
18856
18857 .
18858  Chances are you didn't want to hear some of them...
18859 \layout Chapter
18860
18861 Support
18862 \begin_inset LatexCommand \index{Support}
18863
18864 \end_inset 
18865
18866
18867 \layout Standard
18868
18869 SDCC has grown to be a large project.
18870  The compiler alone (without the preprocessor, assembler and linker) is
18871  well over 100,000 lines of code (blank stripped).
18872  The open source nature of this project is a key to its continued growth
18873  and support.
18874  You gain the benefit and support of many active software developers and
18875  end users.
18876  Is SDCC perfect? No, that's why we need your help.
18877  The developers take pride in fixing reported bugs.
18878  You can help by reporting the bugs and helping other SDCC users.
18879  There are lots of ways to contribute, and we encourage you to take part
18880  in making SDCC a great software package.
18881  
18882 \layout Standard
18883
18884 The SDCC project is hosted on the SDCC sourceforge site at 
18885 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
18886
18887 \end_inset 
18888
18889 .
18890  You'll find the complete set of mailing lists
18891 \begin_inset LatexCommand \index{Mailing list(s)}
18892
18893 \end_inset 
18894
18895 , forums, bug reporting system, patch submission
18896 \begin_inset LatexCommand \index{Patch submission}
18897
18898 \end_inset 
18899
18900  system, download
18901 \begin_inset LatexCommand \index{download}
18902
18903 \end_inset 
18904
18905  area and cvs code repository
18906 \begin_inset LatexCommand \index{cvs code repository}
18907
18908 \end_inset 
18909
18910  there.
18911 \layout Section
18912
18913 Reporting Bugs
18914 \begin_inset LatexCommand \index{Bug reporting}
18915
18916 \end_inset 
18917
18918
18919 \begin_inset LatexCommand \index{Reporting bugs}
18920
18921 \end_inset 
18922
18923
18924 \layout Standard
18925
18926 The recommended way of reporting bugs is using the infrastructure of the
18927  sourceforge site.
18928  You can follow the status of bug reports there and have an overview about
18929  the known bugs.
18930 \layout Standard
18931
18932 Bug reports are automatically forwarded to the developer mailing list and
18933  will be fixed ASAP.
18934  When reporting a bug, it is very useful to include a small test program
18935  (the smaller the better) which reproduces the problem.
18936  If you can isolate the problem by looking at the generated assembly code,
18937  this can be very helpful.
18938  Compiling your program with the -
18939 \begin_inset ERT
18940 status Collapsed
18941
18942 \layout Standard
18943
18944 \backslash 
18945 /
18946 \end_inset 
18947
18948 -dumpall
18949 \begin_inset LatexCommand \index{-\/-dumpall}
18950
18951 \end_inset 
18952
18953  option can sometimes be useful in locating optimization problems.
18954  When reporting a bug please maker sure you:
18955 \layout Enumerate
18956
18957 Attach the code you are compiling with SDCC.
18958  
18959 \layout Enumerate
18960
18961 Specify the exact command you use to run SDCC, or attach your Makefile.
18962  
18963 \layout Enumerate
18964
18965 Specify the SDCC version (type "
18966 \family sans 
18967 \series bold 
18968 sdcc -v
18969 \family default 
18970 \series default 
18971 "), your platform, and operating system.
18972  
18973 \layout Enumerate
18974
18975 Provide an exact copy of any error message or incorrect output.
18976  
18977 \layout Enumerate
18978
18979 Put something meaningful in the subject of your message.
18980 \layout Standard
18981
18982 Please attempt to include these 5 important parts, as applicable, in all
18983  requests for support or when reporting any problems or bugs with SDCC.
18984  Though this will make your message lengthy, it will greatly improve your
18985  chance that SDCC users and developers will be able to help you.
18986  Some SDCC developers are frustrated by bug reports without code provided
18987  that they can use to reproduce and ultimately fix the problem, so please
18988  be sure to provide sample code if you are reporting a bug! 
18989 \layout Standard
18990
18991 Please have a short check that you are using a recent version of SDCC and
18992  the bug is not yet known.
18993  This is the link for reporting bugs: 
18994 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
18995
18996 \end_inset 
18997
18998 .
18999 \layout Section
19000
19001 Requesting Features
19002 \begin_inset LatexCommand \label{sub:Requesting-Features}
19003
19004 \end_inset 
19005
19006
19007 \begin_inset LatexCommand \index{Feature request}
19008
19009 \end_inset 
19010
19011
19012 \begin_inset LatexCommand \index{Requesting features}
19013
19014 \end_inset 
19015
19016
19017 \layout Standard
19018
19019 Like bug reports feature requests are forwarded to the developer mailing
19020  list.
19021  This is the link for requesting features: 
19022 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
19023
19024 \end_inset 
19025
19026 .
19027 \layout Section
19028
19029 Submitting patches
19030 \layout Standard
19031
19032 Like bug reports contributed patches are forwarded to the developer mailing
19033  list.
19034  This is the link for submitting patches
19035 \begin_inset LatexCommand \index{Patch submission}
19036
19037 \end_inset 
19038
19039
19040 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
19041
19042 \end_inset 
19043
19044 .
19045 \layout Standard
19046
19047 You need to specify some parameters to the 
19048 \family typewriter 
19049 diff
19050 \family default 
19051  command for the patches to be useful.
19052  If you modified more than one file a patch created f.e.
19053  with 
19054 \family sans 
19055 \series bold 
19056
19057 \begin_inset Quotes sld
19058 \end_inset 
19059
19060 diff -Naur unmodified_directory modified_directory >my_changes.patch
19061 \begin_inset Quotes srd
19062 \end_inset 
19063
19064
19065 \family default 
19066 \series default 
19067  will be fine, otherwise 
19068 \family sans 
19069 \series bold 
19070
19071 \begin_inset Quotes sld
19072 \end_inset 
19073
19074 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
19075 \begin_inset Quotes srd
19076 \end_inset 
19077
19078
19079 \series default 
19080  
19081 \family default 
19082 will do.
19083 \layout Section
19084
19085 Getting Help
19086 \layout Standard
19087
19088 These links should take you directly to the 
19089 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
19090
19091 \end_inset 
19092
19093
19094 \begin_inset Foot
19095 collapsed false
19096
19097 \layout Standard
19098
19099 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
19100  automated messages (mid 2003)
19101 \end_inset 
19102
19103  and the 
19104 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
19105
19106 \end_inset 
19107
19108 , lists
19109 \begin_inset LatexCommand \index{Mailing list(s)}
19110
19111 \end_inset 
19112
19113  and forums are archived and searchable so if you are lucky someone already
19114  had a similar problem.
19115  While mails to the lists themselves are delivered promptly their web front
19116  end on sourceforge sometimes shows a severe time lag (up to several weeks),
19117  if you're seriously using SDCC please consider subscribing to the lists.
19118 \layout Section
19119
19120 ChangeLog
19121 \layout Standard
19122
19123 You can follow the status of the cvs version
19124 \begin_inset LatexCommand \index{version}
19125
19126 \end_inset 
19127
19128  of SDCC by watching the Changelog
19129 \begin_inset LatexCommand \index{Changelog}
19130
19131 \end_inset 
19132
19133  in the cvs-repository
19134 \newline 
19135
19136 \size footnotesize 
19137
19138 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
19139
19140 \end_inset 
19141
19142 .
19143 \layout Section
19144
19145 Release policy
19146 \begin_inset LatexCommand \index{Release policy}
19147
19148 \end_inset 
19149
19150
19151 \layout Standard
19152
19153 Historically there often were long delays between official releases and
19154  the sourceforge download area tends to get not updated at all.
19155  Excuses in the past might have referred to problems with live range analysis,
19156  but as this was fixed a while ago, the current problem is that another
19157  excuse has to be found.
19158  Kidding aside, we have to get better there! On the other hand there are
19159  daily snapshots available at 
19160 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
19161
19162 \end_inset 
19163
19164 , and you can always build the very last version (hopefully with many bugs
19165  fixed, and features added) from the source code available at 
19166 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
19167
19168 \end_inset 
19169
19170 .
19171 \layout Section
19172
19173 Examples
19174 \begin_inset LatexCommand \index{Examples}
19175
19176 \end_inset 
19177
19178
19179 \layout Standard
19180
19181 You'll find some small examples in the directory 
19182 \emph on 
19183 sdcc/device/examples/.
19184  
19185 \emph default 
19186 More examples and libraries are available at
19187 \emph on 
19188  The SDCC Open Knowledge Resource 
19189 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
19190
19191 \end_inset 
19192
19193  
19194 \emph default 
19195 web site or at 
19196 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
19197
19198 \end_inset 
19199
19200 .
19201 \layout Comment
19202
19203 I did insert a reference to Paul's web site here although it seems rather
19204  dedicated to a specific 8032 board (I think it's okay because it f.e.
19205  shows LCD/Harddisc interface and has a free 8051 monitor.
19206  Independent 8032 board vendors face hard competition of heavily subsidized
19207  development boards anyway).
19208 \layout Comment
19209
19210 Maybe we should include some links to real world applications.
19211  Preferably pointer to pointers (one for each architecture) so this stays
19212  manageable here?
19213 \layout Section
19214
19215 Quality control
19216 \begin_inset LatexCommand \index{Quality control}
19217
19218 \end_inset 
19219
19220
19221 \layout Standard
19222
19223 The compiler is passed through nightly compile and build checks.
19224  The so called 
19225 \shape italic 
19226 regression tests
19227 \shape default 
19228
19229 \begin_inset LatexCommand \index{Regression test}
19230
19231 \end_inset 
19232
19233  check that SDCC itself compiles flawlessly on several platforms and checks
19234  the quality of the code generated by SDCC by running the code through simulator
19235 s.
19236  There is a separate document 
19237 \shape italic 
19238 test_suite.pdf
19239 \begin_inset LatexCommand \index{Test suite}
19240
19241 \end_inset 
19242
19243
19244 \shape default 
19245  about this.
19246 \layout Standard
19247
19248 You'll find the test code in the directory 
19249 \shape italic 
19250 sdcc/support/regression
19251 \shape default 
19252 .
19253  You can run these tests manually by running 
19254 \family sans 
19255 make
19256 \family default 
19257  in this directory (or f.e.
19258  
19259 \family sans 
19260 \series bold 
19261
19262 \begin_inset Quotes sld
19263 \end_inset 
19264
19265 make test-mcs51
19266 \begin_inset Quotes srd
19267 \end_inset 
19268
19269
19270 \family default 
19271 \series default 
19272  if you don't want to run the complete tests).
19273  The test code might also be interesting if you want to look for examples
19274 \begin_inset LatexCommand \index{Examples}
19275
19276 \end_inset 
19277
19278  checking corner cases of SDCC or if you plan to submit patches
19279 \begin_inset LatexCommand \index{Patch submission}
19280
19281 \end_inset 
19282
19283 .
19284 \layout Standard
19285
19286 The pic port uses a different set of regression tests, you'll find them
19287  in the directory 
19288 \shape italic 
19289 sdcc/src/regression
19290 \shape default 
19291 .
19292 \layout Chapter
19293 \pagebreak_top 
19294 SDCC Technical Data
19295 \layout Section
19296
19297 Optimizations
19298 \begin_inset LatexCommand \index{Optimizations}
19299
19300 \end_inset 
19301
19302
19303 \layout Standard
19304
19305 SDCC performs a host of standard optimizations in addition to some MCU specific
19306  optimizations.
19307  
19308 \layout Subsection
19309
19310 Sub-expression Elimination
19311 \begin_inset LatexCommand \index{Subexpression elimination}
19312
19313 \end_inset 
19314
19315
19316 \layout Standard
19317
19318 The compiler does local and 
19319 \emph on 
19320 g
19321 \emph default 
19322 lobal 
19323 \emph on 
19324 c
19325 \emph default 
19326 ommon 
19327 \emph on 
19328 s
19329 \emph default 
19330 ubexpression 
19331 \emph on 
19332 e
19333 \emph default 
19334 limination, e.g.: 
19335 \layout Verse
19336
19337
19338 \family typewriter 
19339 i = x + y + 1; 
19340 \newline 
19341 j = x + y;
19342 \layout Standard
19343
19344 will be translated to
19345 \layout Verse
19346
19347
19348 \family typewriter 
19349 iTemp = x + y; 
19350 \newline 
19351 i = iTemp + 1; 
19352 \newline 
19353 j = iTemp;
19354 \layout Standard
19355
19356 Some subexpressions are not as obvious as the above example, e.g.:
19357 \layout Verse
19358
19359
19360 \family typewriter 
19361 a->b[i].c = 10; 
19362 \newline 
19363 a->b[i].d = 11;
19364 \layout Standard
19365
19366 In this case the address arithmetic a->b[i] will be computed only once;
19367  the equivalent code in C would be.
19368 \layout Verse
19369
19370
19371 \family typewriter 
19372 iTemp = a->b[i]; 
19373 \newline 
19374 iTemp.c = 10; 
19375 \newline 
19376 iTemp.d = 11;
19377 \layout Standard
19378
19379 The compiler will try to keep these temporary variables in registers.
19380 \layout Subsection
19381
19382 Dead-Code Elimination
19383 \begin_inset LatexCommand \index{Dead-code elimination}
19384
19385 \end_inset 
19386
19387
19388 \layout Verse
19389
19390
19391 \family typewriter 
19392 int global;
19393 \newline 
19394
19395 \newline 
19396 void f () { 
19397 \newline 
19398 \SpecialChar ~
19399 \SpecialChar ~
19400 int i; 
19401 \newline 
19402 \SpecialChar ~
19403 \SpecialChar ~
19404 i = 1; \SpecialChar ~
19405 \SpecialChar ~
19406 \SpecialChar ~
19407 \SpecialChar ~
19408 \SpecialChar ~
19409 /* dead store */ 
19410 \newline 
19411 \SpecialChar ~
19412 \SpecialChar ~
19413 global = 1;\SpecialChar ~
19414 /* dead store */ 
19415 \newline 
19416 \SpecialChar ~
19417 \SpecialChar ~
19418 global = 2; 
19419 \newline 
19420 \SpecialChar ~
19421 \SpecialChar ~
19422 return; 
19423 \newline 
19424 \SpecialChar ~
19425 \SpecialChar ~
19426 global = 3;\SpecialChar ~
19427 /* unreachable */ 
19428 \newline 
19429 }
19430 \layout Standard
19431
19432 will be changed to
19433 \layout Verse
19434
19435
19436 \family typewriter 
19437 int global;
19438 \newline 
19439
19440 \newline 
19441 void f () {
19442 \newline 
19443 \SpecialChar ~
19444 \SpecialChar ~
19445 global = 2; 
19446 \newline 
19447 \SpecialChar ~
19448 \SpecialChar ~
19449 return; 
19450 \newline 
19451 }
19452 \layout Subsection
19453
19454 Copy-Propagation
19455 \begin_inset LatexCommand \index{Copy propagation}
19456
19457 \end_inset 
19458
19459
19460 \layout Verse
19461
19462
19463 \family typewriter 
19464 int f() { 
19465 \newline 
19466 \SpecialChar ~
19467 \SpecialChar ~
19468 int i, j; 
19469 \newline 
19470 \SpecialChar ~
19471 \SpecialChar ~
19472 i = 10; 
19473 \newline 
19474 \SpecialChar ~
19475 \SpecialChar ~
19476 j = i; 
19477 \newline 
19478 \SpecialChar ~
19479 \SpecialChar ~
19480 return j; 
19481 \newline 
19482 }
19483 \layout Standard
19484
19485 will be changed to 
19486 \layout Verse
19487
19488
19489 \family typewriter 
19490 int f() { 
19491 \newline 
19492 \SpecialChar ~
19493 \SpecialChar ~
19494 int i, j; 
19495 \newline 
19496 \SpecialChar ~
19497 \SpecialChar ~
19498 i = 10; 
19499 \newline 
19500 \SpecialChar ~
19501 \SpecialChar ~
19502 j = 10; 
19503 \newline 
19504 \SpecialChar ~
19505 \SpecialChar ~
19506 return 10; 
19507 \newline 
19508 }
19509 \layout Standard
19510
19511 Note: the dead stores created by this copy propagation will be eliminated
19512  by dead-code elimination.
19513 \layout Subsection
19514
19515 Loop Optimizations
19516 \begin_inset LatexCommand \index{Loop optimization}
19517
19518 \end_inset 
19519
19520
19521 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
19522
19523 \end_inset 
19524
19525
19526 \layout Standard
19527
19528 Two types of loop optimizations are done by SDCC 
19529 \emph on 
19530 loop invariant
19531 \emph default 
19532  lifting and
19533 \emph on 
19534  strength reduction
19535 \emph default 
19536  of loop induction variables.
19537  In addition to the strength reduction the optimizer marks the induction
19538  variables and the register allocator tries to keep the induction variables
19539  in registers for the duration of the loop.
19540  Because of this preference of the register allocator
19541 \begin_inset LatexCommand \index{Register allocation}
19542
19543 \end_inset 
19544
19545 , loop induction optimization causes an increase in register pressure, which
19546  may cause unwanted spilling of other temporary variables into the stack
19547 \begin_inset LatexCommand \index{stack}
19548
19549 \end_inset 
19550
19551  / data space.
19552  The compiler will generate a warning message when it is forced to allocate
19553  extra space either on the stack or data space.
19554  If this extra space allocation is undesirable then induction optimization
19555  can be eliminated either for the entire source file (with -
19556 \begin_inset ERT
19557 status Collapsed
19558
19559 \layout Standard
19560
19561 \backslash 
19562 /
19563 \end_inset 
19564
19565 -noinduction option) or for a given function only using #pragma\SpecialChar ~
19566 noinduction
19567 \begin_inset LatexCommand \index{\#pragma noinduction}
19568
19569 \end_inset 
19570
19571 .
19572 \newline 
19573
19574 \newline 
19575 Loop Invariant:
19576 \layout Verse
19577
19578
19579 \family typewriter 
19580 for (i = 0 ; i < 100 ; i ++) 
19581 \newline 
19582 \SpecialChar ~
19583 \SpecialChar ~
19584 \SpecialChar ~
19585 \SpecialChar ~
19586 f += k + l;
19587 \layout Standard
19588
19589 changed to
19590 \layout Verse
19591
19592
19593 \family typewriter 
19594 itemp = k + l; 
19595 \newline 
19596 for (i = 0; i < 100; i++) 
19597 \newline 
19598 \SpecialChar ~
19599 \SpecialChar ~
19600 \SpecialChar ~
19601 \SpecialChar ~
19602 f += itemp;
19603 \layout Standard
19604
19605 As mentioned previously some loop invariants are not as apparent, all static
19606  address computations are also moved out of the loop.
19607 \newline 
19608
19609 \newline 
19610 Strength Reduction
19611 \begin_inset LatexCommand \index{Strength reduction}
19612
19613 \end_inset 
19614
19615 , this optimization substitutes an expression by a cheaper expression:
19616 \layout Verse
19617
19618
19619 \family typewriter 
19620 for (i=0;i < 100; i++)
19621 \newline 
19622 \SpecialChar ~
19623 \SpecialChar ~
19624 \SpecialChar ~
19625 \SpecialChar ~
19626 ar[i*5] = i*3;
19627 \layout Standard
19628
19629 changed to
19630 \layout Verse
19631
19632
19633 \family typewriter 
19634 itemp1 = 0; 
19635 \newline 
19636 itemp2 = 0; 
19637 \newline 
19638 for (i=0;i< 100;i++) { 
19639 \newline 
19640 \SpecialChar ~
19641 \SpecialChar ~
19642 \SpecialChar ~
19643 \SpecialChar ~
19644 ar[itemp1] = itemp2; 
19645 \newline 
19646 \SpecialChar ~
19647 \SpecialChar ~
19648 \SpecialChar ~
19649 \SpecialChar ~
19650 itemp1 += 5; 
19651 \newline 
19652 \SpecialChar ~
19653 \SpecialChar ~
19654 \SpecialChar ~
19655 \SpecialChar ~
19656 itemp2 += 3; 
19657 \newline 
19658 }
19659 \layout Standard
19660
19661 The more expensive multiplication
19662 \begin_inset LatexCommand \index{Multiplication}
19663
19664 \end_inset 
19665
19666  is changed to a less expensive addition.
19667 \layout Subsection
19668
19669 Loop Reversing
19670 \begin_inset LatexCommand \index{Loop reversing}
19671
19672 \end_inset 
19673
19674
19675 \layout Standard
19676
19677 This optimization is done to reduce the overhead of checking loop boundaries
19678  for every iteration.
19679  Some simple loops can be reversed and implemented using a 
19680 \begin_inset Quotes eld
19681 \end_inset 
19682
19683 decrement and jump if not zero
19684 \begin_inset Quotes erd
19685 \end_inset 
19686
19687  instruction.
19688  SDCC checks for the following criterion to determine if a loop is reversible
19689  (note: more sophisticated compilers use data-dependency analysis to make
19690  this determination, SDCC uses a more simple minded analysis).
19691 \layout Itemize
19692
19693 The 'for' loop is of the form 
19694 \newline 
19695
19696 \newline 
19697
19698 \family typewriter 
19699 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
19700  += 1])
19701 \newline 
19702 \SpecialChar ~
19703 \SpecialChar ~
19704 \SpecialChar ~
19705 \SpecialChar ~
19706 <for body>
19707 \layout Itemize
19708
19709 The <for body> does not contain 
19710 \begin_inset Quotes eld
19711 \end_inset 
19712
19713 continue
19714 \begin_inset Quotes erd
19715 \end_inset 
19716
19717  or 'break
19718 \begin_inset Quotes erd
19719 \end_inset 
19720
19721 .
19722 \layout Itemize
19723
19724 All goto's are contained within the loop.
19725 \layout Itemize
19726
19727 No function calls within the loop.
19728 \layout Itemize
19729
19730 The loop control variable <sym> is not assigned any value within the loop
19731 \layout Itemize
19732
19733 The loop control variable does NOT participate in any arithmetic operation
19734  within the loop.
19735 \layout Itemize
19736
19737 There are NO switch statements in the loop.
19738 \layout Subsection
19739
19740 Algebraic Simplifications
19741 \layout Standard
19742
19743 SDCC does numerous algebraic simplifications, the following is a small sub-set
19744  of these optimizations.
19745 \layout Verse
19746
19747
19748 \family typewriter 
19749 i = j + 0;\SpecialChar ~
19750 \SpecialChar ~
19751 \SpecialChar ~
19752 \SpecialChar ~
19753  /* changed to: */\SpecialChar ~
19754 \SpecialChar ~
19755 \SpecialChar ~
19756 \SpecialChar ~
19757  i = j; 
19758 \newline 
19759 i /= 2;\SpecialChar ~
19760 \SpecialChar ~
19761 \SpecialChar ~
19762 \SpecialChar ~
19763 \SpecialChar ~
19764 \SpecialChar ~
19765 \SpecialChar ~
19766  /* changed to: */\SpecialChar ~
19767 \SpecialChar ~
19768 \SpecialChar ~
19769 \SpecialChar ~
19770  i >>= 1; 
19771 \newline 
19772 i = j - j;\SpecialChar ~
19773 \SpecialChar ~
19774 \SpecialChar ~
19775 \SpecialChar ~
19776  /* changed to: */\SpecialChar ~
19777 \SpecialChar ~
19778 \SpecialChar ~
19779 \SpecialChar ~
19780  i = 0; 
19781 \newline 
19782 i = j / 1;\SpecialChar ~
19783 \SpecialChar ~
19784 \SpecialChar ~
19785 \SpecialChar ~
19786  /* changed to: */\SpecialChar ~
19787 \SpecialChar ~
19788 \SpecialChar ~
19789 \SpecialChar ~
19790  i = j;
19791 \layout Standard
19792
19793 Note the subexpressions
19794 \begin_inset LatexCommand \index{Subexpression}
19795
19796 \end_inset 
19797
19798  given above are generally introduced by macro expansions or as a result
19799  of copy/constant propagation.
19800 \layout Subsection
19801
19802 'switch' Statements
19803 \begin_inset LatexCommand \label{sub:'switch'-Statements}
19804
19805 \end_inset 
19806
19807
19808 \begin_inset LatexCommand \index{switch statement}
19809
19810 \end_inset 
19811
19812
19813 \layout Standard
19814
19815 SDCC changes switch statements to jump tables
19816 \begin_inset LatexCommand \index{jump tables}
19817
19818 \end_inset 
19819
19820  when the following conditions are true.
19821  
19822 \layout Itemize
19823
19824 The case labels are in numerical sequence, the labels need not be in order,
19825  and the starting number need not be one or zero.
19826 \begin_deeper 
19827 \layout Verse
19828
19829
19830 \family typewriter 
19831 switch(i) {\SpecialChar ~
19832 \SpecialChar ~
19833 \SpecialChar ~
19834 \SpecialChar ~
19835 \SpecialChar ~
19836 \SpecialChar ~
19837 \SpecialChar ~
19838 \SpecialChar ~
19839 \SpecialChar ~
19840 \SpecialChar ~
19841 \SpecialChar ~
19842 \SpecialChar ~
19843 \SpecialChar ~
19844 \SpecialChar ~
19845 \SpecialChar ~
19846 \SpecialChar ~
19847 \SpecialChar ~
19848 \SpecialChar ~
19849 \SpecialChar ~
19850 \SpecialChar ~
19851 \SpecialChar ~
19852 \SpecialChar ~
19853 \SpecialChar ~
19854 \SpecialChar ~
19855 \SpecialChar ~
19856 \SpecialChar ~
19857 switch (i) { 
19858 \newline 
19859 \SpecialChar ~
19860 \SpecialChar ~
19861 \SpecialChar ~
19862 case 4: ...\SpecialChar ~
19863 \SpecialChar ~
19864 \SpecialChar ~
19865 \SpecialChar ~
19866 \SpecialChar ~
19867 \SpecialChar ~
19868 \SpecialChar ~
19869 \SpecialChar ~
19870 \SpecialChar ~
19871 \SpecialChar ~
19872 \SpecialChar ~
19873 \SpecialChar ~
19874 \SpecialChar ~
19875 \SpecialChar ~
19876 \SpecialChar ~
19877 \SpecialChar ~
19878 \SpecialChar ~
19879 \SpecialChar ~
19880 \SpecialChar ~
19881 \SpecialChar ~
19882 \SpecialChar ~
19883 \SpecialChar ~
19884 \SpecialChar ~
19885 \SpecialChar ~
19886 \SpecialChar ~
19887 \SpecialChar ~
19888 case 0: ...
19889  
19890 \newline 
19891 \SpecialChar ~
19892 \SpecialChar ~
19893 \SpecialChar ~
19894 case 5: ...\SpecialChar ~
19895 \SpecialChar ~
19896 \SpecialChar ~
19897 \SpecialChar ~
19898 \SpecialChar ~
19899 \SpecialChar ~
19900 \SpecialChar ~
19901 \SpecialChar ~
19902 \SpecialChar ~
19903 \SpecialChar ~
19904 \SpecialChar ~
19905 \SpecialChar ~
19906 \SpecialChar ~
19907 \SpecialChar ~
19908 \SpecialChar ~
19909 \SpecialChar ~
19910 \SpecialChar ~
19911 \SpecialChar ~
19912 \SpecialChar ~
19913 \SpecialChar ~
19914 \SpecialChar ~
19915 \SpecialChar ~
19916 \SpecialChar ~
19917 \SpecialChar ~
19918 \SpecialChar ~
19919 \SpecialChar ~
19920 case 1: ...
19921  
19922 \newline 
19923 \SpecialChar ~
19924 \SpecialChar ~
19925 \SpecialChar ~
19926 case 3: ...\SpecialChar ~
19927 \SpecialChar ~
19928 \SpecialChar ~
19929 \SpecialChar ~
19930 \SpecialChar ~
19931 \SpecialChar ~
19932 \SpecialChar ~
19933 \SpecialChar ~
19934 \SpecialChar ~
19935 \SpecialChar ~
19936 \SpecialChar ~
19937 \SpecialChar ~
19938 \SpecialChar ~
19939 \SpecialChar ~
19940 \SpecialChar ~
19941 \SpecialChar ~
19942 \SpecialChar ~
19943 \SpecialChar ~
19944 \SpecialChar ~
19945 \SpecialChar ~
19946 \SpecialChar ~
19947 \SpecialChar ~
19948 \SpecialChar ~
19949 \SpecialChar ~
19950 \SpecialChar ~
19951 \SpecialChar ~
19952 case 2: ...
19953  
19954 \newline 
19955 \SpecialChar ~
19956 \SpecialChar ~
19957 \SpecialChar ~
19958 case 6: ...\SpecialChar ~
19959 \SpecialChar ~
19960 \SpecialChar ~
19961 \SpecialChar ~
19962 \SpecialChar ~
19963 \SpecialChar ~
19964 \SpecialChar ~
19965 \SpecialChar ~
19966 \SpecialChar ~
19967 \SpecialChar ~
19968 \SpecialChar ~
19969 \SpecialChar ~
19970 \SpecialChar ~
19971 \SpecialChar ~
19972 \SpecialChar ~
19973 \SpecialChar ~
19974 \SpecialChar ~
19975 \SpecialChar ~
19976 \SpecialChar ~
19977 \SpecialChar ~
19978 \SpecialChar ~
19979 \SpecialChar ~
19980 \SpecialChar ~
19981 \SpecialChar ~
19982 \SpecialChar ~
19983 \SpecialChar ~
19984 case 3: ...
19985  
19986 \newline 
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 \SpecialChar ~
20000 \SpecialChar ~
20001 \SpecialChar ~
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 }
20024 \layout Standard
20025
20026 Both the above switch statements will be implemented using a jump-table.
20027  The example to the right side is slightly more efficient as the check for
20028  the lower boundary of the jump-table is not needed.
20029 \end_deeper 
20030 \layout Itemize
20031
20032 The number of case labels is at least three, since it takes two conditional
20033  statements to handle the boundary conditions.
20034 \layout Itemize
20035
20036 The number of case labels is less than 84, since each label takes 3 bytes
20037  and a jump-table can be utmost 256 bytes long.
20038 \layout Standard
20039
20040 Switch statements which have gaps in the numeric sequence or those that
20041  have more that 84 case labels can be split into more than one switch statement
20042  for efficient code generation, e.g.:
20043 \layout Verse
20044
20045
20046 \family typewriter 
20047 switch (i) { 
20048 \newline 
20049 \SpecialChar ~
20050 \SpecialChar ~
20051 case 1: ...
20052  
20053 \newline 
20054 \SpecialChar ~
20055 \SpecialChar ~
20056 case 2: ...
20057  
20058 \newline 
20059 \SpecialChar ~
20060 \SpecialChar ~
20061 case 3: ...
20062  
20063 \newline 
20064 \SpecialChar ~
20065 \SpecialChar ~
20066 case 4: ...
20067  
20068 \newline 
20069 \SpecialChar ~
20070 \SpecialChar ~
20071 case 9: ...
20072  
20073 \newline 
20074 \SpecialChar ~
20075 \SpecialChar ~
20076 case 10: ...
20077  
20078 \newline 
20079 \SpecialChar ~
20080 \SpecialChar ~
20081 case 11: ...
20082  
20083 \newline 
20084 \SpecialChar ~
20085 \SpecialChar ~
20086 case 12: ...
20087  
20088 \newline 
20089 }
20090 \layout Standard
20091
20092 If the above switch statement is broken down into two switch statements
20093 \layout Verse
20094
20095
20096 \family typewriter 
20097 switch (i) { 
20098 \newline 
20099 \SpecialChar ~
20100 \SpecialChar ~
20101 case 1: ...
20102  
20103 \newline 
20104 \SpecialChar ~
20105 \SpecialChar ~
20106 case 2: ...
20107  
20108 \newline 
20109 \SpecialChar ~
20110 \SpecialChar ~
20111 case 3: ...
20112  
20113 \newline 
20114 \SpecialChar ~
20115 \SpecialChar ~
20116 case 4: ...
20117  
20118 \newline 
20119 }
20120 \layout Standard
20121
20122 and
20123 \layout Verse
20124
20125
20126 \family typewriter 
20127 switch (i) { 
20128 \newline 
20129 \SpecialChar ~
20130 \SpecialChar ~
20131 case 9:\SpecialChar ~
20132 \SpecialChar ~
20133 ...
20134  
20135 \newline 
20136 \SpecialChar ~
20137 \SpecialChar ~
20138 case 10:\SpecialChar ~
20139 ...
20140  
20141 \newline 
20142 \SpecialChar ~
20143 \SpecialChar ~
20144 case 11:\SpecialChar ~
20145 ...
20146  
20147 \newline 
20148 \SpecialChar ~
20149 \SpecialChar ~
20150 case 12:\SpecialChar ~
20151 ...
20152  
20153 \newline 
20154 }
20155 \layout Standard
20156
20157 then both the switch statements will be implemented using jump-tables whereas
20158  the unmodified switch statement will not be.
20159  You might also consider inserting dummy cases 0 and 5 to 8 in this example.
20160  
20161 \newline 
20162 The pragma nojtbound
20163 \begin_inset LatexCommand \index{\#pragma nojtbound}
20164
20165 \end_inset 
20166
20167  can be used to turn off checking the 
20168 \emph on 
20169 j
20170 \emph default 
20171 ump 
20172 \emph on 
20173 t
20174 \emph default 
20175 able 
20176 \emph on 
20177 bound
20178 \emph default 
20179 aries.
20180  It has no effect if a default label is supplied.
20181  Use of this pragma is dangerous: if the switch argument is not matched
20182  by a case statement the processor will happily jump into Nirvana.
20183 \layout Subsection
20184
20185 Bit-shifting Operations
20186 \begin_inset LatexCommand \index{Bit shifting}
20187
20188 \end_inset 
20189
20190 .
20191 \layout Standard
20192
20193 Bit shifting is one of the most frequently used operation in embedded programmin
20194 g.
20195  SDCC tries to implement bit-shift operations in the most efficient way
20196  possible, e.g.:
20197 \layout Verse
20198
20199
20200 \family typewriter 
20201 unsigned char i;
20202 \newline 
20203 ...
20204  
20205 \newline 
20206 i >>= 4; 
20207 \newline 
20208 ...
20209 \layout Standard
20210
20211 generates the following code:
20212 \layout Verse
20213
20214
20215 \family typewriter 
20216 mov\SpecialChar ~
20217  a,_i 
20218 \newline 
20219 swap a 
20220 \newline 
20221 anl\SpecialChar ~
20222  a,#0x0f 
20223 \newline 
20224 mov\SpecialChar ~
20225  _i,a
20226 \layout Standard
20227
20228 In general SDCC will never setup a loop if the shift count is known.
20229  Another example:
20230 \layout Verse
20231
20232
20233 \family typewriter 
20234 unsigned int i; 
20235 \newline 
20236 ...
20237  
20238 \newline 
20239 i >>= 9; 
20240 \newline 
20241 ...
20242 \layout Standard
20243
20244 will generate:
20245 \layout Verse
20246
20247
20248 \family typewriter 
20249 mov\SpecialChar ~
20250 \SpecialChar ~
20251 a,(_i + 1) 
20252 \newline 
20253 mov\SpecialChar ~
20254 \SpecialChar ~
20255 (_i + 1),#0x00 
20256 \newline 
20257 clr\SpecialChar ~
20258 \SpecialChar ~
20259
20260 \newline 
20261 rrc\SpecialChar ~
20262 \SpecialChar ~
20263
20264 \newline 
20265 mov\SpecialChar ~
20266 \SpecialChar ~
20267 _i,a
20268 \layout Subsection
20269
20270 Bit-rotation
20271 \begin_inset LatexCommand \index{Bit rotation}
20272
20273 \end_inset 
20274
20275
20276 \layout Standard
20277
20278 A special case of the bit-shift operation is bit rotation
20279 \begin_inset LatexCommand \index{rotating bits}
20280
20281 \end_inset 
20282
20283 , SDCC recognizes the following expression to be a left bit-rotation:
20284 \layout Verse
20285
20286
20287 \family typewriter 
20288 \series bold 
20289 unsigned
20290 \series default 
20291 \SpecialChar ~
20292 \SpecialChar ~
20293 char i;\SpecialChar ~
20294 \SpecialChar ~
20295 \SpecialChar ~
20296 \SpecialChar ~
20297 \SpecialChar ~
20298 \SpecialChar ~
20299 \SpecialChar ~
20300 \SpecialChar ~
20301 \SpecialChar ~
20302 \SpecialChar ~
20303 \SpecialChar ~
20304 /* unsigned is needed for rotation */ 
20305 \newline 
20306 ...
20307  
20308 \newline 
20309 i = ((i << 1) | (i >> 7)); 
20310 \family default 
20311
20312 \newline 
20313
20314 \family typewriter 
20315 ...
20316 \layout Standard
20317
20318 will generate the following code:
20319 \layout Verse
20320
20321
20322 \family typewriter 
20323 mov\SpecialChar ~
20324 \SpecialChar ~
20325 a,_i 
20326 \newline 
20327 rl\SpecialChar ~
20328 \SpecialChar ~
20329 \SpecialChar ~
20330
20331 \newline 
20332 mov\SpecialChar ~
20333 \SpecialChar ~
20334 _i,a
20335 \layout Standard
20336
20337 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
20338 ns of this case will also be recognized as bit-rotation, i.e.: 
20339 \layout Verse
20340
20341
20342 \family typewriter 
20343 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
20344 \layout Subsection
20345
20346 Nibble and Byte Swapping
20347 \layout Standard
20348
20349 Other special cases of the bit-shift operations are nibble or byte swapping
20350 \begin_inset LatexCommand \index{swapping nibbles/bytes}
20351
20352 \end_inset 
20353
20354 , SDCC recognizes the following expressions:
20355 \layout Verse
20356
20357
20358 \family typewriter 
20359 \series bold 
20360 unsigned
20361 \series default 
20362 \SpecialChar ~
20363 \SpecialChar ~
20364 char i; 
20365 \newline 
20366
20367 \series bold 
20368 unsigned
20369 \series default 
20370 \SpecialChar ~
20371 \SpecialChar ~
20372 int j; 
20373 \newline 
20374 ...
20375  
20376 \newline 
20377 i = ((i << 4) | (i >> 4)); 
20378 \family default 
20379
20380 \newline 
20381
20382 \family typewriter 
20383 j = ((j << 8) | (j >> 8)); 
20384 \layout Standard
20385
20386 and generates a swap instruction for the nibble swapping
20387 \begin_inset LatexCommand \index{Nibble swapping}
20388
20389 \end_inset 
20390
20391  or move instructions for the byte swapping
20392 \begin_inset LatexCommand \index{Byte swapping}
20393
20394 \end_inset 
20395
20396 .
20397  The 
20398 \begin_inset Quotes sld
20399 \end_inset 
20400
20401 j
20402 \begin_inset Quotes srd
20403 \end_inset 
20404
20405  example can be used to convert from little to big-endian or vice versa.
20406  If you want to change the endianness of a 
20407 \emph on 
20408 signed
20409 \emph default 
20410  integer you have to cast to 
20411 \family typewriter 
20412 (unsigned int)
20413 \family default 
20414  first.
20415 \layout Standard
20416
20417 Note that SDCC stores numbers in little-endian
20418 \begin_inset Foot
20419 collapsed false
20420
20421 \layout Standard
20422
20423 Usually 8-bit processors don't care much about endianness.
20424  This is not the case for the standard 8051 which only has an instruction
20425  to increment its 
20426 \emph on 
20427 dptr
20428 \emph default 
20429
20430 \begin_inset LatexCommand \index{DPTR}
20431
20432 \end_inset 
20433
20434 -datapointer
20435 \emph on 
20436  
20437 \emph default 
20438 so little-endian is the more efficient byte order.
20439 \end_inset 
20440
20441
20442 \begin_inset LatexCommand \index{little-endian}
20443
20444 \end_inset 
20445
20446
20447 \begin_inset LatexCommand \index{Endianness}
20448
20449 \end_inset 
20450
20451  format (i.e.
20452  lowest order first).
20453 \layout Subsection
20454
20455 Highest Order Bit
20456 \begin_inset LatexCommand \index{Highest Order Bit}
20457
20458 \end_inset 
20459
20460
20461 \layout Standard
20462
20463 It is frequently required to obtain the highest order bit of an integral
20464  type (long, int, short or char types).
20465  SDCC recognizes the following expression to yield the highest order bit
20466  and generates optimized code for it, e.g.:
20467 \layout Verse
20468
20469
20470 \family typewriter 
20471 unsigned int gint; 
20472 \newline 
20473
20474 \newline 
20475 foo () { 
20476 \newline 
20477 \SpecialChar ~
20478 \SpecialChar ~
20479 unsigned char hob; 
20480 \newline 
20481 \SpecialChar ~
20482 \SpecialChar ~
20483 ...
20484  
20485 \newline 
20486 \SpecialChar ~
20487 \SpecialChar ~
20488 hob = (gint >> 15) & 1; 
20489 \newline 
20490 \SpecialChar ~
20491 \SpecialChar ~
20492 ..
20493  
20494 \newline 
20495 }
20496 \layout Standard
20497
20498 will generate the following code:
20499 \layout Verse
20500
20501
20502 \family typewriter 
20503 \SpecialChar ~
20504 \SpecialChar ~
20505 \SpecialChar ~
20506 \SpecialChar ~
20507 \SpecialChar ~
20508 \SpecialChar ~
20509 \SpecialChar ~
20510 \SpecialChar ~
20511 \SpecialChar ~
20512 \SpecialChar ~
20513 \SpecialChar ~
20514 \SpecialChar ~
20515 \SpecialChar ~
20516 \SpecialChar ~
20517 \SpecialChar ~
20518 \SpecialChar ~
20519 \SpecialChar ~
20520 \SpecialChar ~
20521 \SpecialChar ~
20522 \SpecialChar ~
20523 \SpecialChar ~
20524 \SpecialChar ~
20525 \SpecialChar ~
20526 \SpecialChar ~
20527 \SpecialChar ~
20528  61 ;\SpecialChar ~
20529  hob.c 7 
20530 \newline 
20531 000A E5*01\SpecialChar ~
20532 \SpecialChar ~
20533 \SpecialChar ~
20534 \SpecialChar ~
20535 \SpecialChar ~
20536 \SpecialChar ~
20537 \SpecialChar ~
20538 \SpecialChar ~
20539 \SpecialChar ~
20540 \SpecialChar ~
20541 \SpecialChar ~
20542 \SpecialChar ~
20543 \SpecialChar ~
20544 \SpecialChar ~
20545 \SpecialChar ~
20546  62\SpecialChar ~
20547 \SpecialChar ~
20548 \SpecialChar ~
20549 \SpecialChar ~
20550 \SpecialChar ~
20551 \SpecialChar ~
20552 \SpecialChar ~
20553 \SpecialChar ~
20554  mov\SpecialChar ~
20555 \SpecialChar ~
20556  a,(_gint + 1) 
20557 \newline 
20558 000C 23\SpecialChar ~
20559 \SpecialChar ~
20560 \SpecialChar ~
20561 \SpecialChar ~
20562 \SpecialChar ~
20563 \SpecialChar ~
20564 \SpecialChar ~
20565 \SpecialChar ~
20566 \SpecialChar ~
20567 \SpecialChar ~
20568 \SpecialChar ~
20569 \SpecialChar ~
20570 \SpecialChar ~
20571 \SpecialChar ~
20572 \SpecialChar ~
20573 \SpecialChar ~
20574 \SpecialChar ~
20575 \SpecialChar ~
20576  63\SpecialChar ~
20577 \SpecialChar ~
20578 \SpecialChar ~
20579 \SpecialChar ~
20580 \SpecialChar ~
20581 \SpecialChar ~
20582 \SpecialChar ~
20583 \SpecialChar ~
20584  rl\SpecialChar ~
20585 \SpecialChar ~
20586 \SpecialChar ~
20587  a 
20588 \newline 
20589 000D 54 01\SpecialChar ~
20590 \SpecialChar ~
20591 \SpecialChar ~
20592 \SpecialChar ~
20593 \SpecialChar ~
20594 \SpecialChar ~
20595 \SpecialChar ~
20596 \SpecialChar ~
20597 \SpecialChar ~
20598 \SpecialChar ~
20599 \SpecialChar ~
20600 \SpecialChar ~
20601 \SpecialChar ~
20602 \SpecialChar ~
20603 \SpecialChar ~
20604  64\SpecialChar ~
20605 \SpecialChar ~
20606 \SpecialChar ~
20607 \SpecialChar ~
20608 \SpecialChar ~
20609 \SpecialChar ~
20610 \SpecialChar ~
20611 \SpecialChar ~
20612  anl\SpecialChar ~
20613 \SpecialChar ~
20614  a,#0x01 
20615 \newline 
20616 000F F5*02\SpecialChar ~
20617 \SpecialChar ~
20618 \SpecialChar ~
20619 \SpecialChar ~
20620 \SpecialChar ~
20621 \SpecialChar ~
20622 \SpecialChar ~
20623 \SpecialChar ~
20624 \SpecialChar ~
20625 \SpecialChar ~
20626 \SpecialChar ~
20627 \SpecialChar ~
20628 \SpecialChar ~
20629 \SpecialChar ~
20630 \SpecialChar ~
20631  65\SpecialChar ~
20632 \SpecialChar ~
20633 \SpecialChar ~
20634 \SpecialChar ~
20635 \SpecialChar ~
20636 \SpecialChar ~
20637 \SpecialChar ~
20638 \SpecialChar ~
20639  mov\SpecialChar ~
20640 \SpecialChar ~
20641  _foo_hob_1_1,a
20642 \layout Standard
20643
20644 Variations of this case however will 
20645 \emph on 
20646 not
20647 \emph default 
20648  be recognized.
20649  It is a standard C expression, so I heartily recommend this be the only
20650  way to get the highest order bit, (it is portable).
20651  Of course it will be recognized even if it is embedded in other expressions,
20652  e.g.:
20653 \layout Verse
20654
20655
20656 \family typewriter 
20657 xyz = gint + ((gint >> 15) & 1);
20658 \layout Standard
20659
20660 will still be recognized.
20661 \layout Subsection
20662
20663 Peephole Optimizer
20664 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
20665
20666 \end_inset 
20667
20668
20669 \begin_inset LatexCommand \index{Peephole optimizer}
20670
20671 \end_inset 
20672
20673
20674 \layout Standard
20675
20676 The compiler uses a rule based, pattern matching and re-writing mechanism
20677  for peep-hole optimization.
20678  It is inspired by 
20679 \emph on 
20680 copt
20681 \emph default 
20682  a peep-hole optimizer by Christopher W.
20683  Fraser (cwfraser@microsoft.com).
20684  A default set of rules are compiled into the compiler, additional rules
20685  may be added with the 
20686 \emph on 
20687 -
20688 \begin_inset ERT
20689 status Collapsed
20690
20691 \layout Standard
20692
20693 \backslash 
20694 /
20695 \end_inset 
20696
20697 -peep-file
20698 \begin_inset LatexCommand \index{-\/-peep-file}
20699
20700 \end_inset 
20701
20702  <filename>
20703 \emph default 
20704  option.
20705  The rule language is best illustrated with examples.
20706 \layout Verse
20707
20708
20709 \family typewriter 
20710 replace { 
20711 \newline 
20712 \SpecialChar ~
20713 \SpecialChar ~
20714 mov %1,a 
20715 \newline 
20716 \SpecialChar ~
20717 \SpecialChar ~
20718 mov a,%1
20719 \newline 
20720 } by {
20721 \newline 
20722 \SpecialChar ~
20723 \SpecialChar ~
20724 mov %1,a
20725 \newline 
20726 }
20727 \layout Standard
20728
20729 The above rule will change the following assembly
20730 \begin_inset LatexCommand \index{Assembler routines}
20731
20732 \end_inset 
20733
20734  sequence:
20735 \layout Verse
20736
20737
20738 \family typewriter 
20739 mov r1,a 
20740 \newline 
20741 mov a,r1
20742 \layout Standard
20743
20744 to
20745 \layout Verse
20746
20747
20748 \family typewriter 
20749 mov r1,a
20750 \layout Standard
20751
20752 Note: All occurrences of a 
20753 \emph on 
20754 %n
20755 \emph default 
20756  (pattern variable) must denote the same string.
20757  With the above rule, the assembly sequence:
20758 \layout Verse
20759
20760
20761 \family typewriter 
20762 mov r1,a 
20763 \newline 
20764 mov a,r2
20765 \layout Standard
20766
20767 will remain unmodified.
20768 \newline 
20769
20770 \newline 
20771 Other special case optimizations may be added by the user (via 
20772 \emph on 
20773 -
20774 \begin_inset ERT
20775 status Collapsed
20776
20777 \layout Standard
20778
20779 \backslash 
20780 /
20781 \end_inset 
20782
20783 -peep-file option
20784 \emph default 
20785 ).
20786  E.g.
20787  some variants of the 8051 MCU
20788 \begin_inset LatexCommand \index{MCS51 variants}
20789
20790 \end_inset 
20791
20792  allow only 
20793 \family typewriter 
20794 ajmp
20795 \family default 
20796  and 
20797 \family typewriter 
20798 acall
20799 \family default 
20800 .
20801  The following two rules will change all 
20802 \family typewriter 
20803 ljmp
20804 \family default 
20805  and 
20806 \family typewriter 
20807 lcall
20808 \family default 
20809  to 
20810 \family typewriter 
20811 ajmp
20812 \family default 
20813  and 
20814 \family typewriter 
20815 acall
20816 \layout Verse
20817
20818
20819 \family typewriter 
20820 replace { lcall %1 } by { acall %1 } 
20821 \newline 
20822 replace { ljmp %1 } by { ajmp %1 }
20823 \layout Standard
20824
20825 The 
20826 \emph on 
20827 inline-assembler code
20828 \emph default 
20829  is also passed through the peep hole optimizer, thus the peephole optimizer
20830  can also be used as an assembly level macro expander.
20831  The rules themselves are MCU dependent whereas the rule language infra-structur
20832 e is MCU independent.
20833  Peephole optimization rules for other MCU can be easily programmed using
20834  the rule language.
20835 \newline 
20836
20837 \newline 
20838 The syntax for a rule is as follows:
20839 \layout Verse
20840
20841
20842 \family typewriter 
20843 rule := replace [ restart ] '{' <assembly sequence> '
20844 \backslash 
20845 n' 
20846 \newline 
20847 \SpecialChar ~
20848  \SpecialChar ~
20849  \SpecialChar ~
20850  \SpecialChar ~
20851  \SpecialChar ~
20852  \SpecialChar ~
20853  \SpecialChar ~
20854  \SpecialChar ~
20855  \SpecialChar ~
20856  \SpecialChar ~
20857  \SpecialChar ~
20858  \SpecialChar ~
20859  \SpecialChar ~
20860  \SpecialChar ~
20861  '}' by '{' '
20862 \backslash 
20863 n' 
20864 \newline 
20865 \SpecialChar ~
20866  \SpecialChar ~
20867  \SpecialChar ~
20868  \SpecialChar ~
20869  \SpecialChar ~
20870  \SpecialChar ~
20871  \SpecialChar ~
20872  \SpecialChar ~
20873  \SpecialChar ~
20874  \SpecialChar ~
20875  \SpecialChar ~
20876  \SpecialChar ~
20877  \SpecialChar ~
20878  \SpecialChar ~
20879  \SpecialChar ~
20880  \SpecialChar ~
20881  <assembly sequence> '
20882 \backslash 
20883 n' 
20884 \newline 
20885 \SpecialChar ~
20886  \SpecialChar ~
20887  \SpecialChar ~
20888  \SpecialChar ~
20889  \SpecialChar ~
20890  \SpecialChar ~
20891  \SpecialChar ~
20892  \SpecialChar ~
20893  \SpecialChar ~
20894  \SpecialChar ~
20895  \SpecialChar ~
20896  \SpecialChar ~
20897  \SpecialChar ~
20898  \SpecialChar ~
20899  '}' [if <functionName> ] '
20900 \backslash 
20901 n' 
20902 \layout Standard
20903
20904 <assembly sequence> := assembly instruction (each instruction including
20905  labels must be on a separate line).
20906 \newline 
20907
20908 \newline 
20909 The optimizer will apply to the rules one by one from the top in the sequence
20910  of their appearance, it will terminate when all rules are exhausted.
20911  If the 'restart' option is specified, then the optimizer will start matching
20912  the rules again from the top, this option for a rule is expensive (performance)
20913 , it is intended to be used in situations where a transformation will trigger
20914  the same rule again.
20915  An example of this (not a good one, it has side effects) is the following
20916  rule:
20917 \layout Verse
20918
20919
20920 \family typewriter 
20921 replace restart { 
20922 \newline 
20923 \SpecialChar ~
20924 \SpecialChar ~
20925 pop %1 
20926 \newline 
20927 \SpecialChar ~
20928 \SpecialChar ~
20929 push %1 } by { 
20930 \newline 
20931 \SpecialChar ~
20932 \SpecialChar ~
20933 ; nop 
20934 \newline 
20935 }
20936 \layout Standard
20937
20938 Note that the replace pattern cannot be a blank, but can be a comment line.
20939  Without the 'restart' option only the innermost 'pop' 'push' pair would
20940  be eliminated, i.e.:
20941 \layout Verse
20942
20943
20944 \family typewriter 
20945 pop ar1 
20946 \newline 
20947 pop ar2 
20948 \newline 
20949 push ar2 
20950 \newline 
20951 push ar1
20952 \layout Standard
20953
20954 would result in:
20955 \layout Verse
20956
20957
20958 \family typewriter 
20959 pop ar1 
20960 \newline 
20961 ; nop 
20962 \newline 
20963 push ar1
20964 \layout Standard
20965
20966
20967 \emph on 
20968 with
20969 \emph default 
20970  the restart option the rule will be applied again to the resulting code
20971  and then all the pop-push pairs will be eliminated to yield:
20972 \layout Verse
20973
20974
20975 \family typewriter 
20976 ; nop 
20977 \newline 
20978 ; nop
20979 \layout Standard
20980
20981 A conditional function can be attached to a rule.
20982  Attaching rules are somewhat more involved, let me illustrate this with
20983  an example.
20984 \layout Verse
20985
20986
20987 \family typewriter 
20988 replace { 
20989 \newline 
20990 \SpecialChar ~
20991  \SpecialChar ~
20992  \SpecialChar ~
20993 ljmp %5 
20994 \newline 
20995 %2:
20996 \newline 
20997 } by { 
20998 \newline 
20999 \SpecialChar ~
21000  \SpecialChar ~
21001  \SpecialChar ~
21002 sjmp %5 
21003 \newline 
21004 %2:
21005 \newline 
21006 } if labelInRange
21007 \layout Standard
21008
21009 The optimizer does a look-up of a function name table defined in function
21010  
21011 \emph on 
21012 callFuncByName
21013 \emph default 
21014  in the source file SDCCpeeph.c, with the name 
21015 \emph on 
21016 labelInRange
21017 \emph default 
21018 .
21019  If it finds a corresponding entry the function is called.
21020  Note there can be no parameters specified for these functions, in this
21021  case the use of 
21022 \emph on 
21023 %5
21024 \emph default 
21025  is crucial, since the function 
21026 \emph on 
21027 labelInRange
21028 \emph default 
21029  expects to find the label in that particular variable (the hash table containin
21030 g the variable bindings is passed as a parameter).
21031  If you want to code more such functions, take a close look at the function
21032  labelInRange and the calling mechanism in source file SDCCpeeph.c.
21033  Currently implemented are 
21034 \emph on 
21035 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
21036  24bitMode, portIsDS390, 24bitModeAndPortDS390 
21037 \emph default 
21038 and
21039 \emph on 
21040  notVolatile
21041 \emph default 
21042 .
21043 \layout Standard
21044
21045 I know this whole thing is a little kludgey, but maybe some day we will
21046  have some better means.
21047  If you are looking at this file, you will see the default rules that are
21048  compiled into the compiler, you can add your own rules in the default set
21049  there if you get tired of specifying the -
21050 \begin_inset ERT
21051 status Collapsed
21052
21053 \layout Standard
21054
21055 \backslash 
21056 /
21057 \end_inset 
21058
21059 -peep-file option.
21060 \layout Section
21061
21062 ANSI-Compliance
21063 \begin_inset LatexCommand \index{ANSI-compliance}
21064
21065 \end_inset 
21066
21067
21068 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
21069
21070 \end_inset 
21071
21072
21073 \layout Standard
21074
21075 Deviations from the compliance:
21076 \layout Itemize
21077
21078 functions are not always reentrant
21079 \begin_inset LatexCommand \index{reentrant}
21080
21081 \end_inset 
21082
21083 .
21084 \layout Itemize
21085
21086 structures cannot be assigned values directly, cannot be passed as function
21087  parameters or assigned to each other and cannot be a return value from
21088  a function, e.g.:
21089 \begin_deeper 
21090 \layout Verse
21091
21092
21093 \family typewriter 
21094 struct s { ...
21095  }; 
21096 \newline 
21097 struct s s1, s2; 
21098 \newline 
21099 foo() 
21100 \newline 
21101
21102 \newline 
21103 \SpecialChar ~
21104 \SpecialChar ~
21105 \SpecialChar ~
21106 \SpecialChar ~
21107 ...
21108  
21109 \newline 
21110 \SpecialChar ~
21111 \SpecialChar ~
21112 \SpecialChar ~
21113 \SpecialChar ~
21114 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
21115 \newline 
21116 \SpecialChar ~
21117 \SpecialChar ~
21118 \SpecialChar ~
21119 \SpecialChar ~
21120 ...
21121  
21122 \newline 
21123 }
21124 \newline 
21125 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
21126  */
21127 \newline 
21128
21129 \newline 
21130 \SpecialChar ~
21131 \SpecialChar ~
21132 \SpecialChar ~
21133 \SpecialChar ~
21134 struct s rets; 
21135 \newline 
21136 \SpecialChar ~
21137 \SpecialChar ~
21138 \SpecialChar ~
21139 \SpecialChar ~
21140 ...
21141  
21142 \newline 
21143 \SpecialChar ~
21144 \SpecialChar ~
21145 \SpecialChar ~
21146 \SpecialChar ~
21147 return rets;/* is invalid in SDCC although allowed in ANSI */ 
21148 \newline 
21149 }
21150 \end_deeper 
21151 \layout Itemize
21152
21153 'long long
21154 \begin_inset LatexCommand \index{long long (not supported)}
21155
21156 \end_inset 
21157
21158 ' (64 bit integers
21159 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
21160
21161 \end_inset 
21162
21163 ) not supported.
21164 \layout Itemize
21165
21166 'double
21167 \begin_inset LatexCommand \index{double (not supported)}
21168
21169 \end_inset 
21170
21171 ' precision floating point 
21172 \begin_inset LatexCommand \index{Floating point support}
21173
21174 \end_inset 
21175
21176 not supported.
21177 \layout Itemize
21178
21179 No support for setjmp
21180 \begin_inset LatexCommand \index{setjmp (not supported)}
21181
21182 \end_inset 
21183
21184  and longjmp
21185 \begin_inset LatexCommand \index{longjmp (not supported)}
21186
21187 \end_inset 
21188
21189  (for now).
21190 \layout Itemize
21191
21192 Old K&R style
21193 \begin_inset LatexCommand \index{K\&R style}
21194
21195 \end_inset 
21196
21197  function declarations are NOT allowed.
21198 \begin_deeper 
21199 \layout Verse
21200
21201
21202 \family typewriter 
21203 foo(i,j) /* this old style of function declarations */ 
21204 \newline 
21205 int i,j; /* are valid in ANSI but not valid in SDCC */ 
21206 \newline 
21207
21208 \newline 
21209 \SpecialChar ~
21210 \SpecialChar ~
21211 \SpecialChar ~
21212 \SpecialChar ~
21213 ...
21214  
21215 \newline 
21216 }
21217 \end_deeper 
21218 \layout Section
21219
21220 Cyclomatic Complexity
21221 \begin_inset LatexCommand \index{Cyclomatic complexity}
21222
21223 \end_inset 
21224
21225
21226 \layout Standard
21227
21228 Cyclomatic complexity of a function is defined as the number of independent
21229  paths the program can take during execution of the function.
21230  This is an important number since it defines the number test cases you
21231  have to generate to validate the function.
21232  The accepted industry standard for complexity number is 10, if the cyclomatic
21233  complexity reported by SDCC exceeds 10 you should think about simplification
21234  of the function logic.
21235  Note that the complexity level is not related to the number of lines of
21236  code in a function.
21237  Large functions can have low complexity, and small functions can have large
21238  complexity levels.
21239  
21240 \newline 
21241
21242 \newline 
21243 SDCC uses the following formula to compute the complexity:
21244 \newline 
21245
21246 \layout Standard
21247
21248 complexity = (number of edges in control flow graph) - (number of nodes
21249  in control flow graph) + 2;
21250 \newline 
21251
21252 \newline 
21253 Having said that the industry standard is 10, you should be aware that in
21254  some cases it be may unavoidable to have a complexity level of less than
21255  10.
21256  For example if you have switch statement with more than 10 case labels,
21257  each case label adds one to the complexity level.
21258  The complexity level is by no means an absolute measure of the algorithmic
21259  complexity of the function, it does however provide a good starting point
21260  for which functions you might look at for further optimization.
21261 \layout Section
21262
21263 Retargetting for other Processors
21264 \layout Standard
21265
21266 The issues for retargetting the compiler are far too numerous to be covered
21267  by this document.
21268  What follows is a brief description of each of the seven phases of the
21269  compiler and its MCU dependency.
21270 \layout Itemize
21271
21272 Parsing the source and building the annotated parse tree.
21273  This phase is largely MCU independent (except for the language extensions).
21274  Syntax & semantic checks are also done in this phase, along with some initial
21275  optimizations like back patching labels and the pattern matching optimizations
21276  like bit-rotation etc.
21277 \layout Itemize
21278
21279 The second phase involves generating an intermediate code which can be easy
21280  manipulated during the later phases.
21281  This phase is entirely MCU independent.
21282  The intermediate code generation assumes the target machine has unlimited
21283  number of registers, and designates them with the name iTemp.
21284  The compiler can be made to dump a human readable form of the code generated
21285  by using the -
21286 \begin_inset ERT
21287 status Collapsed
21288
21289 \layout Standard
21290
21291 \backslash 
21292 /
21293 \end_inset 
21294
21295 -dumpraw option.
21296 \layout Itemize
21297
21298 This phase does the bulk of the standard optimizations and is also MCU independe
21299 nt.
21300  This phase can be broken down into several sub-phases:
21301 \newline 
21302
21303 \newline 
21304 Break down intermediate code (iCode) into basic blocks.
21305 \newline 
21306 Do control flow & data flow analysis on the basic blocks.
21307 \newline 
21308 Do local common subexpression elimination, then global subexpression elimination
21309 \newline 
21310 Dead code elimination
21311 \newline 
21312 Loop optimizations
21313 \newline 
21314 If loop optimizations caused any changes then do 'global subexpression eliminati
21315 on' and 'dead code elimination' again.
21316 \layout Itemize
21317
21318 This phase determines the live-ranges; by live range I mean those iTemp
21319  variables defined by the compiler that still survive after all the optimization
21320 s.
21321  Live range analysis
21322 \begin_inset LatexCommand \index{Live range analysis}
21323
21324 \end_inset 
21325
21326  is essential for register allocation, since these computation determines
21327  which of these iTemps will be assigned to registers, and for how long.
21328 \layout Itemize
21329
21330 Phase five is register allocation.
21331  There are two parts to this process.
21332 \newline 
21333
21334 \newline 
21335 The first part I call 'register packing' (for lack of a better term).
21336  In this case several MCU specific expression folding is done to reduce
21337  register pressure.
21338 \newline 
21339
21340 \newline 
21341 The second part is more MCU independent and deals with allocating registers
21342  to the remaining live ranges.
21343  A lot of MCU specific code does creep into this phase because of the limited
21344  number of index registers available in the 8051.
21345 \layout Itemize
21346
21347 The Code generation phase is (unhappily), entirely MCU dependent and very
21348  little (if any at all) of this code can be reused for other MCU.
21349  However the scheme for allocating a homogenized assembler operand for each
21350  iCode operand may be reused.
21351 \layout Itemize
21352
21353 As mentioned in the optimization section the peep-hole optimizer is rule
21354  based system, which can reprogrammed for other MCUs.
21355 \layout Chapter
21356
21357 Compiler internals
21358 \begin_inset LatexCommand \index{Compiler internals}
21359
21360 \end_inset 
21361
21362
21363 \layout Section
21364
21365 The anatomy of the compiler
21366 \begin_inset LatexCommand \label{sub:The-anatomy-of}
21367
21368 \end_inset 
21369
21370
21371 \layout Standard
21372
21373
21374 \shape italic 
21375 This is an excerpt from an article published in Circuit Cellar Magazine
21376  in august 2000.
21377  It's a little outdated (the compiler is much more efficient now and user/develo
21378 per friendly), but pretty well exposes the guts of it all.
21379 \shape default 
21380
21381 \newline 
21382
21383 \newline 
21384 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
21385  It is fairly easy to retarget for other 8-bit MCU.
21386  Here we take a look at some of the internals of the compiler.
21387  
21388 \layout Paragraph*
21389
21390 Parsing
21391 \begin_inset LatexCommand \index{Parsing}
21392
21393 \end_inset 
21394
21395  
21396 \layout Standard
21397
21398 Parsing the input source file and creating an AST (Annotated Syntax Tree
21399 \begin_inset LatexCommand \index{Annotated syntax tree}
21400
21401 \end_inset 
21402
21403 ).
21404  This phase also involves propagating types (annotating each node of the
21405  parse tree with type information) and semantic analysis.
21406  There are some MCU specific parsing rules.
21407  For example the storage classes, the extended storage classes are MCU specific
21408  while there may be a xdata storage class for 8051 there is no such storage
21409  class for z80 or Atmel AVR.
21410  SDCC allows MCU specific storage class extensions, i.e.
21411  xdata will be treated as a storage class specifier when parsing 8051 C
21412  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
21413  C code.
21414 \layout Paragraph*
21415
21416 Generating iCode
21417 \begin_inset LatexCommand \index{iCode}
21418
21419 \end_inset 
21420
21421
21422 \layout Standard
21423
21424 Intermediate code generation.
21425  In this phase the AST is broken down into three-operand form (iCode).
21426  These three operand forms are represented as doubly linked lists.
21427  ICode is the term given to the intermediate form generated by the compiler.
21428  ICode example section shows some examples of iCode generated for some simple
21429  C source functions.
21430 \layout Paragraph*
21431
21432 Optimizations
21433 \begin_inset LatexCommand \index{Optimizations}
21434
21435 \end_inset 
21436
21437 .
21438 \layout Standard
21439
21440 Bulk of the target independent optimizations is performed in this phase.
21441  The optimizations include constant propagation, common sub-expression eliminati
21442 on, loop invariant code movement, strength reduction of loop induction variables
21443  and dead-code elimination.
21444 \layout Paragraph*
21445
21446 Live range analysis
21447 \begin_inset LatexCommand \index{Live range analysis}
21448
21449 \end_inset 
21450
21451
21452 \layout Standard
21453
21454 During intermediate code generation phase, the compiler assumes the target
21455  machine has infinite number of registers and generates a lot of temporary
21456  variables.
21457  The live range computation determines the lifetime of each of these compiler-ge
21458 nerated temporaries.
21459  A picture speaks a thousand words.
21460  ICode example sections show the live range annotations for each of the
21461  operand.
21462  It is important to note here, each iCode is assigned a number in the order
21463  of its execution in the function.
21464  The live ranges are computed in terms of these numbers.
21465  The from number is the number of the iCode which first defines the operand
21466  and the to number signifies the iCode which uses this operand last.
21467 \layout Paragraph*
21468
21469 Register Allocation
21470 \begin_inset LatexCommand \index{Register allocation}
21471
21472 \end_inset 
21473
21474
21475 \layout Standard
21476
21477 The register allocation determines the type and number of registers needed
21478  by each operand.
21479  In most MCUs only a few registers can be used for indirect addressing.
21480  In case of 8051 for example the registers R0 & R1 can be used to indirectly
21481  address the internal ram and DPTR to indirectly address the external ram.
21482  The compiler will try to allocate the appropriate register to pointer variables
21483  if it can.
21484  ICode example section shows the operands annotated with the registers assigned
21485  to them.
21486  The compiler will try to keep operands in registers as much as possible;
21487  there are several schemes the compiler uses to do achieve this.
21488  When the compiler runs out of registers the compiler will check to see
21489  if there are any live operands which is not used or defined in the current
21490  basic block being processed, if there are any found then it will push that
21491  operand and use the registers in this block, the operand will then be popped
21492  at the end of the basic block.
21493  
21494 \layout Standard
21495
21496 There are other MCU specific considerations in this phase.
21497  Some MCUs have an accumulator; very short-lived operands could be assigned
21498  to the accumulator instead of a general-purpose register.
21499 \layout Paragraph*
21500
21501 Code generation
21502 \layout Standard
21503
21504 Figure II gives a table of iCode operations supported by the compiler.
21505  The code generation involves translating these operations into corresponding
21506  assembly code for the processor.
21507  This sounds overly simple but that is the essence of code generation.
21508  Some of the iCode operations are generated on a MCU specific manner for
21509  example, the z80 port does not use registers to pass parameters so the
21510  SEND and RECV iCode operations will not be generated, and it also does
21511  not support JUMPTABLES.
21512  
21513 \newline 
21514
21515 \series bold 
21516 \shape italic 
21517 \color red
21518 <Where is Figure II ?>
21519 \layout Paragraph*
21520
21521 ICode Example
21522 \begin_inset LatexCommand \index{iCode}
21523
21524 \end_inset 
21525
21526
21527 \layout Standard
21528
21529 This section shows some details of iCode.
21530  The example C code does not do anything useful; it is used as an example
21531  to illustrate the intermediate code generated by the compiler.
21532 \layout Verse
21533
21534
21535 \family typewriter 
21536 1.\SpecialChar ~
21537 xdata int * p;
21538 \newline 
21539 2.\SpecialChar ~
21540 int gint;
21541 \newline 
21542 3.\SpecialChar ~
21543 /* This function does nothing useful.
21544  It is used
21545 \newline 
21546 4.\SpecialChar ~
21547 \SpecialChar ~
21548 \SpecialChar ~
21549 \SpecialChar ~
21550 for the purpose of explaining iCode */
21551 \newline 
21552 5.\SpecialChar ~
21553 short function (data int *x)
21554 \newline 
21555 6.\SpecialChar ~
21556 {
21557 \newline 
21558 7.\SpecialChar ~
21559 \SpecialChar ~
21560 \SpecialChar ~
21561 short i=10; \SpecialChar ~
21562 \SpecialChar ~
21563 /* dead initialization eliminated */
21564 \newline 
21565 8.\SpecialChar ~
21566 \SpecialChar ~
21567 \SpecialChar ~
21568 short sum=10; /* dead initialization eliminated */
21569 \newline 
21570 9.\SpecialChar ~
21571 \SpecialChar ~
21572 \SpecialChar ~
21573 short mul;
21574 \newline 
21575 10.\SpecialChar ~
21576 \SpecialChar ~
21577 int j ;
21578 \newline 
21579 11.\SpecialChar ~
21580 \SpecialChar ~
21581 while (*x) *x++ = *p++; 
21582 \newline 
21583 12.\SpecialChar ~
21584 \SpecialChar ~
21585 \SpecialChar ~
21586 \SpecialChar ~
21587 sum = 0 ; 
21588 \newline 
21589 13.\SpecialChar ~
21590 \SpecialChar ~
21591 mul = 0;
21592 \newline 
21593 14.\SpecialChar ~
21594 \SpecialChar ~
21595 /* compiler detects i,j to be induction variables */
21596 \newline 
21597 15.\SpecialChar ~
21598 \SpecialChar ~
21599 for (i = 0, j = 10 ; i < 10 ; i++, j
21600 \family default 
21601 -
21602 \begin_inset ERT
21603 status Collapsed
21604
21605 \layout Standard
21606
21607 \backslash 
21608 /
21609 \end_inset 
21610
21611 -
21612 \family typewriter 
21613 ) {
21614 \newline 
21615 16.\SpecialChar ~
21616 \SpecialChar ~
21617 \SpecialChar ~
21618 \SpecialChar ~
21619 sum += i;
21620 \newline 
21621 17.\SpecialChar ~
21622 \SpecialChar ~
21623 \SpecialChar ~
21624 \SpecialChar ~
21625 mul += i * 3; \SpecialChar ~
21626 \SpecialChar ~
21627 /* this multiplication remains */
21628 \newline 
21629 18.\SpecialChar ~
21630 \SpecialChar ~
21631 \SpecialChar ~
21632 \SpecialChar ~
21633 gint += j * 3;\SpecialChar ~
21634 \SpecialChar ~
21635 /* this multiplication changed to addition */
21636 \newline 
21637 19.\SpecialChar ~
21638 \SpecialChar ~
21639 }
21640 \newline 
21641 20.\SpecialChar ~
21642 \SpecialChar ~
21643 return sum+mul;
21644 \newline 
21645 21.\SpecialChar ~
21646 }
21647 \layout Standard
21648
21649 In addition to the operands each iCode contains information about the filename
21650  and line it corresponds to in the source file.
21651  The first field in the listing should be interpreted as follows:
21652 \newline 
21653
21654 \shape italic 
21655 \size footnotesize 
21656 Filename(linenumber: iCode Execution sequence number : ICode hash table
21657  key : loop depth of the iCode).
21658 \shape default 
21659 \size default 
21660
21661 \newline 
21662 Then follows the human readable form of the ICode operation.
21663  Each operand of this triplet form can be of three basic types a) compiler
21664  generated temporary b) user defined variable c) a constant value.
21665  Note that local variables and parameters are replaced by compiler generated
21666  temporaries.
21667  Live ranges
21668 \begin_inset LatexCommand \index{Live range analysis}
21669
21670 \end_inset 
21671
21672  are computed only for temporaries (i.e.
21673  live ranges are not computed for global variables).
21674  Registers
21675 \begin_inset LatexCommand \index{Register allocation}
21676
21677 \end_inset 
21678
21679  are allocated for temporaries only.
21680  Operands are formatted in the following manner:
21681 \newline 
21682
21683 \shape italic 
21684 \size footnotesize 
21685 Operand Name [lr live-from : live-to ] { type information } [ registers
21686  allocated ].
21687 \shape default 
21688 \size default 
21689
21690 \newline 
21691 As mentioned earlier the live ranges are computed in terms of the execution
21692  sequence number of the iCodes, for example 
21693 \newline 
21694 the iTemp0 is live from (i.e.
21695  first defined in iCode with execution sequence number 3, and is last used
21696  in the iCode with sequence number 5).
21697  For induction variables such as iTemp21 the live range computation extends
21698  the lifetime from the start to the end of the loop.
21699 \newline 
21700 The register allocator used the live range information to allocate registers,
21701  the same registers may be used for different temporaries if their live
21702  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
21703  iTemp17 since their live ranges do not overlap.
21704  In addition the allocator also takes into consideration the type and usage
21705  of a temporary, for example itemp6 is a pointer to near space and is used
21706  as to fetch data from (i.e.
21707  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
21708  Some short lived temporaries are allocated to special registers which have
21709  meaning to the code generator e.g.
21710  iTemp13 is allocated to a pseudo register CC which tells the back end that
21711  the temporary is used only for a conditional jump the code generation makes
21712  use of this information to optimize a compare and jump ICode.
21713 \newline 
21714 There are several loop optimizations
21715 \begin_inset LatexCommand \index{Loop optimization}
21716
21717 \end_inset 
21718
21719  performed by the compiler.
21720  It can detect induction variables iTemp21(i) and iTemp23(j).
21721  Also note the compiler does selective strength reduction
21722 \begin_inset LatexCommand \index{Strength reduction}
21723
21724 \end_inset 
21725
21726 , i.e.
21727  the multiplication of an induction variable in line 18 (gint = j * 3) is
21728  changed to addition, a new temporary iTemp17 is allocated and assigned
21729  a initial value, a constant 3 is then added for each iteration of the loop.
21730  The compiler does not change the multiplication
21731 \begin_inset LatexCommand \index{Multiplication}
21732
21733 \end_inset 
21734
21735  in line 17 however since the processor does support an 8 * 8 bit multiplication.
21736 \newline 
21737 Note the dead code elimination
21738 \begin_inset LatexCommand \index{Dead-code elimination}
21739
21740 \end_inset 
21741
21742  optimization eliminated the dead assignments in line 7 & 8 to I and sum
21743  respectively.
21744 \newline 
21745
21746 \layout Standard
21747
21748
21749 \size footnotesize 
21750 Sample.c (5:1:0:0) _entry($9) :
21751 \layout Standard
21752
21753
21754 \size footnotesize 
21755 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
21756 \layout Standard
21757
21758
21759 \size footnotesize 
21760 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
21761 \layout Standard
21762
21763
21764 \size footnotesize 
21765 Sample.c(11:4:53:0) preHeaderLbl0($11) :
21766 \layout Standard
21767
21768
21769 \size footnotesize 
21770 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
21771  * int}[r2]
21772 \layout Standard
21773
21774
21775 \size footnotesize 
21776 Sample.c(11:6:5:1) _whilecontinue_0($1) :
21777 \layout Standard
21778
21779
21780 \size footnotesize 
21781 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
21782  int}[r0]]
21783 \layout Standard
21784
21785
21786 \size footnotesize 
21787 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21788 \layout Standard
21789
21790
21791 \size footnotesize 
21792 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
21793  * int}
21794 \layout Standard
21795
21796
21797 \size footnotesize 
21798 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
21799  {short}
21800 \layout Standard
21801
21802
21803 \size footnotesize 
21804 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
21805  * int}[DPTR]]
21806 \layout Standard
21807
21808
21809 \size footnotesize 
21810 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
21811 }[r2 r3]
21812 \layout Standard
21813
21814
21815 \size footnotesize 
21816 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
21817  * int}[r0] + 0x2 {short}
21818 \layout Standard
21819
21820
21821 \size footnotesize 
21822 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
21823 \layout Standard
21824
21825
21826 \size footnotesize 
21827 Sample.c(11:17:21:0)_whilebreak_0($3) :
21828 \layout Standard
21829
21830
21831 \size footnotesize 
21832 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21833 \layout Standard
21834
21835
21836 \size footnotesize 
21837 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21838 \layout Standard
21839
21840
21841 \size footnotesize 
21842 Sample.c(15:20:54:0)preHeaderLbl1($13) :
21843 \layout Standard
21844
21845
21846 \size footnotesize 
21847 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21848 \layout Standard
21849
21850
21851 \size footnotesize 
21852 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21853 \layout Standard
21854
21855
21856 \size footnotesize 
21857 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21858 \layout Standard
21859
21860
21861 \size footnotesize 
21862 Sample.c(15:24:26:1)_forcond_0($4) :
21863 \layout Standard
21864
21865
21866 \size footnotesize 
21867 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
21868  < 0xa {short}
21869 \layout Standard
21870
21871
21872 \size footnotesize 
21873 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21874 \layout Standard
21875
21876
21877 \size footnotesize 
21878 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
21879  + ITemp21 [lr21:38]{short}[r4]
21880 \layout Standard
21881
21882
21883 \size footnotesize 
21884 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
21885  * 0x3 {short}
21886 \layout Standard
21887
21888
21889 \size footnotesize 
21890 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
21891  + iTemp15 [lr29:30]{short}[r1]
21892 \layout Standard
21893
21894
21895 \size footnotesize 
21896 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
21897  r0]- 0x3 {short}
21898 \layout Standard
21899
21900
21901 \size footnotesize 
21902 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
21903 int}[r7 r0]
21904 \layout Standard
21905
21906
21907 \size footnotesize 
21908 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
21909  + 0x1 {short}
21910 \layout Standard
21911
21912
21913 \size footnotesize 
21914 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
21915  r6]- 0x1 {short}
21916 \layout Standard
21917
21918
21919 \size footnotesize 
21920 Sample.c(19:38:47:1) goto _forcond_0($4)
21921 \layout Standard
21922
21923
21924 \size footnotesize 
21925 Sample.c(19:39:48:0)_forbreak_0($7) :
21926 \layout Standard
21927
21928
21929 \size footnotesize 
21930 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
21931  + ITemp11 [lr19:40]{short}[r3]
21932 \layout Standard
21933
21934
21935 \size footnotesize 
21936 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
21937 \layout Standard
21938
21939
21940 \size footnotesize 
21941 Sample.c(20:42:51:0)_return($8) :
21942 \layout Standard
21943
21944
21945 \size footnotesize 
21946 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
21947 \size default 
21948
21949 \newline 
21950
21951 \newline 
21952 Finally the code generated for this function:
21953 \newline 
21954
21955 \layout Standard
21956
21957
21958 \size footnotesize 
21959 .area DSEG (DATA)
21960 \layout Standard
21961
21962
21963 \size footnotesize 
21964 _p::
21965 \layout Standard
21966
21967
21968 \size footnotesize 
21969 \SpecialChar ~
21970 \SpecialChar ~
21971 .ds 2
21972 \layout Standard
21973
21974
21975 \size footnotesize 
21976 _gint::
21977 \layout Standard
21978
21979
21980 \size footnotesize 
21981 \SpecialChar ~
21982 \SpecialChar ~
21983 .ds 2
21984 \layout Standard
21985
21986
21987 \size footnotesize 
21988 ; sample.c 5
21989 \layout Standard
21990
21991
21992 \size footnotesize 
21993 ; ----------------------------------------------
21994 \layout Standard
21995
21996
21997 \size footnotesize 
21998 ; function function
21999 \layout Standard
22000
22001
22002 \size footnotesize 
22003 ; ----------------------------------------------
22004 \layout Standard
22005
22006
22007 \size footnotesize 
22008 _function:
22009 \layout Standard
22010
22011
22012 \size footnotesize 
22013 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
22014 \layout Standard
22015
22016
22017 \size footnotesize 
22018 \SpecialChar ~
22019 \SpecialChar ~
22020 mov r2,dpl
22021 \layout Standard
22022
22023
22024 \size footnotesize 
22025 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
22026 \layout Standard
22027
22028
22029 \size footnotesize 
22030 \SpecialChar ~
22031 \SpecialChar ~
22032 mov ar0,r2
22033 \layout Standard
22034
22035
22036 \size footnotesize 
22037 ;_whilecontinue_0($1) :
22038 \layout Standard
22039
22040
22041 \size footnotesize 
22042 00101$:
22043 \layout Standard
22044
22045
22046 \size footnotesize 
22047 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
22048 \layout Standard
22049
22050
22051 \size footnotesize 
22052 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
22053 \layout Standard
22054
22055
22056 \size footnotesize 
22057 \SpecialChar ~
22058 \SpecialChar ~
22059 mov ar2,@r0
22060 \layout Standard
22061
22062
22063 \size footnotesize 
22064 \SpecialChar ~
22065 \SpecialChar ~
22066 inc r0
22067 \layout Standard
22068
22069
22070 \size footnotesize 
22071 \SpecialChar ~
22072 \SpecialChar ~
22073 mov ar3,@r0
22074 \layout Standard
22075
22076
22077 \size footnotesize 
22078 \SpecialChar ~
22079 \SpecialChar ~
22080 dec r0
22081 \layout Standard
22082
22083
22084 \size footnotesize 
22085 \SpecialChar ~
22086 \SpecialChar ~
22087 mov a,r2
22088 \layout Standard
22089
22090
22091 \size footnotesize 
22092 \SpecialChar ~
22093 \SpecialChar ~
22094 orl a,r3
22095 \layout Standard
22096
22097
22098 \size footnotesize 
22099 \SpecialChar ~
22100 \SpecialChar ~
22101 jz 00103$
22102 \layout Standard
22103
22104
22105 \size footnotesize 
22106 00114$:
22107 \layout Standard
22108
22109
22110 \size footnotesize 
22111 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
22112 \layout Standard
22113
22114
22115 \size footnotesize 
22116 \SpecialChar ~
22117 \SpecialChar ~
22118 mov dpl,_p
22119 \layout Standard
22120
22121
22122 \size footnotesize 
22123 \SpecialChar ~
22124 \SpecialChar ~
22125 mov dph,(_p + 1)
22126 \layout Standard
22127
22128
22129 \size footnotesize 
22130 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
22131 \layout Standard
22132
22133
22134 \size footnotesize 
22135 \SpecialChar ~
22136 \SpecialChar ~
22137 mov a,#0x02
22138 \layout Standard
22139
22140
22141 \size footnotesize 
22142 \SpecialChar ~
22143 \SpecialChar ~
22144 add a,_p
22145 \layout Standard
22146
22147
22148 \size footnotesize 
22149 \SpecialChar ~
22150 \SpecialChar ~
22151 mov _p,a
22152 \layout Standard
22153
22154
22155 \size footnotesize 
22156 \SpecialChar ~
22157 \SpecialChar ~
22158 clr a
22159 \layout Standard
22160
22161
22162 \size footnotesize 
22163 \SpecialChar ~
22164 \SpecialChar ~
22165 addc a,(_p + 1)
22166 \layout Standard
22167
22168
22169 \size footnotesize 
22170 \SpecialChar ~
22171 \SpecialChar ~
22172 mov (_p + 1),a
22173 \layout Standard
22174
22175
22176 \size footnotesize 
22177 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
22178 \layout Standard
22179
22180
22181 \size footnotesize 
22182 \SpecialChar ~
22183 \SpecialChar ~
22184 movx a,@dptr
22185 \layout Standard
22186
22187
22188 \size footnotesize 
22189 \SpecialChar ~
22190 \SpecialChar ~
22191 mov r2,a
22192 \layout Standard
22193
22194
22195 \size footnotesize 
22196 \SpecialChar ~
22197 \SpecialChar ~
22198 inc dptr
22199 \layout Standard
22200
22201
22202 \size footnotesize 
22203 \SpecialChar ~
22204 \SpecialChar ~
22205 movx a,@dptr
22206 \layout Standard
22207
22208
22209 \size footnotesize 
22210 \SpecialChar ~
22211 \SpecialChar ~
22212 mov r3,a
22213 \layout Standard
22214
22215
22216 \size footnotesize 
22217 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
22218 \layout Standard
22219
22220
22221 \size footnotesize 
22222 \SpecialChar ~
22223 \SpecialChar ~
22224 mov @r0,ar2
22225 \layout Standard
22226
22227
22228 \size footnotesize 
22229 \SpecialChar ~
22230 \SpecialChar ~
22231 inc r0
22232 \layout Standard
22233
22234
22235 \size footnotesize 
22236 \SpecialChar ~
22237 \SpecialChar ~
22238 mov @r0,ar3
22239 \layout Standard
22240
22241
22242 \size footnotesize 
22243 ; iTemp6 [lr5:16]{_near * int}[r0] = 
22244 \layout Standard
22245
22246
22247 \size footnotesize 
22248 ; iTemp6 [lr5:16]{_near * int}[r0] + 
22249 \layout Standard
22250
22251
22252 \size footnotesize 
22253 ; 0x2 {short}
22254 \layout Standard
22255
22256
22257 \size footnotesize 
22258 \SpecialChar ~
22259 \SpecialChar ~
22260 inc r0
22261 \layout Standard
22262
22263
22264 \size footnotesize 
22265 ; goto _whilecontinue_0($1)
22266 \layout Standard
22267
22268
22269 \size footnotesize 
22270 \SpecialChar ~
22271 \SpecialChar ~
22272 sjmp 00101$
22273 \layout Standard
22274
22275
22276 \size footnotesize 
22277 ; _whilebreak_0($3) :
22278 \layout Standard
22279
22280
22281 \size footnotesize 
22282 00103$:
22283 \layout Standard
22284
22285
22286 \size footnotesize 
22287 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
22288 \layout Standard
22289
22290
22291 \size footnotesize 
22292 \SpecialChar ~
22293 \SpecialChar ~
22294 mov r2,#0x00
22295 \layout Standard
22296
22297
22298 \size footnotesize 
22299 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
22300 \layout Standard
22301
22302
22303 \size footnotesize 
22304 \SpecialChar ~
22305 \SpecialChar ~
22306 mov r3,#0x00
22307 \layout Standard
22308
22309
22310 \size footnotesize 
22311 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
22312 \layout Standard
22313
22314
22315 \size footnotesize 
22316 \SpecialChar ~
22317 \SpecialChar ~
22318 mov r4,#0x00
22319 \layout Standard
22320
22321
22322 \size footnotesize 
22323 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
22324 \layout Standard
22325
22326
22327 \size footnotesize 
22328 \SpecialChar ~
22329 \SpecialChar ~
22330 mov r5,#0x0A
22331 \layout Standard
22332
22333
22334 \size footnotesize 
22335 \SpecialChar ~
22336 \SpecialChar ~
22337 mov r6,#0x00
22338 \layout Standard
22339
22340
22341 \size footnotesize 
22342 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
22343 \layout Standard
22344
22345
22346 \size footnotesize 
22347 \SpecialChar ~
22348 \SpecialChar ~
22349 mov r7,#0x1E
22350 \layout Standard
22351
22352
22353 \size footnotesize 
22354 \SpecialChar ~
22355 \SpecialChar ~
22356 mov r0,#0x00
22357 \layout Standard
22358
22359
22360 \size footnotesize 
22361 ; _forcond_0($4) :
22362 \layout Standard
22363
22364
22365 \size footnotesize 
22366 00104$:
22367 \layout Standard
22368
22369
22370 \size footnotesize 
22371 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
22372 \layout Standard
22373
22374
22375 \size footnotesize 
22376 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
22377 \layout Standard
22378
22379
22380 \size footnotesize 
22381 \SpecialChar ~
22382 \SpecialChar ~
22383 clr c
22384 \layout Standard
22385
22386
22387 \size footnotesize 
22388 \SpecialChar ~
22389 \SpecialChar ~
22390 mov a,r4
22391 \layout Standard
22392
22393
22394 \size footnotesize 
22395 \SpecialChar ~
22396 \SpecialChar ~
22397 xrl a,#0x80
22398 \layout Standard
22399
22400
22401 \size footnotesize 
22402 \SpecialChar ~
22403 \SpecialChar ~
22404 subb a,#0x8a
22405 \layout Standard
22406
22407
22408 \size footnotesize 
22409 \SpecialChar ~
22410 \SpecialChar ~
22411 jnc 00107$
22412 \layout Standard
22413
22414
22415 \size footnotesize 
22416 00115$:
22417 \layout Standard
22418
22419
22420 \size footnotesize 
22421 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
22422 \layout Standard
22423
22424
22425 \size footnotesize 
22426 ; iTemp21 [lr21:38]{short}[r4]
22427 \layout Standard
22428
22429
22430 \size footnotesize 
22431 \SpecialChar ~
22432 \SpecialChar ~
22433 mov a,r4
22434 \layout Standard
22435
22436
22437 \size footnotesize 
22438 \SpecialChar ~
22439 \SpecialChar ~
22440 add a,r2
22441 \layout Standard
22442
22443
22444 \size footnotesize 
22445 \SpecialChar ~
22446 \SpecialChar ~
22447 mov r2,a
22448 \layout Standard
22449
22450
22451 \size footnotesize 
22452 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
22453 \layout Standard
22454
22455
22456 \size footnotesize 
22457 \SpecialChar ~
22458 \SpecialChar ~
22459 mov b,#0x03
22460 \layout Standard
22461
22462
22463 \size footnotesize 
22464 \SpecialChar ~
22465 \SpecialChar ~
22466 mov a,r4
22467 \layout Standard
22468
22469
22470 \size footnotesize 
22471 \SpecialChar ~
22472 \SpecialChar ~
22473 mul ab
22474 \layout Standard
22475
22476
22477 \size footnotesize 
22478 \SpecialChar ~
22479 \SpecialChar ~
22480 mov r1,a
22481 \layout Standard
22482
22483
22484 \size footnotesize 
22485 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
22486 \layout Standard
22487
22488
22489 \size footnotesize 
22490 ; iTemp15 [lr29:30]{short}[r1]
22491 \layout Standard
22492
22493
22494 \size footnotesize 
22495 \SpecialChar ~
22496 \SpecialChar ~
22497 add a,r3
22498 \layout Standard
22499
22500
22501 \size footnotesize 
22502 \SpecialChar ~
22503 \SpecialChar ~
22504 mov r3,a
22505 \layout Standard
22506
22507
22508 \size footnotesize 
22509 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
22510 \layout Standard
22511
22512
22513 \size footnotesize 
22514 \SpecialChar ~
22515 \SpecialChar ~
22516 mov a,r7
22517 \layout Standard
22518
22519
22520 \size footnotesize 
22521 \SpecialChar ~
22522 \SpecialChar ~
22523 add a,#0xfd
22524 \layout Standard
22525
22526
22527 \size footnotesize 
22528 \SpecialChar ~
22529 \SpecialChar ~
22530 mov r7,a
22531 \layout Standard
22532
22533
22534 \size footnotesize 
22535 \SpecialChar ~
22536 \SpecialChar ~
22537 mov a,r0
22538 \layout Standard
22539
22540
22541 \size footnotesize 
22542 \SpecialChar ~
22543 \SpecialChar ~
22544 addc a,#0xff
22545 \layout Standard
22546
22547
22548 \size footnotesize 
22549 \SpecialChar ~
22550 \SpecialChar ~
22551 mov r0,a
22552 \layout Standard
22553
22554
22555 \size footnotesize 
22556 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
22557 \layout Standard
22558
22559
22560 \size footnotesize 
22561 \SpecialChar ~
22562 \SpecialChar ~
22563 mov a,r7
22564 \layout Standard
22565
22566
22567 \size footnotesize 
22568 \SpecialChar ~
22569 \SpecialChar ~
22570 add a,_gint
22571 \layout Standard
22572
22573
22574 \size footnotesize 
22575 \SpecialChar ~
22576 \SpecialChar ~
22577 mov _gint,a
22578 \layout Standard
22579
22580
22581 \size footnotesize 
22582 \SpecialChar ~
22583 \SpecialChar ~
22584 mov a,r0
22585 \layout Standard
22586
22587
22588 \size footnotesize 
22589 \SpecialChar ~
22590 \SpecialChar ~
22591 addc a,(_gint + 1)
22592 \layout Standard
22593
22594
22595 \size footnotesize 
22596 \SpecialChar ~
22597 \SpecialChar ~
22598 mov (_gint + 1),a
22599 \layout Standard
22600
22601
22602 \size footnotesize 
22603 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
22604 \layout Standard
22605
22606
22607 \size footnotesize 
22608 \SpecialChar ~
22609 \SpecialChar ~
22610 inc r4
22611 \layout Standard
22612
22613
22614 \size footnotesize 
22615 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
22616 \layout Standard
22617
22618
22619 \size footnotesize 
22620 \SpecialChar ~
22621 \SpecialChar ~
22622 dec r5
22623 \layout Standard
22624
22625
22626 \size footnotesize 
22627 \SpecialChar ~
22628 \SpecialChar ~
22629 cjne r5,#0xff,00104$
22630 \layout Standard
22631
22632
22633 \size footnotesize 
22634 \SpecialChar ~
22635 \SpecialChar ~
22636 dec r6
22637 \layout Standard
22638
22639
22640 \size footnotesize 
22641 ; goto _forcond_0($4)
22642 \layout Standard
22643
22644
22645 \size footnotesize 
22646 \SpecialChar ~
22647 \SpecialChar ~
22648 sjmp 00104$
22649 \layout Standard
22650
22651
22652 \size footnotesize 
22653 ; _forbreak_0($7) :
22654 \layout Standard
22655
22656
22657 \size footnotesize 
22658 00107$:
22659 \layout Standard
22660
22661
22662 \size footnotesize 
22663 ; ret iTemp24 [lr40:41]{short}
22664 \layout Standard
22665
22666
22667 \size footnotesize 
22668 \SpecialChar ~
22669 \SpecialChar ~
22670 mov a,r3
22671 \layout Standard
22672
22673
22674 \size footnotesize 
22675 \SpecialChar ~
22676 \SpecialChar ~
22677 add a,r2
22678 \layout Standard
22679
22680
22681 \size footnotesize 
22682 \SpecialChar ~
22683 \SpecialChar ~
22684 mov dpl,a
22685 \layout Standard
22686
22687
22688 \size footnotesize 
22689 ; _return($8) :
22690 \layout Standard
22691
22692
22693 \size footnotesize 
22694 00108$:
22695 \layout Standard
22696
22697
22698 \size footnotesize 
22699 \SpecialChar ~
22700 \SpecialChar ~
22701 ret
22702 \newline 
22703
22704 \layout Section
22705
22706 A few words about basic block successors, predecessors and dominators
22707 \layout Standard
22708
22709 Successors are basic blocks
22710 \begin_inset LatexCommand \index{Basic blocks}
22711
22712 \end_inset 
22713
22714  that might execute after this basic block.
22715 \newline 
22716 Predecessors are basic blocks that might execute before reaching this basic
22717  block.
22718 \newline 
22719 Dominators are basic blocks that WILL execute before reaching this basic
22720  block.
22721 \newline 
22722
22723 \layout Standard
22724
22725 [basic block 1]
22726 \layout Standard
22727
22728 if (something)
22729 \layout Standard
22730
22731 \SpecialChar ~
22732 \SpecialChar ~
22733 \SpecialChar ~
22734 \SpecialChar ~
22735 [basic block 2]
22736 \layout Standard
22737
22738 else
22739 \layout Standard
22740
22741 \SpecialChar ~
22742 \SpecialChar ~
22743 \SpecialChar ~
22744 \SpecialChar ~
22745 [basic block 3]
22746 \layout Standard
22747
22748 [basic block 4]
22749 \newline 
22750
22751 \layout Standard
22752
22753 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
22754 \layout Standard
22755
22756 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
22757 \layout Standard
22758
22759 c) domVect of [BB4] = BB1 ...
22760  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
22761  was executed.
22762 \layout Chapter
22763
22764 Acknowledgments
22765 \layout Standard
22766
22767
22768 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
22769
22770 \end_inset 
22771
22772
22773 \newline 
22774
22775 \newline 
22776
22777 \emph on 
22778 Thanks to all the other volunteer developers who have helped with coding,
22779  testing, web-page creation, distribution sets, etc.
22780  You know who you are :-)
22781 \emph default 
22782
22783 \newline 
22784
22785 \layout Standard
22786
22787 This document was initially written by Sandeep Dutta
22788 \layout Standard
22789
22790 All product names mentioned herein may be trademarks
22791 \begin_inset LatexCommand \index{Trademarks}
22792
22793 \end_inset 
22794
22795  of their respective companies.
22796  
22797 \layout Section*
22798
22799 Alphabetical index
22800 \layout Standard
22801
22802 To avoid confusion, the installation and building options for SDCC itself
22803  (chapter 2) are not part of the index.
22804 \layout Standard
22805
22806
22807 \begin_inset LatexCommand \printindex{}
22808
22809 \end_inset 
22810
22811
22812 \the_end