75d1494ef8bb49deac8011ad008494bc1f4b2cd2
[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 Section
10344
10345 Enabling and Disabling Interrupts
10346 \layout Subsection
10347
10348 Critical Functions and Critical Statements
10349 \layout Standard
10350
10351 A special keyword may be associated with a block or a function declaring
10352  it as 
10353 \emph on 
10354 critical
10355 \emph default 
10356 .
10357  SDCC will generate code to disable all interrupts
10358 \begin_inset LatexCommand \index{interrupt}
10359
10360 \end_inset 
10361
10362  upon entry to a critical function and restore the interrupt enable to the
10363  previous state before returning.
10364  Nesting critical functions will need one additional byte on the stack
10365 \begin_inset LatexCommand \index{stack}
10366
10367 \end_inset 
10368
10369  for each call.
10370 \layout Verse
10371
10372
10373 \family typewriter 
10374 int foo () critical
10375 \begin_inset LatexCommand \index{critical}
10376
10377 \end_inset 
10378
10379  
10380 \newline 
10381
10382 \newline 
10383 \SpecialChar ~
10384 \SpecialChar ~
10385 \SpecialChar ~
10386 \SpecialChar ~
10387 ...
10388  
10389 \newline 
10390 \SpecialChar ~
10391 \SpecialChar ~
10392 \SpecialChar ~
10393 \SpecialChar ~
10394 ...
10395  
10396 \newline 
10397 }
10398 \layout Standard
10399
10400 The critical attribute maybe used with other attributes like 
10401 \emph on 
10402 reentrant.
10403 \emph default 
10404
10405 \newline 
10406 The keyword 
10407 \emph on 
10408 critical
10409 \emph default 
10410  may also be used to disable interrupts more locally:
10411 \layout Verse
10412
10413
10414 \family typewriter 
10415 critical{ i++; }
10416 \layout Standard
10417
10418 More than one statement could have been included in the block.
10419 \layout Subsection
10420
10421 Enabling and Disabling Interrupts directly
10422 \layout Standard
10423
10424 Interrupts
10425 \begin_inset LatexCommand \index{interrupt}
10426
10427 \end_inset 
10428
10429  can also be disabled and enabled directly (8051):
10430 \layout Verse
10431
10432
10433 \family typewriter 
10434 EA = 0;\SpecialChar ~
10435 \SpecialChar ~
10436 \SpecialChar ~
10437 \SpecialChar ~
10438 \SpecialChar ~
10439 \SpecialChar ~
10440 \SpecialChar ~
10441 \SpecialChar ~
10442 \SpecialChar ~
10443 \SpecialChar ~
10444 \SpecialChar ~
10445 \SpecialChar ~
10446 or:\SpecialChar ~
10447 \SpecialChar ~
10448 \SpecialChar ~
10449 \SpecialChar ~
10450 \SpecialChar ~
10451 \SpecialChar ~
10452 \SpecialChar ~
10453 \SpecialChar ~
10454 \SpecialChar ~
10455 \SpecialChar ~
10456 \SpecialChar ~
10457 EA_SAVE = EA;
10458 \layout Verse
10459
10460
10461 \family typewriter 
10462 ...\SpecialChar ~
10463 \SpecialChar ~
10464 \SpecialChar ~
10465 \SpecialChar ~
10466 \SpecialChar ~
10467 \SpecialChar ~
10468 \SpecialChar ~
10469 \SpecialChar ~
10470 \SpecialChar ~
10471 \SpecialChar ~
10472 \SpecialChar ~
10473 \SpecialChar ~
10474 \SpecialChar ~
10475 \SpecialChar ~
10476 \SpecialChar ~
10477 \SpecialChar ~
10478 \SpecialChar ~
10479 \SpecialChar ~
10480 \SpecialChar ~
10481 \SpecialChar ~
10482 \SpecialChar ~
10483 \SpecialChar ~
10484 \SpecialChar ~
10485 \SpecialChar ~
10486 \SpecialChar ~
10487 \SpecialChar ~
10488 \SpecialChar ~
10489 \SpecialChar ~
10490 \SpecialChar ~
10491 \SpecialChar ~
10492 EA = 0;
10493 \layout Verse
10494
10495
10496 \family typewriter 
10497 EA = 1;\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 ...
10524 \layout Verse
10525
10526
10527 \family typewriter 
10528 \SpecialChar ~
10529 \SpecialChar ~
10530 \SpecialChar ~
10531 \SpecialChar ~
10532 \SpecialChar ~
10533 \SpecialChar ~
10534 \SpecialChar ~
10535 \SpecialChar ~
10536 \SpecialChar ~
10537 \SpecialChar ~
10538 \SpecialChar ~
10539 \SpecialChar ~
10540 \SpecialChar ~
10541 \SpecialChar ~
10542 \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 \SpecialChar ~
10559 \SpecialChar ~
10560 \SpecialChar ~
10561 EA = EA_SAVE;
10562 \layout Standard
10563
10564 On other architectures which have seperate opcodes for enabling and disabling
10565  interrupts you might want to make use of defines with inline assembly
10566 \begin_inset LatexCommand \index{Assembler routines}
10567
10568 \end_inset 
10569
10570  (HC08):
10571 \layout Verse
10572
10573
10574 \family typewriter 
10575 #define CLI _asm
10576 \begin_inset LatexCommand \index{\_asm}
10577
10578 \end_inset 
10579
10580 \SpecialChar ~
10581 \SpecialChar ~
10582 cli\SpecialChar ~
10583 \SpecialChar ~
10584 _endasm
10585 \begin_inset LatexCommand \index{\_endasm}
10586
10587 \end_inset 
10588
10589
10590 \layout Verse
10591
10592
10593 \family typewriter 
10594 #define SEI _asm\SpecialChar ~
10595 \SpecialChar ~
10596 sei\SpecialChar ~
10597 \SpecialChar ~
10598 _endasm; 
10599 \layout Verse
10600
10601
10602 \family typewriter 
10603 ...
10604 \layout Standard
10605
10606 Note: it is sometimes sufficient to disable only a specific interrupt source
10607  like f.e.
10608  a timer or serial interrupt by manipulating an 
10609 \emph on 
10610 interrupt mask
10611 \begin_inset LatexCommand \index{interrupt mask}
10612
10613 \end_inset 
10614
10615
10616 \emph default 
10617  register.
10618  
10619 \layout Standard
10620
10621 Usually the time during which interrupts are disabled should be kept as
10622  short as possible.
10623  This minimizes both 
10624 \emph on 
10625 interrupt latency
10626 \emph default 
10627
10628 \begin_inset LatexCommand \index{interrupt latency}
10629
10630 \end_inset 
10631
10632  (the time between the occurrence of the interrupt and the execution of
10633  the first code in the interrupt routine) and 
10634 \emph on 
10635 interrupt jitter
10636 \emph default 
10637
10638 \begin_inset LatexCommand \index{interrupt jitter}
10639
10640 \end_inset 
10641
10642  (the difference between the shortest and the longest interrupt latency).
10643  These really are something different, f.e.
10644  a serial interrupt has to be served before its buffer overruns so it cares
10645  for the maximum interrupt latency, whereas it does not care about jitter.
10646  On a loudspeaker driven via a digital to analog converter which is fed
10647  by an interrupt a latency of a few milliseconds might be tolerable, whereas
10648  a much smaller jitter will be very audible.
10649 \layout Standard
10650
10651 You can reenable interrupts within an interrupt routine and on some architecture
10652 s you can make use of two (or more) levels of 
10653 \emph on 
10654 interrupt priorities
10655 \emph default 
10656
10657 \begin_inset LatexCommand \index{interrupt priority}
10658
10659 \end_inset 
10660
10661 .
10662  On some architectures which don't support interrupt priorities these can
10663  be implemented by manipulating the interrupt mask and reenabling interrupts
10664  within the interrupt routine.
10665  Check there is sufficient space on the stack
10666 \begin_inset LatexCommand \index{stack}
10667
10668 \end_inset 
10669
10670  and don't add complexity unless you have to.
10671  
10672 \layout Section
10673
10674 Functions using private register banks
10675 \begin_inset LatexCommand \label{sub:Functions-using-private-banks}
10676
10677 \end_inset 
10678
10679  (mcs51/ds390)
10680 \layout Standard
10681
10682 Some architectures have support for quickly changing register sets.
10683  SDCC supports this feature with the 
10684 \emph on 
10685 using
10686 \begin_inset LatexCommand \index{using (mcs51, ds390 register bank)}
10687
10688 \end_inset 
10689
10690
10691 \emph default 
10692  attribute (which tells the compiler to use a register bank
10693 \begin_inset LatexCommand \index{register bank (mcs51, ds390)}
10694
10695 \end_inset 
10696
10697  other than the default bank zero).
10698  It should only be applied to 
10699 \emph on 
10700 interrupt
10701 \begin_inset LatexCommand \index{interrupt}
10702
10703 \end_inset 
10704
10705
10706 \emph default 
10707  functions (see footnote below).
10708  This will in most circumstances make the generated ISR code more efficient
10709  since it will not have to save registers on the stack.
10710 \layout Standard
10711
10712 The 
10713 \emph on 
10714 using
10715 \emph default 
10716  attribute will have no effect on the generated code for a 
10717 \emph on 
10718 non-interrupt
10719 \emph default 
10720  function (but may occasionally be useful anyway
10721 \begin_inset Foot
10722 collapsed false
10723
10724 \layout Standard
10725
10726 possible exception: if a function is called ONLY from 'interrupt' functions
10727  using a particular bank, it can be declared with the same 'using' attribute
10728  as the calling 'interrupt' functions.
10729  For instance, if you have several ISRs using bank one, and all of them
10730  call memcpy(), it might make sense to create a specialized version of memcpy()
10731  'using 1', since this would prevent the ISR from having to save bank zero
10732  to the stack on entry and switch to bank zero before calling the function
10733 \end_inset 
10734
10735 ).
10736 \newline 
10737
10738 \emph on 
10739 (pending: I don't think this has been done yet)
10740 \layout Standard
10741
10742 An 
10743 \emph on 
10744 interrupt
10745 \emph default 
10746  function using a non-zero bank will assume that it can trash that register
10747  bank, and will not save it.
10748  Since high-priority interrupts
10749 \begin_inset LatexCommand \index{interrupt priority}
10750
10751 \end_inset 
10752
10753  can interrupt low-priority ones on the 8051 and friends, this means that
10754  if a high-priority ISR 
10755 \emph on 
10756 using
10757 \emph default 
10758  a particular bank occurs while processing a low-priority ISR 
10759 \emph on 
10760 using
10761 \emph default 
10762  the same bank, terrible and bad things can happen.
10763  To prevent this, no single register bank should be 
10764 \emph on 
10765 used
10766 \emph default 
10767  by both a high priority and a low priority ISR.
10768  This is probably most easily done by having all high priority ISRs use
10769  one bank and all low priority ISRs use another.
10770  If you have an ISR which can change priority at runtime, you're on your
10771  own: I suggest using the default bank zero and taking the small performance
10772  hit.
10773 \layout Standard
10774
10775 It is most efficient if your ISR calls no other functions.
10776  If your ISR must call other functions, it is most efficient if those functions
10777  use the same bank as the ISR (see note 1 below); the next best is if the
10778  called functions use bank zero.
10779  It is very inefficient to call a function using a different, non-zero bank
10780  from an ISR.
10781  
10782 \layout Section
10783
10784 Startup Code
10785 \begin_inset LatexCommand \label{sub:Startup-Code}
10786
10787 \end_inset 
10788
10789
10790 \begin_inset LatexCommand \index{Startup code}
10791
10792 \end_inset 
10793
10794
10795 \layout Subsection
10796
10797 MCS51/DS390 Startup Code
10798 \layout Standard
10799
10800 The compiler inserts a call to the C routine 
10801 \emph on 
10802 _sdcc_external_startup()
10803 \begin_inset LatexCommand \index{\_sdcc\_external\_startup()}
10804
10805 \end_inset 
10806
10807
10808 \series bold 
10809 \emph default 
10810  
10811 \series default 
10812 at the start of the CODE area.
10813  This routine is in the runtime library
10814 \begin_inset LatexCommand \index{Runtime library}
10815
10816 \end_inset 
10817
10818 .
10819  By default this routine returns 0, if this routine returns a non-zero value,
10820  the static & global variable initialization will be skipped and the function
10821  main will be invoked.
10822  Otherwise static & global variables will be initialized before the function
10823  main is invoked.
10824  You could add a 
10825 \emph on 
10826 _sdcc_external_startup()
10827 \emph default 
10828  routine to your program to override the default if you need to setup hardware
10829  or perform some other critical operation prior to static & global variable
10830  initialization.
10831  On some mcs51 variants xdata has to be explicitly enabled before it can
10832  be accessed, this is the place to do it.
10833  The startup code clears the complete 256 byte of idata memory, this might
10834  cause problems for 128 byte devices (endless loop reported for Chipcon
10835  CC1010).
10836 \layout Standard
10837
10838 See also the compiler option 
10839 \emph on 
10840 -
10841 \begin_inset ERT
10842 status Collapsed
10843
10844 \layout Standard
10845
10846 \backslash 
10847 /
10848 \end_inset 
10849
10850 -no-xinit
10851 \emph default 
10852 -
10853 \emph on 
10854 opt
10855 \emph default 
10856
10857 \begin_inset LatexCommand \index{-\/-no-xinit-opt}
10858
10859 \end_inset 
10860
10861  and section 
10862 \begin_inset LatexCommand \ref{sub:MCS51-variants}
10863
10864 \end_inset 
10865
10866 \SpecialChar ~
10867 about MCS51-variants.
10868 \layout Subsection
10869
10870 HC08 Startup Code
10871 \layout Standard
10872
10873 The HC08 startup code follows the same scheme as the MCS51 startup code.
10874 \layout Subsection
10875
10876 Z80 Startup Code
10877 \layout Standard
10878
10879 On the Z80 the startup code is inserted by linking with crt0.o which is generated
10880  from sdcc/device/lib/z80/crt0.s.
10881  If you need a different startup code you can use the compiler option 
10882 \emph on 
10883 -
10884 \series bold 
10885 \emph default 
10886
10887 \begin_inset ERT
10888 status Collapsed
10889
10890 \layout Standard
10891
10892 \backslash 
10893 /
10894 \end_inset 
10895
10896
10897 \series default 
10898 \emph on 
10899 -no-std-crt0
10900 \emph default 
10901
10902 \begin_inset LatexCommand \index{-\/-no-std-crt0}
10903
10904 \end_inset 
10905
10906  and provide your own crt0.o.
10907  
10908 \layout Section
10909
10910 Inline Assembler Code
10911 \begin_inset LatexCommand \index{Assembler routines}
10912
10913 \end_inset 
10914
10915
10916 \layout Subsection
10917
10918 A Step by Step Introduction
10919 \begin_inset LatexCommand \label{sub:A-Step-by Assembler Introduction}
10920
10921 \end_inset 
10922
10923
10924 \layout Standard
10925
10926 Starting from a small snippet of c-code this example shows for the MCS51
10927  how to use inline assembly, access variables, a function parameter and
10928  an array in xdata memory.
10929  The example uses an MCS51 here but is easily adapted for other architectures.
10930  This is a buffer routine which should be optimized:
10931 \layout Verse
10932
10933
10934 \family typewriter 
10935 \size footnotesize 
10936 unsigned char far
10937 \begin_inset LatexCommand \index{far (storage class)}
10938
10939 \end_inset 
10940
10941  at
10942 \begin_inset LatexCommand \index{at}
10943
10944 \end_inset 
10945
10946  0x7f00 buf[0x100];
10947 \begin_inset LatexCommand \index{Aligned array}
10948
10949 \end_inset 
10950
10951
10952 \newline 
10953 unsigned char head,tail;
10954 \newline 
10955
10956 \newline 
10957 void to_buffer( unsigned char c ) 
10958 \newline 
10959 {
10960 \newline 
10961 \SpecialChar ~
10962 \SpecialChar ~
10963 \SpecialChar ~
10964 \SpecialChar ~
10965 if( head != tail-1 ) 
10966 \newline 
10967 \SpecialChar ~
10968 \SpecialChar ~
10969 \SpecialChar ~
10970 \SpecialChar ~
10971 \SpecialChar ~
10972 \SpecialChar ~
10973 \SpecialChar ~
10974 \SpecialChar ~
10975 buf[ head++ ] = c;\SpecialChar ~
10976 \SpecialChar ~
10977 \SpecialChar ~
10978 \SpecialChar ~
10979 /* access to a 256 byte aligned array */
10980 \newline 
10981
10982 \layout Standard
10983
10984 If the code snippet (assume it is saved in buffer.c) is compiled with SDCC
10985  then a corresponding buffer.asm file is generated.
10986  We define a new function 
10987 \family typewriter 
10988 to_buffer_asm()
10989 \family default 
10990  in file buffer.c in which we cut and paste the generated code, removing
10991  unwanted comments and some ':'.
10992  Then add 
10993 \begin_inset Quotes sld
10994 \end_inset 
10995
10996 _asm
10997 \begin_inset Quotes srd
10998 \end_inset 
10999
11000  and 
11001 \begin_inset Quotes sld
11002 \end_inset 
11003
11004 _endasm;
11005 \begin_inset Quotes srd
11006 \end_inset 
11007
11008  to the beginning and the end of the function body:
11009 \layout Verse
11010
11011
11012 \family typewriter 
11013 \size footnotesize 
11014 /* With a cut and paste from the .asm file, we have something to start with.
11015 \newline 
11016 \SpecialChar ~
11017 \SpecialChar ~
11018 \SpecialChar ~
11019 The function is not yet OK! (registers aren't saved) */ 
11020 \newline 
11021 void to_buffer_asm( unsigned char c ) 
11022 \newline 
11023
11024 \newline 
11025 \SpecialChar ~
11026 \SpecialChar ~
11027 \SpecialChar ~
11028 \SpecialChar ~
11029 _asm
11030 \begin_inset LatexCommand \index{\_asm}
11031
11032 \end_inset 
11033
11034
11035 \newline 
11036 \SpecialChar ~
11037 \SpecialChar ~
11038 \SpecialChar ~
11039 \SpecialChar ~
11040 mov\SpecialChar ~
11041 \SpecialChar ~
11042 r2,dpl 
11043 \newline 
11044 ;buffer.c if( head != tail-1 ) 
11045 \newline 
11046 \SpecialChar ~
11047 \SpecialChar ~
11048 \SpecialChar ~
11049 \SpecialChar ~
11050 mov\SpecialChar ~
11051 \SpecialChar ~
11052 a,_tail 
11053 \newline 
11054 \SpecialChar ~
11055 \SpecialChar ~
11056 \SpecialChar ~
11057 \SpecialChar ~
11058 dec\SpecialChar ~
11059 \SpecialChar ~
11060
11061 \newline 
11062 \SpecialChar ~
11063 \SpecialChar ~
11064 \SpecialChar ~
11065 \SpecialChar ~
11066 mov\SpecialChar ~
11067 \SpecialChar ~
11068 r3,a 
11069 \newline 
11070 \SpecialChar ~
11071 \SpecialChar ~
11072 \SpecialChar ~
11073 \SpecialChar ~
11074 mov\SpecialChar ~
11075 \SpecialChar ~
11076 a,_head 
11077 \newline 
11078 \SpecialChar ~
11079 \SpecialChar ~
11080 \SpecialChar ~
11081 \SpecialChar ~
11082 cjne a,ar3,00106$ 
11083 \newline 
11084 \SpecialChar ~
11085 \SpecialChar ~
11086 \SpecialChar ~
11087 \SpecialChar ~
11088 ret
11089 \newline 
11090 00106$: 
11091 \newline 
11092 ;buffer.c buf[ head++ ] = c; /* access to a 256 byte aligned array */
11093 \begin_inset LatexCommand \index{Aligned array}
11094
11095 \end_inset 
11096
11097
11098 \newline 
11099 \SpecialChar ~
11100 \SpecialChar ~
11101 \SpecialChar ~
11102 \SpecialChar ~
11103 mov\SpecialChar ~
11104 \SpecialChar ~
11105 r3,_head 
11106 \newline 
11107 \SpecialChar ~
11108 \SpecialChar ~
11109 \SpecialChar ~
11110 \SpecialChar ~
11111 inc\SpecialChar ~
11112 \SpecialChar ~
11113 _head 
11114 \newline 
11115 \SpecialChar ~
11116 \SpecialChar ~
11117 \SpecialChar ~
11118 \SpecialChar ~
11119 mov\SpecialChar ~
11120 \SpecialChar ~
11121 dpl,r3 
11122 \newline 
11123 \SpecialChar ~
11124 \SpecialChar ~
11125 \SpecialChar ~
11126 \SpecialChar ~
11127 mov\SpecialChar ~
11128 \SpecialChar ~
11129 dph,#(_buf >> 8) 
11130 \newline 
11131 \SpecialChar ~
11132 \SpecialChar ~
11133 \SpecialChar ~
11134 \SpecialChar ~
11135 mov\SpecialChar ~
11136 \SpecialChar ~
11137 a,r2 
11138 \newline 
11139 \SpecialChar ~
11140 \SpecialChar ~
11141 \SpecialChar ~
11142 \SpecialChar ~
11143 movx @dptr,a 
11144 \newline 
11145 00103$: 
11146 \newline 
11147 \SpecialChar ~
11148 \SpecialChar ~
11149 \SpecialChar ~
11150 \SpecialChar ~
11151 ret
11152 \newline 
11153 \SpecialChar ~
11154 \SpecialChar ~
11155 \SpecialChar ~
11156 \SpecialChar ~
11157 _endasm;
11158 \newline 
11159
11160 \layout Standard
11161
11162 The new file buffer.c should compile with only one warning about the unreferenced
11163  function argument 'c'.
11164  Now we hand-optimize the assembly code and insert an #define USE_ASSEMBLY
11165  (1) and finally have:
11166 \layout Verse
11167
11168
11169 \family typewriter 
11170 \size footnotesize 
11171 unsigned char far at 0x7f00 buf[0x100];
11172 \newline 
11173 unsigned char head,tail;
11174 \newline 
11175 #define USE_ASSEMBLY (1)
11176 \newline 
11177
11178 \newline 
11179 #if !USE_ASSEMBLY
11180 \newline 
11181
11182 \newline 
11183 void to_buffer( unsigned char c )
11184 \newline 
11185 {
11186 \newline 
11187 \SpecialChar ~
11188 \SpecialChar ~
11189 \SpecialChar ~
11190 \SpecialChar ~
11191 if( head != tail-1 )
11192 \newline 
11193 \SpecialChar ~
11194 \SpecialChar ~
11195 \SpecialChar ~
11196 \SpecialChar ~
11197 \SpecialChar ~
11198 \SpecialChar ~
11199 \SpecialChar ~
11200 \SpecialChar ~
11201 buf[ head++ ] = c;
11202 \newline 
11203 }
11204 \newline 
11205
11206 \newline 
11207 #else
11208 \newline 
11209
11210 \newline 
11211 void to_buffer( unsigned char c )
11212 \newline 
11213 {
11214 \newline 
11215 \SpecialChar ~
11216 \SpecialChar ~
11217 \SpecialChar ~
11218 \SpecialChar ~
11219 c; // to avoid warning: unreferenced function argument
11220 \newline 
11221 \SpecialChar ~
11222 \SpecialChar ~
11223 \SpecialChar ~
11224 \SpecialChar ~
11225 _asm
11226 \begin_inset LatexCommand \index{\_asm}
11227
11228 \end_inset 
11229
11230
11231 \newline 
11232 \SpecialChar ~
11233 \SpecialChar ~
11234 \SpecialChar ~
11235 \SpecialChar ~
11236 \SpecialChar ~
11237 \SpecialChar ~
11238 \SpecialChar ~
11239 \SpecialChar ~
11240 ; save used registers here.
11241  
11242 \newline 
11243 \SpecialChar ~
11244 \SpecialChar ~
11245 \SpecialChar ~
11246 \SpecialChar ~
11247 \SpecialChar ~
11248 \SpecialChar ~
11249 \SpecialChar ~
11250 \SpecialChar ~
11251 ; If we were still using r2,r3 we would have to push them here.
11252  
11253 \newline 
11254 ; if( head != tail-1 )
11255 \newline 
11256 \SpecialChar ~
11257 \SpecialChar ~
11258 \SpecialChar ~
11259 \SpecialChar ~
11260 \SpecialChar ~
11261 \SpecialChar ~
11262 \SpecialChar ~
11263 \SpecialChar ~
11264 mov\SpecialChar ~
11265  a,_tail
11266 \newline 
11267 \SpecialChar ~
11268 \SpecialChar ~
11269 \SpecialChar ~
11270 \SpecialChar ~
11271 \SpecialChar ~
11272 \SpecialChar ~
11273 \SpecialChar ~
11274 \SpecialChar ~
11275 dec\SpecialChar ~
11276  a
11277 \newline 
11278 \SpecialChar ~
11279 \SpecialChar ~
11280 \SpecialChar ~
11281 \SpecialChar ~
11282 \SpecialChar ~
11283 \SpecialChar ~
11284 \SpecialChar ~
11285 \SpecialChar ~
11286 xrl\SpecialChar ~
11287  a,_head
11288 \newline 
11289 \SpecialChar ~
11290 \SpecialChar ~
11291 \SpecialChar ~
11292 \SpecialChar ~
11293 \SpecialChar ~
11294 \SpecialChar ~
11295 \SpecialChar ~
11296 \SpecialChar ~
11297 ; we could do an ANL a,#0x0f here to use a smaller buffer (see below)
11298 \newline 
11299 \SpecialChar ~
11300 \SpecialChar ~
11301 \SpecialChar ~
11302 \SpecialChar ~
11303 \SpecialChar ~
11304 \SpecialChar ~
11305 \SpecialChar ~
11306 \SpecialChar ~
11307 jz\SpecialChar ~
11308 \SpecialChar ~
11309  t_b_end$
11310 \newline 
11311 \SpecialChar ~
11312 \SpecialChar ~
11313 \SpecialChar ~
11314 \SpecialChar ~
11315 \SpecialChar ~
11316 \SpecialChar ~
11317 \SpecialChar ~
11318 \SpecialChar ~
11319 ;
11320 \newline 
11321 ; buf[ head++ ] = c;
11322 \newline 
11323 \SpecialChar ~
11324 \SpecialChar ~
11325 \SpecialChar ~
11326 \SpecialChar ~
11327 \SpecialChar ~
11328 \SpecialChar ~
11329 \SpecialChar ~
11330 \SpecialChar ~
11331 mov\SpecialChar ~
11332  a,dpl \SpecialChar ~
11333 \SpecialChar ~
11334 \SpecialChar ~
11335 \SpecialChar ~
11336 \SpecialChar ~
11337 \SpecialChar ~
11338 \SpecialChar ~
11339 ; dpl holds lower byte of function argument
11340 \newline 
11341 \SpecialChar ~
11342 \SpecialChar ~
11343 \SpecialChar ~
11344 \SpecialChar ~
11345 \SpecialChar ~
11346 \SpecialChar ~
11347 \SpecialChar ~
11348 \SpecialChar ~
11349 mov\SpecialChar ~
11350  dpl,_head \SpecialChar ~
11351 \SpecialChar ~
11352 \SpecialChar ~
11353 ; buf is 0x100 byte aligned so head can be used directly
11354 \newline 
11355 \SpecialChar ~
11356 \SpecialChar ~
11357 \SpecialChar ~
11358 \SpecialChar ~
11359 \SpecialChar ~
11360 \SpecialChar ~
11361 \SpecialChar ~
11362 \SpecialChar ~
11363 mov\SpecialChar ~
11364  dph,#(_buf>>8)
11365 \newline 
11366 \SpecialChar ~
11367 \SpecialChar ~
11368 \SpecialChar ~
11369 \SpecialChar ~
11370 \SpecialChar ~
11371 \SpecialChar ~
11372 \SpecialChar ~
11373 \SpecialChar ~
11374 movx @dptr,a
11375 \newline 
11376 \SpecialChar ~
11377 \SpecialChar ~
11378 \SpecialChar ~
11379 \SpecialChar ~
11380 \SpecialChar ~
11381 \SpecialChar ~
11382 \SpecialChar ~
11383 \SpecialChar ~
11384 inc \SpecialChar ~
11385 _head
11386 \newline 
11387 \SpecialChar ~
11388 \SpecialChar ~
11389 \SpecialChar ~
11390 \SpecialChar ~
11391 \SpecialChar ~
11392 \SpecialChar ~
11393 \SpecialChar ~
11394 \SpecialChar ~
11395 ; we could do an ANL _head,#0x0f here to use a smaller buffer (see above)
11396 \newline 
11397 t_b_end$:
11398 \newline 
11399 \SpecialChar ~
11400 \SpecialChar ~
11401 \SpecialChar ~
11402 \SpecialChar ~
11403 \SpecialChar ~
11404 \SpecialChar ~
11405 \SpecialChar ~
11406 \SpecialChar ~
11407 ; restore used registers here 
11408 \newline 
11409 \SpecialChar ~
11410 \SpecialChar ~
11411 \SpecialChar ~
11412 \SpecialChar ~
11413 _endasm;
11414 \newline 
11415 }
11416 \newline 
11417 #endif
11418 \layout Standard
11419
11420 The inline assembler code can contain any valid code understood by the assembler
11421 , this includes any assembler directives and comment lines
11422 \begin_inset Foot
11423 collapsed false
11424
11425 \layout Standard
11426
11427 The assembler does not like some characters like ':' or ''' in comments.
11428  You'll find an 100+ pages assembler manual in sdcc/as/doc/asxhtm.html
11429 \end_inset 
11430
11431 .
11432  The compiler does not do any validation of the code within the 
11433 \family typewriter 
11434 _asm
11435 \begin_inset LatexCommand \index{\_asm}
11436
11437 \end_inset 
11438
11439  ...
11440  _endasm;
11441 \family default 
11442  keyword pair.
11443  Specifically it will not know which registers are used and thus register
11444  pushing/popping
11445 \begin_inset LatexCommand \index{push/pop}
11446
11447 \end_inset 
11448
11449  has to be done manually.
11450  
11451 \layout Standard
11452
11453 It is recommended that each assembly instruction (including labels) be placed
11454  in a separate line (as the example shows).
11455  When the -
11456 \begin_inset ERT
11457 status Collapsed
11458
11459 \layout Standard
11460
11461 \backslash 
11462 /
11463 \end_inset 
11464
11465 -
11466 \emph on 
11467 peep-asm
11468 \begin_inset LatexCommand \index{-\/-peep-asm}
11469
11470 \end_inset 
11471
11472
11473 \emph default 
11474  command line option is used, the inline assembler code will be passed through
11475  the peephole optimizer
11476 \begin_inset LatexCommand \index{Peephole optimizer}
11477
11478 \end_inset 
11479
11480 .
11481  There are only a few (if any) cases where this option makes sense, it might
11482  cause some unexpected changes in the inline assembler code.
11483  Please go through the peephole optimizer rules defined in file 
11484 \emph on 
11485 SDCCpeeph.def
11486 \emph default 
11487  before using this option.
11488 \layout Subsection
11489
11490 Naked Functions
11491 \begin_inset LatexCommand \label{sub:Naked-Functions}
11492
11493 \end_inset 
11494
11495
11496 \begin_inset LatexCommand \index{Naked functions}
11497
11498 \end_inset 
11499
11500
11501 \layout Standard
11502
11503 A special keyword may be associated with a function declaring it as 
11504 \emph on 
11505 _naked
11506 \begin_inset LatexCommand \index{\_naked}
11507
11508 \end_inset 
11509
11510 .
11511  
11512 \emph default 
11513 The 
11514 \emph on 
11515 _naked
11516 \emph default 
11517  function modifier attribute prevents the compiler from generating prologue
11518 \begin_inset LatexCommand \index{function prologue}
11519
11520 \end_inset 
11521
11522  and epilogue
11523 \begin_inset LatexCommand \index{function epilogue}
11524
11525 \end_inset 
11526
11527  code for that function.
11528  This means that the user is entirely responsible for such things as saving
11529  any registers that may need to be preserved, selecting the proper register
11530  bank, generating the 
11531 \emph on 
11532 return
11533 \emph default 
11534  instruction at the end, etc.
11535  Practically, this means that the contents of the function must be written
11536  in inline assembler.
11537  This is particularly useful for interrupt functions, which can have a large
11538  (and often unnecessary) prologue/epilogue.
11539  For example, compare the code generated by these two functions:
11540 \layout Verse
11541
11542
11543 \family typewriter 
11544 volatile
11545 \begin_inset LatexCommand \index{volatile}
11546
11547 \end_inset 
11548
11549  data unsigned char counter;
11550 \newline 
11551
11552 \newline 
11553 void simpleInterrupt(void) interrupt
11554 \begin_inset LatexCommand \index{interrupt}
11555
11556 \end_inset 
11557
11558  1
11559 \newline 
11560 {
11561 \newline 
11562 \SpecialChar ~
11563 \SpecialChar ~
11564 \SpecialChar ~
11565 \SpecialChar ~
11566 counter++;
11567 \newline 
11568 }
11569 \newline 
11570
11571 \newline 
11572 void nakedInterrupt(void) interrupt 2 _naked
11573 \newline 
11574 {
11575 \newline 
11576 \SpecialChar ~
11577 \SpecialChar ~
11578 \SpecialChar ~
11579 \SpecialChar ~
11580 _asm
11581 \begin_inset LatexCommand \index{\_asm}
11582
11583 \end_inset 
11584
11585
11586 \newline 
11587 \SpecialChar ~
11588 \SpecialChar ~
11589 \SpecialChar ~
11590 \SpecialChar ~
11591 \SpecialChar ~
11592 \SpecialChar ~
11593 inc\SpecialChar ~
11594 \SpecialChar ~
11595 \SpecialChar ~
11596 \SpecialChar ~
11597 \SpecialChar ~
11598 _counter ; does not change flags, no need to save psw
11599 \newline 
11600 \SpecialChar ~
11601 \SpecialChar ~
11602 \SpecialChar ~
11603 \SpecialChar ~
11604 \SpecialChar ~
11605 \SpecialChar ~
11606 reti\SpecialChar ~
11607 \SpecialChar ~
11608 \SpecialChar ~
11609 \SpecialChar ~
11610 ; MUST explicitly include ret or reti in _naked function.
11611 \newline 
11612 \SpecialChar ~
11613 \SpecialChar ~
11614 \SpecialChar ~
11615 \SpecialChar ~
11616 _endasm
11617 \begin_inset LatexCommand \index{\_endasm}
11618
11619 \end_inset 
11620
11621 ;
11622 \newline 
11623 }
11624 \layout Standard
11625
11626 For an 8051 target, the generated simpleInterrupt looks like:
11627 \layout Verse
11628
11629
11630 \family typewriter 
11631 _simpleInterrupt:
11632 \newline 
11633 \SpecialChar ~
11634 \SpecialChar ~
11635 \SpecialChar ~
11636 \SpecialChar ~
11637 push\SpecialChar ~
11638 \SpecialChar ~
11639 \SpecialChar ~
11640 \SpecialChar ~
11641 acc
11642 \newline 
11643 \SpecialChar ~
11644 \SpecialChar ~
11645 \SpecialChar ~
11646 \SpecialChar ~
11647 push\SpecialChar ~
11648 \SpecialChar ~
11649 \SpecialChar ~
11650 \SpecialChar ~
11651 b
11652 \newline 
11653 \SpecialChar ~
11654 \SpecialChar ~
11655 \SpecialChar ~
11656 \SpecialChar ~
11657 push\SpecialChar ~
11658 \SpecialChar ~
11659 \SpecialChar ~
11660 \SpecialChar ~
11661 dpl
11662 \newline 
11663 \SpecialChar ~
11664 \SpecialChar ~
11665 \SpecialChar ~
11666 \SpecialChar ~
11667 push\SpecialChar ~
11668 \SpecialChar ~
11669 \SpecialChar ~
11670 \SpecialChar ~
11671 dph
11672 \newline 
11673 \SpecialChar ~
11674 \SpecialChar ~
11675 \SpecialChar ~
11676 \SpecialChar ~
11677 push\SpecialChar ~
11678 \SpecialChar ~
11679 \SpecialChar ~
11680 \SpecialChar ~
11681 psw
11682 \newline 
11683 \SpecialChar ~
11684 \SpecialChar ~
11685 \SpecialChar ~
11686 \SpecialChar ~
11687 mov\SpecialChar ~
11688 \SpecialChar ~
11689 \SpecialChar ~
11690 \SpecialChar ~
11691 \SpecialChar ~
11692 psw,#0x00
11693 \newline 
11694 \SpecialChar ~
11695 \SpecialChar ~
11696 \SpecialChar ~
11697 \SpecialChar ~
11698 inc\SpecialChar ~
11699 \SpecialChar ~
11700 \SpecialChar ~
11701 \SpecialChar ~
11702 \SpecialChar ~
11703 _counter
11704 \newline 
11705 \SpecialChar ~
11706 \SpecialChar ~
11707 \SpecialChar ~
11708 \SpecialChar ~
11709 pop\SpecialChar ~
11710 \SpecialChar ~
11711 \SpecialChar ~
11712 \SpecialChar ~
11713 \SpecialChar ~
11714 psw
11715 \newline 
11716 \SpecialChar ~
11717 \SpecialChar ~
11718 \SpecialChar ~
11719 \SpecialChar ~
11720 pop\SpecialChar ~
11721 \SpecialChar ~
11722 \SpecialChar ~
11723 \SpecialChar ~
11724 \SpecialChar ~
11725 dph
11726 \newline 
11727 \SpecialChar ~
11728 \SpecialChar ~
11729 \SpecialChar ~
11730 \SpecialChar ~
11731 pop\SpecialChar ~
11732 \SpecialChar ~
11733 \SpecialChar ~
11734 \SpecialChar ~
11735 \SpecialChar ~
11736 dpl
11737 \newline 
11738 \SpecialChar ~
11739 \SpecialChar ~
11740 \SpecialChar ~
11741 \SpecialChar ~
11742 pop\SpecialChar ~
11743 \SpecialChar ~
11744 \SpecialChar ~
11745 \SpecialChar ~
11746 \SpecialChar ~
11747 b
11748 \newline 
11749 \SpecialChar ~
11750 \SpecialChar ~
11751 \SpecialChar ~
11752 \SpecialChar ~
11753 pop\SpecialChar ~
11754 \SpecialChar ~
11755 \SpecialChar ~
11756 \SpecialChar ~
11757 \SpecialChar ~
11758 acc
11759 \newline 
11760 \SpecialChar ~
11761 \SpecialChar ~
11762 \SpecialChar ~
11763 \SpecialChar ~
11764 reti
11765 \layout Standard
11766
11767 whereas nakedInterrupt looks like:
11768 \layout Verse
11769
11770
11771 \family typewriter 
11772 _nakedInterrupt:
11773 \newline 
11774 \SpecialChar ~
11775 \SpecialChar ~
11776 \SpecialChar ~
11777 \SpecialChar ~
11778 inc\SpecialChar ~
11779 \SpecialChar ~
11780 \SpecialChar ~
11781 \SpecialChar ~
11782 _counter ; does not change flags, no need to save psw
11783 \newline 
11784 \SpecialChar ~
11785 \SpecialChar ~
11786 \SpecialChar ~
11787 \SpecialChar ~
11788 reti\SpecialChar ~
11789 \SpecialChar ~
11790 \SpecialChar ~
11791 \SpecialChar ~
11792 \SpecialChar ~
11793 \SpecialChar ~
11794 \SpecialChar ~
11795 \SpecialChar ~
11796 \SpecialChar ~
11797 \SpecialChar ~
11798 \SpecialChar ~
11799 \SpecialChar ~
11800 ; MUST explicitly include ret or reti in _naked function
11801 \layout Standard
11802
11803 The related directive #pragma exclude
11804 \begin_inset LatexCommand \index{\#pragma exclude}
11805
11806 \end_inset 
11807
11808  allows a more fine grained control over pushing & popping
11809 \begin_inset LatexCommand \index{push/pop}
11810
11811 \end_inset 
11812
11813  the registers.
11814 \layout Standard
11815
11816 While there is nothing preventing you from writing C code inside a 
11817 \family typewriter 
11818 _naked
11819 \family default 
11820  function, there are many ways to shoot yourself in the foot doing this,
11821  and it is recommended that you stick to inline assembler.
11822 \layout Subsection
11823
11824 Use of Labels within Inline Assembler
11825 \layout Standard
11826
11827 SDCC allows the use of in-line assembler with a few restrictions regarding
11828  labels.
11829  In older versions of the compiler all labels defined within inline assembler
11830  code 
11831 \emph on 
11832 had to be
11833 \emph default 
11834  of the form 
11835 \emph on 
11836 nnnnn$
11837 \emph default 
11838  where nnnn is a number less than 100 (which implies a limit of utmost 100
11839  inline assembler labels 
11840 \emph on 
11841 per function
11842 \emph default 
11843 \noun on 
11844 )
11845 \noun default 
11846 .
11847  
11848 \layout Verse
11849
11850
11851 \family typewriter 
11852 _asm
11853 \begin_inset LatexCommand \index{\_asm}
11854
11855 \end_inset 
11856
11857  
11858 \newline 
11859 \SpecialChar ~
11860 \SpecialChar ~
11861 \SpecialChar ~
11862 \SpecialChar ~
11863 mov\SpecialChar ~
11864 \SpecialChar ~
11865 \SpecialChar ~
11866 \SpecialChar ~
11867 \SpecialChar ~
11868 b,#10 
11869 \newline 
11870 00001$: 
11871 \newline 
11872 \SpecialChar ~
11873 \SpecialChar ~
11874 \SpecialChar ~
11875 \SpecialChar ~
11876 djnz\SpecialChar ~
11877 \SpecialChar ~
11878 \SpecialChar ~
11879 \SpecialChar ~
11880 b,00001$ 
11881 \newline 
11882 _endasm
11883 \begin_inset LatexCommand \index{\_endasm}
11884
11885 \end_inset 
11886
11887  ;
11888 \layout Standard
11889
11890 Inline assembler code cannot reference any C-Labels, however it can reference
11891  labels
11892 \begin_inset LatexCommand \index{Labels}
11893
11894 \end_inset 
11895
11896  defined by the inline assembler, e.g.:
11897 \layout Verse
11898
11899
11900 \family typewriter 
11901 foo() { 
11902 \newline 
11903 \SpecialChar ~
11904 \SpecialChar ~
11905 \SpecialChar ~
11906 \SpecialChar ~
11907 /* some c code */ 
11908 \newline 
11909 \SpecialChar ~
11910 \SpecialChar ~
11911 \SpecialChar ~
11912 \SpecialChar ~
11913 _asm 
11914 \newline 
11915 \SpecialChar ~
11916 \SpecialChar ~
11917 \SpecialChar ~
11918 \SpecialChar ~
11919 \SpecialChar ~
11920 \SpecialChar ~
11921 ; some assembler code 
11922 \newline 
11923 \SpecialChar ~
11924 \SpecialChar ~
11925 \SpecialChar ~
11926 \SpecialChar ~
11927 \SpecialChar ~
11928 \SpecialChar ~
11929 ljmp $0003 
11930 \newline 
11931 \SpecialChar ~
11932 \SpecialChar ~
11933 \SpecialChar ~
11934 \SpecialChar ~
11935 _endasm; 
11936 \newline 
11937 \SpecialChar ~
11938 \SpecialChar ~
11939 \SpecialChar ~
11940 \SpecialChar ~
11941 /* some more c code */ 
11942 \newline 
11943 clabel:\SpecialChar ~
11944 \SpecialChar ~
11945 /* inline assembler cannot reference this label */ 
11946 \newline 
11947 \SpecialChar ~
11948 \SpecialChar ~
11949 \SpecialChar ~
11950 \SpecialChar ~
11951 _asm
11952 \newline 
11953 \SpecialChar ~
11954 \SpecialChar ~
11955 \SpecialChar ~
11956 \SpecialChar ~
11957 $0003: ;label (can be referenced by inline assembler only) 
11958 \newline 
11959 \SpecialChar ~
11960 \SpecialChar ~
11961 \SpecialChar ~
11962 \SpecialChar ~
11963 _endasm ; 
11964 \newline 
11965 \SpecialChar ~
11966 \SpecialChar ~
11967 \SpecialChar ~
11968 \SpecialChar ~
11969 /* some more c code */
11970 \newline 
11971 }
11972 \layout Standard
11973
11974 In other words inline assembly code can access labels defined in inline
11975  assembly within the scope of the function.
11976  The same goes the other way, i.e.
11977  labels defines in inline assembly can not be accessed by C statements.
11978 \layout Section
11979
11980 Interfacing with Assembler Code
11981 \begin_inset LatexCommand \index{Assembler routines}
11982
11983 \end_inset 
11984
11985
11986 \layout Subsection
11987
11988 Global Registers used for Parameter Passing
11989 \begin_inset LatexCommand \index{Parameter passing}
11990
11991 \end_inset 
11992
11993
11994 \layout Standard
11995
11996 The compiler always uses the global registers 
11997 \emph on 
11998 DPL, DPH
11999 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12000
12001 \end_inset 
12002
12003
12004 \begin_inset LatexCommand \index{DPTR}
12005
12006 \end_inset 
12007
12008 , B
12009 \begin_inset LatexCommand \index{B (mcs51, ds390 register)}
12010
12011 \end_inset 
12012
12013  
12014 \emph default 
12015 and
12016 \emph on 
12017  ACC
12018 \begin_inset LatexCommand \index{ACC (mcs51, ds390 register)}
12019
12020 \end_inset 
12021
12022
12023 \emph default 
12024  to pass the first parameter to a routine.
12025  The second parameter onwards is either allocated on the stack (for reentrant
12026  routines or if -
12027 \begin_inset ERT
12028 status Collapsed
12029
12030 \layout Standard
12031
12032 \backslash 
12033 /
12034 \end_inset 
12035
12036 -stack-auto is used) or in data / xdata memory (depending on the memory
12037  model).
12038  
12039 \layout Subsection
12040
12041 Assembler Routine (non-reentrant)
12042 \layout Standard
12043
12044 In the following example
12045 \begin_inset LatexCommand \index{reentrant}
12046
12047 \end_inset 
12048
12049
12050 \begin_inset LatexCommand \index{Assembler routines (non-reentrant)}
12051
12052 \end_inset 
12053
12054  the function c_func calls an assembler routine asm_func, which takes two
12055  parameters
12056 \begin_inset LatexCommand \index{function parameter}
12057
12058 \end_inset 
12059
12060 .
12061 \layout Verse
12062
12063
12064 \family typewriter 
12065 extern int asm_func(unsigned char, unsigned char);
12066 \newline 
12067
12068 \newline 
12069 int c_func (unsigned char i, unsigned char j)
12070 \newline 
12071 {
12072 \newline 
12073 \SpecialChar ~
12074 \SpecialChar ~
12075 \SpecialChar ~
12076 \SpecialChar ~
12077 return asm_func(i,j);
12078 \newline 
12079 }
12080 \newline 
12081
12082 \newline 
12083 int main()
12084 \newline 
12085 {
12086 \newline 
12087 \SpecialChar ~
12088 \SpecialChar ~
12089 \SpecialChar ~
12090 \SpecialChar ~
12091 return c_func(10,9);
12092 \newline 
12093 }
12094 \layout Standard
12095
12096 The corresponding assembler function is:
12097 \layout Verse
12098
12099
12100 \family typewriter 
12101 .globl _asm_func_PARM_2 
12102 \newline 
12103 \SpecialChar ~
12104 \SpecialChar ~
12105 \SpecialChar ~
12106 \SpecialChar ~
12107 \SpecialChar ~
12108 \SpecialChar ~
12109 \SpecialChar ~
12110 \SpecialChar ~
12111 .globl _asm_func 
12112 \newline 
12113 \SpecialChar ~
12114 \SpecialChar ~
12115 \SpecialChar ~
12116 \SpecialChar ~
12117 \SpecialChar ~
12118 \SpecialChar ~
12119 \SpecialChar ~
12120 \SpecialChar ~
12121 .area OSEG 
12122 \newline 
12123 _asm_func_PARM_2:
12124 \newline 
12125 \SpecialChar ~
12126 \SpecialChar ~
12127 \SpecialChar ~
12128 \SpecialChar ~
12129 \SpecialChar ~
12130 \SpecialChar ~
12131 \SpecialChar ~
12132 \SpecialChar ~
12133 .ds    1 
12134 \newline 
12135 \SpecialChar ~
12136 \SpecialChar ~
12137 \SpecialChar ~
12138 \SpecialChar ~
12139 \SpecialChar ~
12140 \SpecialChar ~
12141 \SpecialChar ~
12142 \SpecialChar ~
12143 .area CSEG 
12144 \newline 
12145 _asm_func: 
12146 \newline 
12147 \SpecialChar ~
12148 \SpecialChar ~
12149 \SpecialChar ~
12150 \SpecialChar ~
12151 \SpecialChar ~
12152 \SpecialChar ~
12153 \SpecialChar ~
12154 \SpecialChar ~
12155 mov\SpecialChar ~
12156 \SpecialChar ~
12157 \SpecialChar ~
12158 \SpecialChar ~
12159 a,dpl 
12160 \newline 
12161 \SpecialChar ~
12162 \SpecialChar ~
12163 \SpecialChar ~
12164 \SpecialChar ~
12165 \SpecialChar ~
12166 \SpecialChar ~
12167 \SpecialChar ~
12168 \SpecialChar ~
12169 add\SpecialChar ~
12170 \SpecialChar ~
12171 \SpecialChar ~
12172 \SpecialChar ~
12173 a,_asm_func_PARM_2 
12174 \newline 
12175 \SpecialChar ~
12176 \SpecialChar ~
12177 \SpecialChar ~
12178 \SpecialChar ~
12179 \SpecialChar ~
12180 \SpecialChar ~
12181 \SpecialChar ~
12182 \SpecialChar ~
12183 mov\SpecialChar ~
12184 \SpecialChar ~
12185 \SpecialChar ~
12186 \SpecialChar ~
12187 dpl,a 
12188 \newline 
12189 \SpecialChar ~
12190 \SpecialChar ~
12191 \SpecialChar ~
12192 \SpecialChar ~
12193 \SpecialChar ~
12194 \SpecialChar ~
12195 \SpecialChar ~
12196 \SpecialChar ~
12197 mov\SpecialChar ~
12198 \SpecialChar ~
12199 \SpecialChar ~
12200 \SpecialChar ~
12201 dph
12202 \begin_inset LatexCommand \index{DPTR, DPH, DPL}
12203
12204 \end_inset 
12205
12206 ,#0x00 
12207 \newline 
12208 \SpecialChar ~
12209 \SpecialChar ~
12210 \SpecialChar ~
12211 \SpecialChar ~
12212 \SpecialChar ~
12213 \SpecialChar ~
12214 \SpecialChar ~
12215 \SpecialChar ~
12216 ret
12217 \layout Standard
12218
12219 Note here that the return values
12220 \begin_inset LatexCommand \index{return value}
12221
12222 \end_inset 
12223
12224  are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for
12225  two byte values.
12226  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
12227 b' & 'acc' for four byte values.
12228 \layout Standard
12229
12230 The parameter naming convention is _<function_name>_PARM_<n>, where n is
12231  the parameter number starting from 1, and counting from the left.
12232  The first parameter is passed in 
12233 \begin_inset Quotes eld
12234 \end_inset 
12235
12236 dpl
12237 \begin_inset Quotes erd
12238 \end_inset 
12239
12240  for a one byte parameter, 
12241 \begin_inset Quotes eld
12242 \end_inset 
12243
12244 dptr
12245 \begin_inset Quotes erd
12246 \end_inset 
12247
12248  for two bytes, 
12249 \begin_inset Quotes eld
12250 \end_inset 
12251
12252 b,dptr
12253 \begin_inset Quotes erd
12254 \end_inset 
12255
12256  for three bytes and 
12257 \begin_inset Quotes eld
12258 \end_inset 
12259
12260 acc,b,dptr
12261 \begin_inset Quotes erd
12262 \end_inset 
12263
12264  for a four bytes parameter.
12265  The variable name for the second parameter will be _<function_name>_PARM_2.
12266 \newline 
12267
12268 \newline 
12269 Assemble the assembler routine with the following command:
12270 \newline 
12271
12272 \newline 
12273
12274 \family sans 
12275 \series bold 
12276 asx8051 -losg asmfunc.asm
12277 \newline 
12278
12279 \newline 
12280
12281 \family default 
12282 \series default 
12283 Then compile and link the assembler routine to the C source file with the
12284  following command:
12285 \newline 
12286
12287 \newline 
12288
12289 \family sans 
12290 \series bold 
12291 sdcc cfunc.c asmfunc.rel
12292 \layout Subsection
12293
12294 Assembler Routine (reentrant)
12295 \layout Standard
12296
12297 In this case
12298 \begin_inset LatexCommand \index{reentrant}
12299
12300 \end_inset 
12301
12302
12303 \begin_inset LatexCommand \index{Assembler routines (reentrant)}
12304
12305 \end_inset 
12306
12307  the second parameter
12308 \begin_inset LatexCommand \index{function parameter}
12309
12310 \end_inset 
12311
12312  onwards will be passed on the stack, the parameters are pushed from right
12313  to left i.e.
12314  after the call the leftmost parameter will be on the top of the stack.
12315  Here is an example:
12316 \layout Verse
12317
12318
12319 \family typewriter 
12320 extern int asm_func(unsigned char, unsigned char);
12321 \newline 
12322
12323 \newline 
12324 int c_func (unsigned char i, unsigned char j) reentrant 
12325 \newline 
12326
12327 \newline 
12328 \SpecialChar ~
12329 \SpecialChar ~
12330 \SpecialChar ~
12331 \SpecialChar ~
12332 return asm_func(i,j); 
12333 \newline 
12334
12335 \newline 
12336
12337 \newline 
12338 int main() 
12339 \newline 
12340
12341 \newline 
12342 \SpecialChar ~
12343 \SpecialChar ~
12344 \SpecialChar ~
12345 \SpecialChar ~
12346 return c_func(10,9); 
12347 \newline 
12348 }
12349 \layout Standard
12350
12351 The corresponding assembler routine is:
12352 \layout Verse
12353
12354
12355 \family typewriter 
12356 .globl _asm_func 
12357 \newline 
12358 _asm_func: 
12359 \newline 
12360 \SpecialChar ~
12361 \SpecialChar ~
12362 \SpecialChar ~
12363 \SpecialChar ~
12364 push  _bp 
12365 \newline 
12366 \SpecialChar ~
12367 \SpecialChar ~
12368 \SpecialChar ~
12369 \SpecialChar ~
12370 mov _bp,sp 
12371 \newline 
12372 \SpecialChar ~
12373 \SpecialChar ~
12374 \SpecialChar ~
12375 \SpecialChar ~
12376 mov r2,dpl
12377 \newline 
12378 \SpecialChar ~
12379 \SpecialChar ~
12380 \SpecialChar ~
12381 \SpecialChar ~
12382 mov a,_bp 
12383 \newline 
12384 \SpecialChar ~
12385 \SpecialChar ~
12386 \SpecialChar ~
12387 \SpecialChar ~
12388 add a,#0xfd 
12389 \newline 
12390 \SpecialChar ~
12391 \SpecialChar ~
12392 \SpecialChar ~
12393 \SpecialChar ~
12394 mov r0,a 
12395 \newline 
12396 \SpecialChar ~
12397 \SpecialChar ~
12398 \SpecialChar ~
12399 \SpecialChar ~
12400 add  a,#0xfc ;?
12401 \newline 
12402 \SpecialChar ~
12403 \SpecialChar ~
12404 \SpecialChar ~
12405 \SpecialChar ~
12406 mov  r1,a 
12407 \newline 
12408 \SpecialChar ~
12409 \SpecialChar ~
12410 \SpecialChar ~
12411 \SpecialChar ~
12412 mov  a,@r0 
12413 \newline 
12414 \SpecialChar ~
12415 \SpecialChar ~
12416 \SpecialChar ~
12417 \SpecialChar ~
12418 add  a,r2 ;?
12419 \newline 
12420 \SpecialChar ~
12421 \SpecialChar ~
12422 \SpecialChar ~
12423 \SpecialChar ~
12424 mov  dpl,a 
12425 \newline 
12426 \SpecialChar ~
12427 \SpecialChar ~
12428 \SpecialChar ~
12429 \SpecialChar ~
12430 mov  dph,#0x00 
12431 \newline 
12432 \SpecialChar ~
12433 \SpecialChar ~
12434 \SpecialChar ~
12435 \SpecialChar ~
12436 mov  sp,_bp 
12437 \newline 
12438 \SpecialChar ~
12439 \SpecialChar ~
12440 \SpecialChar ~
12441 \SpecialChar ~
12442 pop  _bp 
12443 \newline 
12444 \SpecialChar ~
12445 \SpecialChar ~
12446 \SpecialChar ~
12447 \SpecialChar ~
12448 ret
12449 \layout Standard
12450
12451 The compiling and linking procedure remains the same, however note the extra
12452  entry & exit linkage required for the assembler code, _bp is the stack
12453  frame pointer and is used to compute the offset into the stack for parameters
12454  and local variables.
12455 \layout Section
12456
12457 int (16 bit)
12458 \begin_inset LatexCommand \index{int (16 bit)}
12459
12460 \end_inset 
12461
12462  and long (32 bit)
12463 \begin_inset LatexCommand \index{long (32 bit)}
12464
12465 \end_inset 
12466
12467  Support
12468 \layout Standard
12469
12470 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
12471  multiplication and modulus operations are implemented by support routines.
12472  These support routines are all developed in ANSI-C to facilitate porting
12473  to other MCUs, although some model specific assembler optimizations are
12474  used.
12475  The following files contain the described routines, all of them can be
12476  found in <installdir>/share/sdcc/lib.
12477 \newline 
12478
12479 \layout Standard
12480 \align center 
12481
12482 \begin_inset  Tabular
12483 <lyxtabular version="3" rows="11" columns="2">
12484 <features>
12485 <column alignment="center" valignment="top" leftline="true" width="0">
12486 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12487 <row topline="true" bottomline="true">
12488 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12489 \begin_inset Text
12490
12491 \layout Standard
12492
12493
12494 \series bold 
12495 Function
12496 \end_inset 
12497 </cell>
12498 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12499 \begin_inset Text
12500
12501 \layout Standard
12502
12503
12504 \series bold 
12505 Description
12506 \end_inset 
12507 </cell>
12508 </row>
12509 <row topline="true">
12510 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12511 \begin_inset Text
12512
12513 \layout Standard
12514
12515 _mulint.c 
12516 \end_inset 
12517 </cell>
12518 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12519 \begin_inset Text
12520
12521 \layout Standard
12522
12523 16 bit multiplication
12524 \end_inset 
12525 </cell>
12526 </row>
12527 <row topline="true">
12528 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12529 \begin_inset Text
12530
12531 \layout Standard
12532
12533 _divsint.c 
12534 \end_inset 
12535 </cell>
12536 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12537 \begin_inset Text
12538
12539 \layout Standard
12540
12541  signed 16 bit division (calls _divuint)
12542 \end_inset 
12543 </cell>
12544 </row>
12545 <row topline="true">
12546 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12547 \begin_inset Text
12548
12549 \layout Standard
12550
12551 _divuint.c 
12552 \end_inset 
12553 </cell>
12554 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12555 \begin_inset Text
12556
12557 \layout Standard
12558
12559  unsigned 16 bit division
12560 \end_inset 
12561 </cell>
12562 </row>
12563 <row topline="true">
12564 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12565 \begin_inset Text
12566
12567 \layout Standard
12568
12569 _modsint.c
12570 \end_inset 
12571 </cell>
12572 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12573 \begin_inset Text
12574
12575 \layout Standard
12576
12577 signed 16 bit modulus (calls _moduint)
12578 \end_inset 
12579 </cell>
12580 </row>
12581 <row topline="true">
12582 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12583 \begin_inset Text
12584
12585 \layout Standard
12586
12587 _moduint.c
12588 \end_inset 
12589 </cell>
12590 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12591 \begin_inset Text
12592
12593 \layout Standard
12594
12595 unsigned 16 bit modulus
12596 \end_inset 
12597 </cell>
12598 </row>
12599 <row topline="true">
12600 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12601 \begin_inset Text
12602
12603 \layout Standard
12604
12605 _mullong.c
12606 \end_inset 
12607 </cell>
12608 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12609 \begin_inset Text
12610
12611 \layout Standard
12612
12613 32 bit multiplication
12614 \end_inset 
12615 </cell>
12616 </row>
12617 <row topline="true">
12618 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12619 \begin_inset Text
12620
12621 \layout Standard
12622
12623 _divslong.c 
12624 \end_inset 
12625 </cell>
12626 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12627 \begin_inset Text
12628
12629 \layout Standard
12630
12631  signed 32 division (calls _divulong)
12632 \end_inset 
12633 </cell>
12634 </row>
12635 <row topline="true">
12636 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12637 \begin_inset Text
12638
12639 \layout Standard
12640
12641 _divulong.c 
12642 \end_inset 
12643 </cell>
12644 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12645 \begin_inset Text
12646
12647 \layout Standard
12648
12649 unsigned 32 division
12650 \end_inset 
12651 </cell>
12652 </row>
12653 <row topline="true">
12654 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12655 \begin_inset Text
12656
12657 \layout Standard
12658
12659 _modslong.c
12660 \end_inset 
12661 </cell>
12662 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12663 \begin_inset Text
12664
12665 \layout Standard
12666
12667  signed 32 bit modulus (calls _modulong)
12668 \end_inset 
12669 </cell>
12670 </row>
12671 <row topline="true" bottomline="true">
12672 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12673 \begin_inset Text
12674
12675 \layout Standard
12676
12677 _modulong.c
12678 \end_inset 
12679 </cell>
12680 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12681 \begin_inset Text
12682
12683 \layout Standard
12684
12685 unsigned 32 bit modulus
12686 \end_inset 
12687 </cell>
12688 </row>
12689 </lyxtabular>
12690
12691 \end_inset 
12692
12693
12694 \newline 
12695
12696 \layout Standard
12697
12698 Since they are compiled as 
12699 \emph on 
12700 non-reentrant
12701 \emph default 
12702
12703 \begin_inset LatexCommand \index{reentrant}
12704
12705 \end_inset 
12706
12707 , interrupt
12708 \begin_inset LatexCommand \index{interrupt}
12709
12710 \end_inset 
12711
12712  service routines should not do any of the above operations.
12713  If this is unavoidable then the above routines will need to be compiled
12714  with the 
12715 \emph on 
12716 -
12717 \begin_inset ERT
12718 status Collapsed
12719
12720 \layout Standard
12721
12722 \backslash 
12723 /
12724 \end_inset 
12725
12726 -stack-auto
12727 \begin_inset LatexCommand \index{-\/-stack-auto}
12728
12729 \end_inset 
12730
12731
12732 \emph default 
12733  option, after which the source program will have to be compiled with 
12734 \emph on 
12735 -
12736 \begin_inset ERT
12737 status Collapsed
12738
12739 \layout Standard
12740
12741 \backslash 
12742 /
12743 \end_inset 
12744
12745 -int-long-reent
12746 \begin_inset LatexCommand \index{-\/-int-long-reent}
12747
12748 \end_inset 
12749
12750
12751 \emph default 
12752  option.
12753  Notice that you don't have to call these routines directly.
12754  The compiler will use them automatically every time an integer operation
12755  is required.
12756 \layout Section
12757
12758 Floating Point Support
12759 \begin_inset LatexCommand \index{Floating point support}
12760
12761 \end_inset 
12762
12763
12764 \layout Standard
12765
12766 SDCC supports IEEE (single precision 4 bytes) floating point numbers.The
12767  floating point support routines are derived from gcc's floatlib.c and consist
12768  of the following routines:
12769 \newline 
12770
12771 \layout Standard
12772 \align center 
12773
12774 \size footnotesize 
12775
12776 \begin_inset  Tabular
12777 <lyxtabular version="3" rows="17" columns="2">
12778 <features>
12779 <column alignment="center" valignment="top" leftline="true" width="0">
12780 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
12781 <row topline="true" bottomline="true">
12782 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12783 \begin_inset Text
12784
12785 \layout Standard
12786
12787
12788 \family roman 
12789 \series medium 
12790 \shape up 
12791 \size normal 
12792 \emph off 
12793 \bar no 
12794 \noun off 
12795 \color none
12796 Function 
12797 \end_inset 
12798 </cell>
12799 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12800 \begin_inset Text
12801
12802 \layout Standard
12803
12804 Description
12805 \end_inset 
12806 </cell>
12807 </row>
12808 <row topline="true">
12809 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12810 \begin_inset Text
12811
12812 \layout Standard
12813
12814
12815 \family roman 
12816 \series medium 
12817 \shape up 
12818 \size normal 
12819 \emph off 
12820 \bar no 
12821 \noun off 
12822 \color none
12823 _fsadd.c
12824 \end_inset 
12825 </cell>
12826 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12827 \begin_inset Text
12828
12829 \layout Standard
12830
12831
12832 \family roman 
12833 \series medium 
12834 \shape up 
12835 \size normal 
12836 \emph off 
12837 \bar no 
12838 \noun off 
12839 \color none
12840 add floating point numbers
12841 \end_inset 
12842 </cell>
12843 </row>
12844 <row topline="true">
12845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12846 \begin_inset Text
12847
12848 \layout Standard
12849
12850
12851 \family roman 
12852 \series medium 
12853 \shape up 
12854 \size normal 
12855 \emph off 
12856 \bar no 
12857 \noun off 
12858 \color none
12859 _fssub.c 
12860 \end_inset 
12861 </cell>
12862 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12863 \begin_inset Text
12864
12865 \layout Standard
12866
12867
12868 \family roman 
12869 \series medium 
12870 \shape up 
12871 \size normal 
12872 \emph off 
12873 \bar no 
12874 \noun off 
12875 \color none
12876 subtract floating point numbers 
12877 \end_inset 
12878 </cell>
12879 </row>
12880 <row topline="true">
12881 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12882 \begin_inset Text
12883
12884 \layout Standard
12885
12886
12887 \family roman 
12888 \series medium 
12889 \shape up 
12890 \size normal 
12891 \emph off 
12892 \bar no 
12893 \noun off 
12894 \color none
12895 _fsdiv.c 
12896 \end_inset 
12897 </cell>
12898 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12899 \begin_inset Text
12900
12901 \layout Standard
12902
12903
12904 \family roman 
12905 \series medium 
12906 \shape up 
12907 \size normal 
12908 \emph off 
12909 \bar no 
12910 \noun off 
12911 \color none
12912 divide floating point numbers 
12913 \end_inset 
12914 </cell>
12915 </row>
12916 <row topline="true">
12917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12918 \begin_inset Text
12919
12920 \layout Standard
12921
12922
12923 \family roman 
12924 \series medium 
12925 \shape up 
12926 \size normal 
12927 \emph off 
12928 \bar no 
12929 \noun off 
12930 \color none
12931 _fsmul.c 
12932 \end_inset 
12933 </cell>
12934 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12935 \begin_inset Text
12936
12937 \layout Standard
12938
12939
12940 \family roman 
12941 \series medium 
12942 \shape up 
12943 \size normal 
12944 \emph off 
12945 \bar no 
12946 \noun off 
12947 \color none
12948 multiply floating point numbers 
12949 \end_inset 
12950 </cell>
12951 </row>
12952 <row topline="true">
12953 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12954 \begin_inset Text
12955
12956 \layout Standard
12957
12958
12959 \family roman 
12960 \series medium 
12961 \shape up 
12962 \size normal 
12963 \emph off 
12964 \bar no 
12965 \noun off 
12966 \color none
12967 _fs2uchar.c
12968 \end_inset 
12969 </cell>
12970 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
12971 \begin_inset Text
12972
12973 \layout Standard
12974
12975
12976 \family roman 
12977 \series medium 
12978 \shape up 
12979 \size normal 
12980 \emph off 
12981 \bar no 
12982 \noun off 
12983 \color none
12984 convert floating point to unsigned char
12985 \end_inset 
12986 </cell>
12987 </row>
12988 <row topline="true">
12989 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
12990 \begin_inset Text
12991
12992 \layout Standard
12993
12994
12995 \family roman 
12996 \series medium 
12997 \shape up 
12998 \size normal 
12999 \emph off 
13000 \bar no 
13001 \noun off 
13002 \color none
13003 _fs2char.c
13004 \end_inset 
13005 </cell>
13006 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13007 \begin_inset Text
13008
13009 \layout Standard
13010
13011
13012 \family roman 
13013 \series medium 
13014 \shape up 
13015 \size normal 
13016 \emph off 
13017 \bar no 
13018 \noun off 
13019 \color none
13020 convert floating point to signed char
13021 \end_inset 
13022 </cell>
13023 </row>
13024 <row topline="true">
13025 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13026 \begin_inset Text
13027
13028 \layout Standard
13029
13030
13031 \family roman 
13032 \series medium 
13033 \shape up 
13034 \size normal 
13035 \emph off 
13036 \bar no 
13037 \noun off 
13038 \color none
13039 _fs2uint.c
13040 \end_inset 
13041 </cell>
13042 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13043 \begin_inset Text
13044
13045 \layout Standard
13046
13047
13048 \family roman 
13049 \series medium 
13050 \shape up 
13051 \size normal 
13052 \emph off 
13053 \bar no 
13054 \noun off 
13055 \color none
13056 convert floating point to unsigned int
13057 \end_inset 
13058 </cell>
13059 </row>
13060 <row topline="true">
13061 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13062 \begin_inset Text
13063
13064 \layout Standard
13065
13066
13067 \family roman 
13068 \series medium 
13069 \shape up 
13070 \size normal 
13071 \emph off 
13072 \bar no 
13073 \noun off 
13074 \color none
13075 _fs2int.c
13076 \end_inset 
13077 </cell>
13078 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13079 \begin_inset Text
13080
13081 \layout Standard
13082
13083
13084 \family roman 
13085 \series medium 
13086 \shape up 
13087 \size normal 
13088 \emph off 
13089 \bar no 
13090 \noun off 
13091 \color none
13092 convert floating point to signed int
13093 \end_inset 
13094 </cell>
13095 </row>
13096 <row topline="true">
13097 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13098 \begin_inset Text
13099
13100 \layout Standard
13101
13102
13103 \family roman 
13104 \series medium 
13105 \shape up 
13106 \size normal 
13107 \emph off 
13108 \bar no 
13109 \noun off 
13110 \color none
13111 _fs2ulong.
13112 \family default 
13113 \series default 
13114 \shape default 
13115 \size default 
13116 \emph default 
13117 \bar default 
13118 \noun default 
13119 \color default
13120 c
13121 \end_inset 
13122 </cell>
13123 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13124 \begin_inset Text
13125
13126 \layout Standard
13127
13128
13129 \family roman 
13130 \series medium 
13131 \shape up 
13132 \size normal 
13133 \emph off 
13134 \bar no 
13135 \noun off 
13136 \color none
13137 convert floating point to unsigned long
13138 \end_inset 
13139 </cell>
13140 </row>
13141 <row topline="true">
13142 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13143 \begin_inset Text
13144
13145 \layout Standard
13146
13147
13148 \family roman 
13149 \series medium 
13150 \shape up 
13151 \size normal 
13152 \emph off 
13153 \bar no 
13154 \noun off 
13155 \color none
13156 _fs2long.c
13157 \end_inset 
13158 </cell>
13159 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13160 \begin_inset Text
13161
13162 \layout Standard
13163
13164
13165 \family roman 
13166 \series medium 
13167 \shape up 
13168 \size normal 
13169 \emph off 
13170 \bar no 
13171 \noun off 
13172 \color none
13173 convert floating point to signed long
13174 \end_inset 
13175 </cell>
13176 </row>
13177 <row topline="true">
13178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13179 \begin_inset Text
13180
13181 \layout Standard
13182
13183
13184 \family roman 
13185 \series medium 
13186 \shape up 
13187 \size normal 
13188 \emph off 
13189 \bar no 
13190 \noun off 
13191 \color none
13192 _uchar2fs.c
13193 \end_inset 
13194 </cell>
13195 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13196 \begin_inset Text
13197
13198 \layout Standard
13199
13200
13201 \family roman 
13202 \series medium 
13203 \shape up 
13204 \size normal 
13205 \emph off 
13206 \bar no 
13207 \noun off 
13208 \color none
13209 convert unsigned char to floating point
13210 \end_inset 
13211 </cell>
13212 </row>
13213 <row topline="true">
13214 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13215 \begin_inset Text
13216
13217 \layout Standard
13218
13219
13220 \family roman 
13221 \series medium 
13222 \shape up 
13223 \size normal 
13224 \emph off 
13225 \bar no 
13226 \noun off 
13227 \color none
13228 _char2fs.c
13229 \end_inset 
13230 </cell>
13231 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13232 \begin_inset Text
13233
13234 \layout Standard
13235
13236
13237 \family roman 
13238 \series medium 
13239 \shape up 
13240 \size normal 
13241 \emph off 
13242 \bar no 
13243 \noun off 
13244 \color none
13245 convert char to floating point number
13246 \end_inset 
13247 </cell>
13248 </row>
13249 <row topline="true">
13250 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13251 \begin_inset Text
13252
13253 \layout Standard
13254
13255
13256 \family roman 
13257 \series medium 
13258 \shape up 
13259 \size normal 
13260 \emph off 
13261 \bar no 
13262 \noun off 
13263 \color none
13264 _uint2fs.c
13265 \end_inset 
13266 </cell>
13267 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13268 \begin_inset Text
13269
13270 \layout Standard
13271
13272
13273 \family roman 
13274 \series medium 
13275 \shape up 
13276 \size normal 
13277 \emph off 
13278 \bar no 
13279 \noun off 
13280 \color none
13281 convert unsigned int to floating point
13282 \end_inset 
13283 </cell>
13284 </row>
13285 <row topline="true">
13286 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13287 \begin_inset Text
13288
13289 \layout Standard
13290
13291
13292 \family roman 
13293 \series medium 
13294 \shape up 
13295 \size normal 
13296 \emph off 
13297 \bar no 
13298 \noun off 
13299 \color none
13300 _int2fs.c
13301 \end_inset 
13302 </cell>
13303 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13304 \begin_inset Text
13305
13306 \layout Standard
13307
13308
13309 \family roman 
13310 \series medium 
13311 \shape up 
13312 \size normal 
13313 \emph off 
13314 \bar no 
13315 \noun off 
13316 \color none
13317 convert int to floating point numbers
13318 \end_inset 
13319 </cell>
13320 </row>
13321 <row topline="true">
13322 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13323 \begin_inset Text
13324
13325 \layout Standard
13326
13327
13328 \family roman 
13329 \series medium 
13330 \shape up 
13331 \size normal 
13332 \emph off 
13333 \bar no 
13334 \noun off 
13335 \color none
13336 _ulong2fs.c
13337 \end_inset 
13338 </cell>
13339 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13340 \begin_inset Text
13341
13342 \layout Standard
13343
13344
13345 \family roman 
13346 \series medium 
13347 \shape up 
13348 \size normal 
13349 \emph off 
13350 \bar no 
13351 \noun off 
13352 \color none
13353 convert unsigned long to floating point number
13354 \end_inset 
13355 </cell>
13356 </row>
13357 <row topline="true" bottomline="true">
13358 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
13359 \begin_inset Text
13360
13361 \layout Standard
13362
13363
13364 \family roman 
13365 \series medium 
13366 \shape up 
13367 \size normal 
13368 \emph off 
13369 \bar no 
13370 \noun off 
13371 \color none
13372 _long2fs.c
13373 \end_inset 
13374 </cell>
13375 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
13376 \begin_inset Text
13377
13378 \layout Standard
13379
13380
13381 \family roman 
13382 \series medium 
13383 \shape up 
13384 \size normal 
13385 \emph off 
13386 \bar no 
13387 \noun off 
13388 \color none
13389 convert long to floating point number
13390 \end_inset 
13391 </cell>
13392 </row>
13393 </lyxtabular>
13394
13395 \end_inset 
13396
13397
13398 \newline 
13399
13400 \layout Standard
13401
13402 These support routines are developed in ANSI-C so there is room for space
13403  and speed improvement.
13404  Note if all these routines are used simultaneously the data space might
13405  overflow.
13406  For serious floating point usage it is recommended that the large model
13407  be used.
13408  Also notice that you don't have to call this routines directly.
13409  The compiler will use them automatically every time a floating point operation
13410  is required.
13411 \layout Section
13412
13413 Library Routines
13414 \begin_inset LatexCommand \index{Libraries}
13415
13416 \end_inset 
13417
13418
13419 \layout Standard
13420
13421
13422 \emph on 
13423 <pending: this is messy and incomplete - a little more information is in
13424  sdcc/doc/libdoc.txt
13425 \emph default 
13426  >
13427 \layout Subsection
13428
13429 Compiler support routines (_gptrget, _mulint etc.)
13430 \layout Subsection
13431
13432 Stdclib functions (puts, printf, strcat etc.)
13433 \layout Subsubsection
13434
13435 <stdio.h>
13436 \layout Standard
13437
13438
13439 \begin_inset LatexCommand \index{<stdio.h>}
13440
13441 \end_inset 
13442
13443 As usual on embedded systems you have to provide your own 
13444 \family typewriter 
13445 getchar()
13446 \begin_inset LatexCommand \index{getchar()}
13447
13448 \end_inset 
13449
13450  
13451 \family default 
13452 and 
13453 \family typewriter 
13454 putchar()
13455 \begin_inset LatexCommand \index{putchar()}
13456
13457 \end_inset 
13458
13459
13460 \family default 
13461  routines.
13462  SDCC does not know whether the system connects to a serial line with or
13463  without handshake, LCD, keyboard or other device.
13464  You'll find examples for serial routines f.e.
13465  in sdcc/device/lib.
13466 \layout Standard
13467
13468 If you're short on memory you might want to use 
13469 \family typewriter 
13470 printf_small()
13471 \family default 
13472  
13473 \emph on 
13474 instead
13475 \emph default 
13476  of
13477 \family typewriter 
13478  printf()
13479 \begin_inset LatexCommand \index{printf()}
13480
13481 \end_inset 
13482
13483 .
13484
13485 \family default 
13486  For the mcs51 there is an assembly version 
13487 \family typewriter 
13488 printf_fast()
13489 \family default 
13490  which should fit the requirements of many embedded systems (by unsetting
13491  #defines it can be customized to 
13492 \emph on 
13493 not
13494 \emph default 
13495  support long variables and field widths).
13496 \layout Subsection
13497
13498 Math functions (sin, pow, sqrt etc.)
13499 \layout Subsection
13500
13501 Other libraries
13502 \layout Standard
13503
13504 Libraries
13505 \begin_inset LatexCommand \index{Libraries}
13506
13507 \end_inset 
13508
13509  included in SDCC should have a license at least as liberal as the GNU Lesser
13510  General Public License
13511 \begin_inset LatexCommand \index{GNU Lesser General Public License, LGPL}
13512
13513 \end_inset 
13514
13515  
13516 \emph on 
13517 LGPL
13518 \emph default 
13519 .
13520 \layout Comment
13521
13522 license statements for the libraries are missing.
13523  sdcc/device/lib/ser_ir.c
13524 \layout Comment
13525
13526 or _decdptr f.e.
13527  come with a GPL (as opposed to LGPL) License - this will not be liberal
13528  enough for many embedded programmers.
13529 \layout Standard
13530
13531 If you have ported some library or want to share experience about some code
13532  which f.e.
13533  falls into any of these categories Busses (I
13534 \begin_inset Formula $^{\textrm{2}}$
13535 \end_inset 
13536
13537 C, CAN, Ethernet, Profibus, Modbus, USB, SPI, JTAG ...), Media (IDE, Memory
13538  cards, eeprom, flash...), En-/Decryption, Remote debugging, Realtime kernel,
13539  Keyboard, LCD, RTC, FPGA, PID then the sdcc-user mailing list 
13540 \begin_inset LatexCommand \url{http://sourceforge.net/mail/?group_id=599}
13541
13542 \end_inset 
13543
13544 \SpecialChar ~
13545 would certainly like to hear about it.
13546  Programmers coding for embedded systems are not especially famous for being
13547  enthusiastic, so don't expect a big hurray but as the mailing list is searchabl
13548 e these references are very valuable.
13549  Let's help to create a climate where information is shared.
13550 \layout Section
13551
13552 Memory Models
13553 \layout Subsection
13554
13555 MCS51 Memory Models
13556 \begin_inset LatexCommand \index{Memory model}
13557
13558 \end_inset 
13559
13560
13561 \begin_inset LatexCommand \index{MCS51 memory model}
13562
13563 \end_inset 
13564
13565
13566 \layout Subsubsection
13567
13568 Small and Large
13569 \layout Standard
13570
13571 SDCC allows two memory models for MCS51 code, 
13572 \shape slanted 
13573 small
13574 \shape default 
13575  and 
13576 \shape slanted 
13577 large
13578 \shape default 
13579 .
13580  Modules compiled with different memory models should 
13581 \emph on 
13582 never
13583 \emph default 
13584  be combined together or the results would be unpredictable.
13585  The library routines supplied with the compiler are compiled as both small
13586  and large.
13587  The compiled library modules are contained in separate directories as small
13588  and large so that you can link to either set.
13589  
13590 \layout Standard
13591
13592 When the large model is used all variables declared without a storage class
13593  will be allocated into the external ram, this includes all parameters and
13594  local variables (for non-reentrant
13595 \begin_inset LatexCommand \index{reentrant}
13596
13597 \end_inset 
13598
13599  functions).
13600  When the small model is used variables without storage class are allocated
13601  in the internal ram.
13602 \layout Standard
13603
13604 Judicious usage of the processor specific storage classes
13605 \begin_inset LatexCommand \index{Storage class}
13606
13607 \end_inset 
13608
13609  and the 'reentrant' function type will yield much more efficient code,
13610  than using the large model.
13611  Several optimizations are disabled when the program is compiled using the
13612  large model, it is therefore recommended that the small model be used unless
13613  absolutely required.
13614 \layout Subsubsection
13615
13616 External Stack
13617 \begin_inset LatexCommand \label{sub:External-Stack}
13618
13619 \end_inset 
13620
13621
13622 \begin_inset LatexCommand \index{stack}
13623
13624 \end_inset 
13625
13626
13627 \begin_inset LatexCommand \index{External stack (mcs51)}
13628
13629 \end_inset 
13630
13631
13632 \layout Standard
13633
13634
13635 \series bold 
13636 Attention
13637 \series default 
13638 : this option wasn't maintained for a long time and is quite buggy.
13639  Small programs might work.
13640  You've been warned!
13641 \layout Standard
13642
13643 The external stack (-
13644 \begin_inset ERT
13645 status Collapsed
13646
13647 \layout Standard
13648
13649 \backslash 
13650 /
13651 \end_inset 
13652
13653 -xstack option
13654 \begin_inset LatexCommand \index{-\/-xstack}
13655
13656 \end_inset 
13657
13658 ) is located in pdata
13659 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
13660
13661 \end_inset 
13662
13663  memory (usually at the start of the external ram segment) and is 256 bytes
13664  in size.
13665  When -
13666 \begin_inset ERT
13667 status Collapsed
13668
13669 \layout Standard
13670
13671 \backslash 
13672 /
13673 \end_inset 
13674
13675 -xstack option is used to compile the program, the parameters and local
13676  variables
13677 \begin_inset LatexCommand \index{local variables}
13678
13679 \end_inset 
13680
13681  of all reentrant functions are allocated in this area.
13682  This option is provided for programs with large stack space requirements.
13683  When used with the -
13684 \begin_inset ERT
13685 status Collapsed
13686
13687 \layout Standard
13688
13689 \backslash 
13690 /
13691 \end_inset 
13692
13693 -stack-auto
13694 \begin_inset LatexCommand \index{-\/-stack-auto}
13695
13696 \end_inset 
13697
13698  option, all parameters and local variables are allocated on the external
13699  stack (note: support libraries will need to be recompiled with the same
13700  options).
13701 \layout Standard
13702
13703 The compiler outputs the higher order address byte of the external ram segment
13704  into port P2
13705 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
13706
13707 \end_inset 
13708
13709  (see also section 
13710 \begin_inset LatexCommand \ref{sub:MCS51-variants}
13711
13712 \end_inset 
13713
13714 ), therefore when using the External Stack option, this port 
13715 \emph on 
13716 may not
13717 \emph default 
13718  be used by the application program.
13719 \layout Subsection
13720
13721 DS390 Memory Model
13722 \begin_inset LatexCommand \index{Memory model}
13723
13724 \end_inset 
13725
13726
13727 \begin_inset LatexCommand \index{DS390 memory model}
13728
13729 \end_inset 
13730
13731
13732 \layout Standard
13733
13734 The only model supported is Flat 24
13735 \begin_inset LatexCommand \index{Flat 24 (DS390 memory model)}
13736
13737 \end_inset 
13738
13739 .
13740  This generates code for the 24 bit contiguous addressing mode of the Dallas
13741  DS80C390 part.
13742  In this mode, up to four meg of external RAM or code space can be directly
13743  addressed.
13744  See the data sheets at www.dalsemi.com for further information on this part.
13745 \newline 
13746
13747 \newline 
13748 Note that the compiler does not generate any code to place the processor
13749  into 24 bitmode (although 
13750 \emph on 
13751 tinibios
13752 \emph default 
13753  in the ds390 libraries will do that for you).
13754  If you don't use 
13755 \emph on 
13756 tinibios
13757 \emph default 
13758
13759 \begin_inset LatexCommand \index{Tinibios (DS390)}
13760
13761 \end_inset 
13762
13763 , the boot loader or similar code must ensure that the processor is in 24
13764  bit contiguous addressing mode before calling the SDCC startup code.
13765 \newline 
13766
13767 \newline 
13768 Like the 
13769 \emph on 
13770 -
13771 \begin_inset ERT
13772 status Collapsed
13773
13774 \layout Standard
13775
13776 \backslash 
13777 /
13778 \end_inset 
13779
13780 -model-large
13781 \emph default 
13782  option, variables will by default be placed into the XDATA segment.
13783  
13784 \newline 
13785
13786 \newline 
13787 Segments may be placed anywhere in the 4 meg address space using the usual
13788  -
13789 \begin_inset ERT
13790 status Collapsed
13791
13792 \layout Standard
13793
13794 \backslash 
13795 /
13796 \end_inset 
13797
13798 -*-loc options.
13799  Note that if any segments are located above 64K, the -r flag must be passed
13800  to the linker to generate the proper segment relocations, and the Intel
13801  HEX output format must be used.
13802  The -r flag can be passed to the linker by using the option 
13803 \emph on 
13804 -Wl-r
13805 \emph default 
13806  on the SDCC command line.
13807  However, currently the linker can not handle code segments > 64k.
13808 \layout Section
13809
13810 Pragmas
13811 \begin_inset LatexCommand \index{Pragmas}
13812
13813 \end_inset 
13814
13815
13816 \layout Standard
13817
13818 SDCC supports the following #pragma directives:
13819 \layout Itemize
13820
13821 save
13822 \begin_inset LatexCommand \index{\#pragma save}
13823
13824 \end_inset 
13825
13826  - this will save all current options to the save/restore stack.
13827  See #pragma\SpecialChar ~
13828 restore.
13829 \layout Itemize
13830
13831 restore
13832 \begin_inset LatexCommand \index{\#pragma restore}
13833
13834 \end_inset 
13835
13836  - will restore saved options from the last save.
13837  saves & restores can be nested.
13838  SDCC uses a save/restore stack: save pushes current options to the stack,
13839  restore pulls current options from the stack.
13840  See #pragma\SpecialChar ~
13841 save.
13842 \newline 
13843
13844 \layout Itemize
13845
13846 callee_saves
13847 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13848
13849 \end_inset 
13850
13851
13852 \begin_inset LatexCommand \index{function prologue}
13853
13854 \end_inset 
13855
13856  function1[,function2[,function3...]] - The compiler by default uses a caller
13857  saves convention for register saving across function calls, however this
13858  can cause unnecessary register pushing & popping
13859 \begin_inset LatexCommand \index{push/pop}
13860
13861 \end_inset 
13862
13863  when calling small functions from larger functions.
13864  This option can be used to switch off the register saving convention for
13865  the function names specified.
13866  The compiler will not save registers when calling these functions, extra
13867  code need to be manually inserted at the entry & exit for these functions
13868  to save & restore the registers used by these functions, this can SUBSTANTIALLY
13869  reduce code & improve run time performance of the generated code.
13870  In the future the compiler (with inter procedural analysis) may be able
13871  to determine the appropriate scheme to use for each function call.
13872  If -
13873 \begin_inset ERT
13874 status Collapsed
13875
13876 \layout Standard
13877
13878 \backslash 
13879 /
13880 \end_inset 
13881
13882 -callee-saves command line option is used, the function names specified
13883  in #pragma\SpecialChar ~
13884 callee_saves
13885 \begin_inset LatexCommand \index{\#pragma callee\_saves}
13886
13887 \end_inset 
13888
13889  is appended to the list of functions specified in the command line.
13890 \layout Itemize
13891
13892 exclude
13893 \begin_inset LatexCommand \index{\#pragma exclude}
13894
13895 \end_inset 
13896
13897  none | {acc[,b[,dpl[,dph]]] - The exclude pragma disables the generation
13898  of pairs of push/pop
13899 \begin_inset LatexCommand \index{push/pop}
13900
13901 \end_inset 
13902
13903  instructions in 
13904 \emph on 
13905 I
13906 \emph default 
13907 nterrupt
13908 \begin_inset LatexCommand \index{interrupt}
13909
13910 \end_inset 
13911
13912  
13913 \emph on 
13914 S
13915 \emph default 
13916 ervice 
13917 \emph on 
13918 R
13919 \emph default 
13920 outines.
13921  The directive should be placed immediately before the ISR function definition
13922  and it affects ALL ISR functions following it.
13923  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
13924 exclude\SpecialChar ~
13925 none
13926 \begin_inset LatexCommand \index{\#pragma exclude}
13927
13928 \end_inset 
13929
13930 .
13931  See also the related keyword _naked
13932 \begin_inset LatexCommand \index{\_naked}
13933
13934 \end_inset 
13935
13936 .
13937 \layout Itemize
13938
13939 less_pedantic
13940 \begin_inset LatexCommand \index{\#pragma less\_pedantic}
13941
13942 \end_inset 
13943
13944  - the compiler will not warn you anymore for obvious mistakes, you'r on
13945  your own now ;-(
13946 \layout Itemize
13947
13948 nogcse
13949 \begin_inset LatexCommand \index{\#pragma nogcse}
13950
13951 \end_inset 
13952
13953  - will stop global common subexpression elimination.
13954 \layout Itemize
13955
13956 noinduction
13957 \begin_inset LatexCommand \index{\#pragma noinduction}
13958
13959 \end_inset 
13960
13961  - will stop loop induction optimizations.
13962 \layout Itemize
13963
13964 noinvariant
13965 \begin_inset LatexCommand \index{\#pragma noinvariant}
13966
13967 \end_inset 
13968
13969  - will not do loop invariant optimizations.
13970  For more details see Loop Invariants in section
13971 \begin_inset LatexCommand \ref{sub:Loop-Optimizations}
13972
13973 \end_inset 
13974
13975 .
13976 \layout Itemize
13977
13978 noiv
13979 \begin_inset LatexCommand \index{\#pragma noiv}
13980
13981 \end_inset 
13982
13983  - Do not generate interrupt
13984 \begin_inset LatexCommand \index{interrupt}
13985
13986 \end_inset 
13987
13988  vector table entries for all ISR functions defined after the pragma.
13989  This is useful in cases where the interrupt vector table must be defined
13990  manually, or when there is a secondary, manually defined interrupt vector
13991  table (e.g.
13992  for the autovector feature of the Cypress EZ-USB FX2).
13993  More elegantly this can be achieved by obmitting the optional interrupt
13994  number after the interrupt keyword, see section 
13995 \begin_inset LatexCommand \ref{sub:Interrupt-Service-Routines}
13996
13997 \end_inset 
13998
13999 \SpecialChar ~
14000 about interrupts.
14001 \layout Itemize
14002
14003 nojtbound
14004 \begin_inset LatexCommand \index{\#pragma nojtbound}
14005
14006 \end_inset 
14007
14008  - will not generate code for boundary value checking, when switch statements
14009  are turned into jump-tables (dangerous).
14010  For more details see section 
14011 \begin_inset LatexCommand \ref{sub:'switch'-Statements}
14012
14013 \end_inset 
14014
14015 .
14016 \layout Itemize
14017
14018 noloopreverse
14019 \begin_inset LatexCommand \index{\#pragma noloopreverse}
14020
14021 \end_inset 
14022
14023  - Will not do loop reversal optimization
14024 \layout Itemize
14025
14026 nooverlay
14027 \begin_inset LatexCommand \index{\#pragma nooverlay}
14028
14029 \end_inset 
14030
14031  - the compiler will not overlay the parameters and local variables of a
14032  function.
14033 \layout Itemize
14034
14035 stackauto
14036 \begin_inset LatexCommand \index{\#pragma stackauto}
14037
14038 \end_inset 
14039
14040 - See option -
14041 \begin_inset ERT
14042 status Collapsed
14043
14044 \layout Standard
14045
14046 \backslash 
14047 /
14048 \end_inset 
14049
14050 -stack-auto
14051 \begin_inset LatexCommand \index{-\/-stack-auto}
14052
14053 \end_inset 
14054
14055  and section 
14056 \begin_inset LatexCommand \ref{sec:Parameters-and-Local-Variables}
14057
14058 \end_inset 
14059
14060  Parameters and Local Variables.
14061 \layout Standard
14062
14063 SDCPP supports the following #pragma directives:
14064 \layout Itemize
14065
14066 preproc_asm
14067 \begin_inset LatexCommand \index{\#pragma preproc\_asm}
14068
14069 \end_inset 
14070
14071  (+ | -) - switch _asm _endasm block preprocessing on / off.
14072  Default is on.
14073 \layout Standard
14074
14075 The pragma's are intended to be used to turn-on or off certain optimizations
14076  which might cause the compiler to generate extra stack / data space to
14077  store compiler generated temporary variables.
14078  This usually happens in large functions.
14079  Pragma directives should be used as shown in the following example, they
14080  are used to control options & optimizations for a given function; pragmas
14081  should be placed before and/or after a function, placing pragma's inside
14082  a function body could have unpredictable results.
14083 \layout Verse
14084
14085
14086 \family typewriter 
14087 #pragma save
14088 \begin_inset LatexCommand \index{\#pragma save}
14089
14090 \end_inset 
14091
14092  \SpecialChar ~
14093 \SpecialChar ~
14094 \SpecialChar ~
14095 \SpecialChar ~
14096 \SpecialChar ~
14097 \SpecialChar ~
14098 \SpecialChar ~
14099 /* save the current settings */ 
14100 \newline 
14101 #pragma nogcse
14102 \begin_inset LatexCommand \index{\#pragma nogcse}
14103
14104 \end_inset 
14105
14106  \SpecialChar ~
14107 \SpecialChar ~
14108 \SpecialChar ~
14109 \SpecialChar ~
14110 \SpecialChar ~
14111 /* turnoff global subexpression elimination */ 
14112 \newline 
14113 #pragma noinduction
14114 \begin_inset LatexCommand \index{\#pragma noinduction}
14115
14116 \end_inset 
14117
14118  /* turn off induction optimizations */ 
14119 \newline 
14120 int foo () 
14121 \newline 
14122
14123 \newline 
14124 \SpecialChar ~
14125  \SpecialChar ~
14126  ...
14127  
14128 \newline 
14129 \SpecialChar ~
14130  \SpecialChar ~
14131  /* large code */ 
14132 \newline 
14133 \SpecialChar ~
14134  \SpecialChar ~
14135  ...
14136  
14137 \newline 
14138
14139 \newline 
14140 #pragma restore
14141 \begin_inset LatexCommand \index{\#pragma restore}
14142
14143 \end_inset 
14144
14145  /* turn the optimizations back on */
14146 \layout Standard
14147
14148 The compiler will generate a warning message when extra space is allocated.
14149  It is strongly recommended that the save and restore pragma's be used when
14150  changing options for a function.
14151 \layout Section
14152
14153 Defines Created by the Compiler
14154 \layout Standard
14155
14156 The compiler creates the following #defines
14157 \begin_inset LatexCommand \index{\#defines}
14158
14159 \end_inset 
14160
14161
14162 \begin_inset LatexCommand \index{Defines created by the compiler}
14163
14164 \end_inset 
14165
14166 :
14167 \newline 
14168
14169 \layout Standard
14170
14171
14172 \begin_inset  Tabular
14173 <lyxtabular version="3" rows="10" columns="2">
14174 <features>
14175 <column alignment="center" valignment="top" leftline="true" width="0">
14176 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
14177 <row topline="true" bottomline="true">
14178 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14179 \begin_inset Text
14180
14181 \layout Standard
14182
14183
14184 \series bold 
14185 #define
14186 \end_inset 
14187 </cell>
14188 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14189 \begin_inset Text
14190
14191 \layout Standard
14192
14193
14194 \series bold 
14195 Description
14196 \end_inset 
14197 </cell>
14198 </row>
14199 <row topline="true">
14200 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14201 \begin_inset Text
14202
14203 \layout Standard
14204
14205 SDCC
14206 \begin_inset LatexCommand \index{SDCC}
14207
14208 \end_inset 
14209
14210  
14211 \end_inset 
14212 </cell>
14213 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14214 \begin_inset Text
14215
14216 \layout Standard
14217
14218 this Symbol is always defined
14219 \end_inset 
14220 </cell>
14221 </row>
14222 <row topline="true">
14223 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14224 \begin_inset Text
14225
14226 \layout Standard
14227
14228 SDCC_mcs51
14229 \begin_inset LatexCommand \index{SDCC\_mcs51}
14230
14231 \end_inset 
14232
14233  or SDCC_ds390
14234 \begin_inset LatexCommand \index{SDCC\_ds390}
14235
14236 \end_inset 
14237
14238  or SDCC_z80
14239 \begin_inset LatexCommand \index{SDCC\_z80}
14240
14241 \end_inset 
14242
14243 , etc
14244 \end_inset 
14245 </cell>
14246 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14247 \begin_inset Text
14248
14249 \layout Standard
14250
14251 depending on the model used (e.g.: -mds390
14252 \end_inset 
14253 </cell>
14254 </row>
14255 <row topline="true">
14256 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14257 \begin_inset Text
14258
14259 \layout Standard
14260
14261 __mcs51
14262 \begin_inset LatexCommand \index{\_\_mcs51}
14263
14264 \end_inset 
14265
14266 , __ds390
14267 \begin_inset LatexCommand \index{\_\_ds390}
14268
14269 \end_inset 
14270
14271 , __hc08
14272 \begin_inset LatexCommand \index{\_\_hc08}
14273
14274 \end_inset 
14275
14276 , __z80
14277 \begin_inset LatexCommand \index{\_\_z80}
14278
14279 \end_inset 
14280
14281 , etc
14282 \end_inset 
14283 </cell>
14284 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14285 \begin_inset Text
14286
14287 \layout Standard
14288
14289 depending on the model used (e.g.
14290  -mz80)
14291 \end_inset 
14292 </cell>
14293 </row>
14294 <row topline="true">
14295 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14296 \begin_inset Text
14297
14298 \layout Standard
14299
14300 SDCC_STACK_AUTO
14301 \begin_inset LatexCommand \index{SDCC\_STACK\_AUTO}
14302
14303 \end_inset 
14304
14305
14306 \end_inset 
14307 </cell>
14308 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14309 \begin_inset Text
14310
14311 \layout Standard
14312
14313 when 
14314 \emph on 
14315 -
14316 \begin_inset ERT
14317 status Collapsed
14318
14319 \layout Standard
14320
14321 \backslash 
14322 /
14323 \end_inset 
14324
14325 -stack-auto
14326 \emph default 
14327  option is used
14328 \end_inset 
14329 </cell>
14330 </row>
14331 <row topline="true">
14332 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14333 \begin_inset Text
14334
14335 \layout Standard
14336
14337 SDCC_MODEL_SMALL
14338 \begin_inset LatexCommand \index{SDCC\_MODEL\_SMALL}
14339
14340 \end_inset 
14341
14342
14343 \end_inset 
14344 </cell>
14345 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14346 \begin_inset Text
14347
14348 \layout Standard
14349
14350 when 
14351 \emph on 
14352 -
14353 \begin_inset ERT
14354 status Collapsed
14355
14356 \layout Standard
14357
14358 \backslash 
14359 /
14360 \end_inset 
14361
14362 -model-small
14363 \emph default 
14364  is used
14365 \end_inset 
14366 </cell>
14367 </row>
14368 <row topline="true">
14369 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14370 \begin_inset Text
14371
14372 \layout Standard
14373
14374 SDCC_MODEL_LARGE
14375 \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE}
14376
14377 \end_inset 
14378
14379
14380 \end_inset 
14381 </cell>
14382 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14383 \begin_inset Text
14384
14385 \layout Standard
14386
14387 when 
14388 \emph on 
14389 -
14390 \begin_inset ERT
14391 status Collapsed
14392
14393 \layout Standard
14394
14395 \backslash 
14396 /
14397 \end_inset 
14398
14399 -model-large
14400 \emph default 
14401  is used
14402 \end_inset 
14403 </cell>
14404 </row>
14405 <row topline="true">
14406 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14407 \begin_inset Text
14408
14409 \layout Standard
14410
14411 SDCC_USE_XSTACK
14412 \begin_inset LatexCommand \index{SDCC\_USE\_XSTACK}
14413
14414 \end_inset 
14415
14416
14417 \end_inset 
14418 </cell>
14419 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14420 \begin_inset Text
14421
14422 \layout Standard
14423
14424 when 
14425 \emph on 
14426 -
14427 \begin_inset ERT
14428 status Collapsed
14429
14430 \layout Standard
14431
14432 \backslash 
14433 /
14434 \end_inset 
14435
14436 -xstack
14437 \emph default 
14438  option is used
14439 \end_inset 
14440 </cell>
14441 </row>
14442 <row topline="true">
14443 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14444 \begin_inset Text
14445
14446 \layout Standard
14447
14448 SDCC_STACK_TENBIT
14449 \begin_inset LatexCommand \index{SDCC\_STACK\_TENBIT}
14450
14451 \end_inset 
14452
14453  
14454 \end_inset 
14455 </cell>
14456 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14457 \begin_inset Text
14458
14459 \layout Standard
14460
14461 when 
14462 \emph on 
14463 -mds390
14464 \emph default 
14465  is used
14466 \end_inset 
14467 </cell>
14468 </row>
14469 <row topline="true" bottomline="true">
14470 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
14471 \begin_inset Text
14472
14473 \layout Standard
14474
14475 SDCC_MODEL_FLAT24
14476 \begin_inset LatexCommand \index{SDCC\_MODEL\_FLAT24}
14477
14478 \end_inset 
14479
14480
14481 \end_inset 
14482 </cell>
14483 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
14484 \begin_inset Text
14485
14486 \layout Standard
14487
14488 when 
14489 \emph on 
14490 -mds390
14491 \emph default 
14492  is used
14493 \end_inset 
14494 </cell>
14495 </row>
14496 </lyxtabular>
14497
14498 \end_inset 
14499
14500
14501 \layout Chapter
14502
14503 Notes on supported Processors
14504 \layout Section
14505
14506 MCS51 variants
14507 \begin_inset LatexCommand \label{sub:MCS51-variants}
14508
14509 \end_inset 
14510
14511
14512 \begin_inset LatexCommand \index{MCS51 variants}
14513
14514 \end_inset 
14515
14516
14517 \layout Standard
14518
14519 MCS51 processors are available from many vendors and come in many different
14520  flavours.
14521  While they might differ considerably in respect to Special Function Registers
14522  the core MCS51 is usually not modified or is kept compatible.
14523  
14524 \layout Subsection
14525
14526 pdata access by SFR 
14527 \layout Standard
14528
14529 With the upcome of devices with internal xdata and flash memory devices
14530  using port P2
14531 \begin_inset LatexCommand \index{P2 (mcs51 sfr)}
14532
14533 \end_inset 
14534
14535  as dedicated I/O port is becoming more popular.
14536  Switching the high byte for pdata
14537 \begin_inset LatexCommand \index{pdata (mcs51, ds390 storage class)}
14538
14539 \end_inset 
14540
14541  access which was formerly done by port P2 is then achieved by a Special
14542  Function Register
14543 \begin_inset LatexCommand \index{sfr}
14544
14545 \end_inset 
14546
14547 .
14548  In well-established MCS51 tradition the address of this 
14549 \emph on 
14550 sfr
14551 \emph default 
14552  is where the chip designers decided to put it.
14553  Needless to say that they didn't agree on a common name either.
14554  So that the startup code can correctly initialize xdata variables, you
14555  should define an sfr with the name _XPAGE
14556 \family typewriter 
14557
14558 \begin_inset LatexCommand \index{\_XPAGE (mcs51)}
14559
14560 \end_inset 
14561
14562
14563 \family default 
14564  at the appropriate location if the default, port P2, is not used for this.
14565  Some examples are:
14566 \layout Verse
14567
14568
14569 \family typewriter 
14570 sfr at 0x92 _XPAGE; /* Cypress EZ-USB family */
14571 \layout Verse
14572
14573
14574 \family typewriter 
14575 sfr at 0xaf _XPAGE; /* some Silicon Labs (Cygnal) chips */
14576 \layout Verse
14577
14578
14579 \family typewriter 
14580 sfr at 0xaa _XPAGE; /* some Silicon Labs (Cygnal) chips */
14581 \layout Standard
14582
14583 For more exotic implementations further customizations may be needed.
14584  See section 
14585 \begin_inset LatexCommand \ref{sub:Startup-Code}
14586
14587 \end_inset 
14588
14589  for other possibilities.
14590 \layout Subsection
14591
14592 Other Features available by SFR
14593 \layout Standard
14594
14595 Some MCS51 variants offer features like Double DPTR
14596 \begin_inset LatexCommand \index{DPTR}
14597
14598 \end_inset 
14599
14600 , multiple DPTR, decrementing DPTR, 16x16 Multiply.
14601  These are currently not used for the MCS51 port.
14602  If you absolutely need them you can fall back to inline assembly or submit
14603  a patch to SDCC.
14604 \layout Section
14605
14606 DS400 port
14607 \layout Standard
14608
14609 The DS80C400 microcontroller has a rich set of peripherals.
14610  In its built-in ROM library it includes functions to access some of the
14611  features, among them is a TCP stack with IP4 and IP6 support.
14612  Library headers (currently in beta status) and other files are provided
14613  at 
14614 \size footnotesize 
14615
14616 \begin_inset LatexCommand \url{ftp://ftp.dalsemi.com/pub/tini/ds80c400/c_libraries/sdcc/index.html}
14617
14618 \end_inset 
14619
14620 .
14621  
14622 \layout Section
14623
14624 The Z80 and gbz80 port
14625 \layout Standard
14626
14627 SDCC can target both the Zilog 
14628 \begin_inset LatexCommand \index{Z80}
14629
14630 \end_inset 
14631
14632  and the Nintendo Gameboy's Z80-like gbz80
14633 \begin_inset LatexCommand \index{gbz80 (GameBoy Z80)}
14634
14635 \end_inset 
14636
14637 .
14638  The Z80 port is passed through the same 
14639 \emph on 
14640 regressions tests
14641 \begin_inset LatexCommand \index{Regression test}
14642
14643 \end_inset 
14644
14645
14646 \emph default 
14647  as the MCS51 and DS390 ports, so floating point support, support for long
14648  variables and bitfield support is fine.
14649  See mailing lists and forums about interrupt routines.
14650 \layout Standard
14651
14652 As always, the code is the authoritative reference - see z80/ralloc.c and
14653  z80/gen.c.
14654  The stack
14655 \begin_inset LatexCommand \index{stack}
14656
14657 \end_inset 
14658
14659  frame is similar to that generated by the IAR Z80 compiler.
14660  IX is used as the base pointer, HL and IY are used as a temporary registers,
14661  and BC and DE are available for holding variables.
14662  Return values
14663 \begin_inset LatexCommand \index{return value}
14664
14665 \end_inset 
14666
14667  for the Z80 port are stored in L (one byte), HL (two bytes), or DEHL (four
14668  bytes).
14669  The gbz80 port use the same set of registers for the return values, but
14670  in a different order of significance: E (one byte), DE (two bytes), or
14671  HLDE (four bytes).
14672 \layout Section
14673
14674 The HC08 port
14675 \layout Standard
14676
14677 The port to the Motorola HC08
14678 \begin_inset LatexCommand \index{HC08}
14679
14680 \end_inset 
14681
14682  family has been added in October 2003, and is still undergoing some basic
14683  development.
14684  The code generator is complete, but the register allocation is still quite
14685  unoptimized.
14686  Some of the SDCC's standard C library functions have embedded non-HC08
14687  inline assembly and so are not yet usable.
14688 \newline 
14689
14690 \newline 
14691
14692 \layout Section
14693
14694 The PIC14 port
14695 \layout Standard
14696
14697 The 14bit PIC
14698 \begin_inset LatexCommand \index{PIC14}
14699
14700 \end_inset 
14701
14702  port still requires a major effort from the development community.
14703  However it can work for very simple code.
14704 \layout Subsection
14705
14706 C code and 14bit PIC code page
14707 \begin_inset LatexCommand \index{code page (pic14)}
14708
14709 \end_inset 
14710
14711  and RAM banks
14712 \begin_inset LatexCommand \index{RAM bank (pic14)}
14713
14714 \end_inset 
14715
14716
14717 \layout Standard
14718
14719 The linker organizes allocation for the code page and RAM banks.
14720  It does not have intimate knowledge of the code flow.
14721  It will put all the code section of a single asm file into a single code
14722  page.
14723  In order to make use of multiple code pages, separate asm files must be
14724  used.
14725  The compiler treats all functions of a single C file as being in the same
14726  code page unless it is non static.
14727  The compiler treats all local variables of a single C file as being in
14728  the same RAM bank unless it is an extern.
14729 \newline 
14730
14731 \newline 
14732 To get the best follow these guide lines:
14733 \layout Enumerate
14734
14735 make local functions static, as non static functions require code page selection
14736  overhead.
14737 \layout Enumerate
14738
14739 Make local variables static as extern variables require RAM bank selection
14740  overhead.
14741 \layout Enumerate
14742
14743 For devices that have multiple code pages it is more efficient to use the
14744  same number of files as pages, i.e.
14745  for the 16F877 use 4 separate files and i.e.
14746  for the 16F874 use 2 separate files.
14747  This way the linker can put the code for each file into different code
14748  pages and the compiler can allocate reusable variables more efficiently
14749  and there's less page selection overhead.
14750  And as for any 8 bit micro (especially for PIC 14 as they have a very simple
14751  instruction set) use 'unsigned char' whereever possible instead of 'int'.
14752 \layout Subsection
14753
14754 Creating a device include file 
14755 \layout Standard
14756
14757 For generating a device include file use the support perl script inc2h.pl
14758  kept in directory support/script.
14759 \layout Subsection
14760
14761 Interrupt code
14762 \layout Standard
14763
14764 For the interrupt function, use the keyword 'interrupt'
14765 \begin_inset LatexCommand \index{interrupt}
14766
14767 \end_inset 
14768
14769  with level number of 0 (PIC14 only has 1 interrupt so this number is only
14770  there to avoid a syntax error - it ought to be fixed).
14771  E.g.:
14772 \layout Verse
14773
14774
14775 \family typewriter 
14776 void Intr(void) interrupt 0
14777 \newline 
14778 {
14779 \newline 
14780 \SpecialChar ~
14781 \SpecialChar ~
14782 T0IF = 0; /* Clear timer interrupt */
14783 \newline 
14784 }
14785 \layout Subsection
14786
14787 Linking and assembling
14788 \layout Standard
14789
14790 For assembling you can use either GPUTILS'
14791 \begin_inset LatexCommand \index{gputils (pic tools)}
14792
14793 \end_inset 
14794
14795  gpasm.exe or MPLAB's mpasmwin.exe.
14796  GPUTILS is available from 
14797 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
14798
14799 \end_inset 
14800
14801 .
14802  For linking you can use either GPUTIL's gplink or MPLAB's mplink.exe.
14803  If you use MPLAB and an interrupt function then the linker script file
14804  vectors section will need to be enlarged to link with mplink.
14805 \newline 
14806
14807 \newline 
14808 Here is a 
14809 \family typewriter 
14810 Makefile
14811 \family default 
14812  using GPUTILS:
14813 \layout Verse
14814
14815
14816 \family typewriter 
14817 .c.o:
14818 \newline 
14819 \SpecialChar ~
14820 \SpecialChar ~
14821 \SpecialChar ~
14822 \SpecialChar ~
14823 \SpecialChar ~
14824 \SpecialChar ~
14825 \SpecialChar ~
14826 \SpecialChar ~
14827 sdcc -S -V -mpic14 -p16F877 $< 
14828 \newline 
14829 \SpecialChar ~
14830 \SpecialChar ~
14831 \SpecialChar ~
14832 \SpecialChar ~
14833 \SpecialChar ~
14834 \SpecialChar ~
14835 \SpecialChar ~
14836 \SpecialChar ~
14837 gpasm -c $*.asm
14838 \newline 
14839
14840 \newline 
14841 $(PRJ).hex: $(OBJS) 
14842 \newline 
14843 \SpecialChar ~
14844 \SpecialChar ~
14845 \SpecialChar ~
14846 \SpecialChar ~
14847 \SpecialChar ~
14848 \SpecialChar ~
14849 \SpecialChar ~
14850 \SpecialChar ~
14851 gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS)
14852 \layout Standard
14853
14854 Here is a 
14855 \family typewriter 
14856 Makefile
14857 \family default 
14858  using MPLAB:
14859 \layout Verse
14860
14861
14862 \family typewriter 
14863 .c.o: 
14864 \newline 
14865 \SpecialChar ~
14866 \SpecialChar ~
14867 \SpecialChar ~
14868 \SpecialChar ~
14869 \SpecialChar ~
14870 \SpecialChar ~
14871 \SpecialChar ~
14872 \SpecialChar ~
14873 sdcc -S -V -mpic14 -p16F877 $< 
14874 \newline 
14875 \SpecialChar ~
14876 \SpecialChar ~
14877 \SpecialChar ~
14878 \SpecialChar ~
14879 \SpecialChar ~
14880 \SpecialChar ~
14881 \SpecialChar ~
14882 \SpecialChar ~
14883 mpasmwin /q /o $*.asm
14884 \newline 
14885
14886 \newline 
14887 $(PRJ).hex: $(OBJS) 
14888 \newline 
14889 \SpecialChar ~
14890 \SpecialChar ~
14891 \SpecialChar ~
14892 \SpecialChar ~
14893 \SpecialChar ~
14894 \SpecialChar ~
14895 \SpecialChar ~
14896 \SpecialChar ~
14897 mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS)
14898 \layout Standard
14899
14900 Please note that indentations within a
14901 \family typewriter 
14902  Makefile
14903 \family default 
14904  have to be done with a tabulator character.
14905 \layout Section
14906
14907 The PIC16
14908 \begin_inset LatexCommand \index{PIC16}
14909
14910 \end_inset 
14911
14912  port
14913 \layout Standard
14914
14915 The PIC16
14916 \begin_inset LatexCommand \index{PIC16}
14917
14918 \end_inset 
14919
14920  port is the portion of SDCC that is responsible to produce code for the
14921  Microchip
14922 \begin_inset LatexCommand \index{Microchip}
14923
14924 \end_inset 
14925
14926 (TM) microcontrollers with 16 bit core.
14927  Currently this family of microcontrollers contains the PIC18Fxxx and PIC18Fxxxx.
14928 \layout Subsection
14929
14930 Global Options
14931 \layout Standard
14932
14933 PIC16 port supports the standard command line arguments as supposed, with
14934  the exception of certain cases that will be mentioned in the following
14935  list:
14936 \layout List
14937 \labelwidthstring 00.00.0000
14938
14939 -
14940 \begin_inset ERT
14941 status Collapsed
14942
14943 \layout Standard
14944
14945 \backslash 
14946 /
14947 \end_inset 
14948
14949 -stack-auto Auto variables that are function parameters, will be saved on
14950  stack by default.
14951  
14952 \emph on 
14953 There is no need to specify this in the command line.
14954 \layout List
14955 \labelwidthstring 00.00.0000
14956
14957 -
14958 \begin_inset ERT
14959 status Collapsed
14960
14961 \layout Standard
14962
14963 \backslash 
14964 /
14965 \end_inset 
14966
14967 -float-reent All floating point functions are reentrant by default.
14968  
14969 \emph on 
14970 There is no need to specifiy this in the command line.
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 -callee-saves See -
14985 \begin_inset ERT
14986 status Collapsed
14987
14988 \layout Standard
14989
14990 \backslash 
14991 /
14992 \end_inset 
14993
14994 -all-callee-saves
14995 \layout List
14996 \labelwidthstring 00.00.0000
14997
14998 -
14999 \begin_inset ERT
15000 status Collapsed
15001
15002 \layout Standard
15003
15004 \backslash 
15005 /
15006 \end_inset 
15007
15008 -all-callee-saves All function arguments are passed on stack by default.
15009  
15010 \emph on 
15011 There is no need to specify this in the command line.
15012 \layout List
15013 \labelwidthstring 00.00.0000
15014
15015 -
15016 \begin_inset ERT
15017 status Collapsed
15018
15019 \layout Standard
15020
15021 \backslash 
15022 /
15023 \end_inset 
15024
15025 -fommit-frame-pointer Frame pointer will be omitted when the function uses
15026  no local variables.
15027 \layout Subsection
15028
15029 Port Specific Options
15030 \begin_inset LatexCommand \index{Options PIC16}
15031
15032 \end_inset 
15033
15034
15035 \layout Standard
15036
15037 The port specific options appear after the global options in the sdcc --help
15038  output.
15039 \layout Subsubsection
15040
15041 General Options
15042 \layout Standard
15043
15044 General options enable certain port features and optimizations.
15045 \layout List
15046 \labelwidthstring 00.00.0000
15047
15048 -
15049 \begin_inset ERT
15050 status Collapsed
15051
15052 \layout Standard
15053
15054 \backslash 
15055 /
15056 \end_inset 
15057
15058 -pgen-bank Instructs the port to insert BANKSEL directives before instructions
15059  that use the Bank Select Register (BSR).
15060 \layout List
15061 \labelwidthstring 00.00.0000
15062
15063 -
15064 \begin_inset ERT
15065 status Collapsed
15066
15067 \layout Standard
15068
15069 \backslash 
15070 /
15071 \end_inset 
15072
15073 -pomit-config-words Instructs the port to omit the generation of the configurati
15074 on words.
15075 \layout List
15076 \labelwidthstring 00.00.0000
15077
15078 -
15079 \begin_inset ERT
15080 status Collapsed
15081
15082 \layout Standard
15083
15084 \backslash 
15085 /
15086 \end_inset 
15087
15088 -pomit-ivt Instructs the port to omit the generation of the interrupt vectors
15089 \layout List
15090 \labelwidthstring 00.00.0000
15091
15092 -
15093 \begin_inset ERT
15094 status Collapsed
15095
15096 \layout Standard
15097
15098 \backslash 
15099 /
15100 \end_inset 
15101
15102 -pleave-reset-vector Used in conjuction with the previous command, instructs
15103  the port NOT to omit the reset vector.
15104 \layout List
15105 \labelwidthstring 00.00.0000
15106
15107 -
15108 \begin_inset ERT
15109 status Collapsed
15110
15111 \layout Standard
15112
15113 \backslash 
15114 /
15115 \end_inset 
15116
15117 -stack-model=[model] Used in conjuction with the command above.
15118  Defines the stack model to be used, valid stack models are : 
15119 \begin_deeper 
15120 \layout List
15121 \labelwidthstring 00.00.0000
15122
15123
15124 \emph on 
15125 small
15126 \emph default 
15127  Selects small stack model.
15128  8 bit stack and frame pointers.
15129  Supports 256 bytes stack size.
15130 \layout List
15131 \labelwidthstring 00.00.0000
15132
15133
15134 \emph on 
15135 large
15136 \emph default 
15137  Selects large stack model.
15138  16 bit stack and frame pointers.
15139  Supports 65536 bytes stack size.
15140 \end_deeper 
15141 \layout List
15142 \labelwidthstring 00.00.0000
15143
15144 -
15145 \begin_inset ERT
15146 status Collapsed
15147
15148 \layout Standard
15149
15150 \backslash 
15151 /
15152 \end_inset 
15153
15154 -preplace-udata-with=[kword] Replaces the default udata keyword for allocating
15155  unitialized data variables with [kword].
15156  Valid keywords are: "udata_acs", "udata_shr", "udata_ovr".
15157 \layout List
15158 \labelwidthstring 00.00.0000
15159
15160 -
15161 \begin_inset ERT
15162 status Collapsed
15163
15164 \layout Standard
15165
15166 \backslash 
15167 /
15168 \end_inset 
15169
15170 -ivt-loc <nnnn> positions the Interrupt Vector Table at location <nnnn>.
15171  Useful for bootloaders.
15172 \layout List
15173 \labelwidthstring 00.00.0000
15174
15175 -
15176 \begin_inset ERT
15177 status Collapsed
15178
15179 \layout Standard
15180
15181 \backslash 
15182 /
15183 \end_inset 
15184
15185 -asm= sets the full path and name of an external assembler to call.
15186 \layout List
15187 \labelwidthstring 00.00.0000
15188
15189 -
15190 \begin_inset ERT
15191 status Collapsed
15192
15193 \layout Standard
15194
15195 \backslash 
15196 /
15197 \end_inset 
15198
15199 -link= sets the full path and name of an external linker to call.
15200 \layout Subsubsection
15201
15202 Debugging Options
15203 \layout Standard
15204
15205 Debugging options enable extra debugging information in the output files.
15206 \layout List
15207 \labelwidthstring 00.00.0000
15208
15209 -
15210 \begin_inset ERT
15211 status Collapsed
15212
15213 \layout Standard
15214
15215 \backslash 
15216 /
15217 \end_inset 
15218
15219 -debug-xtra Similar to -
15220 \begin_inset ERT
15221 status Collapsed
15222
15223 \layout Standard
15224
15225 \backslash 
15226 /
15227 \end_inset 
15228
15229 -debug
15230 \begin_inset LatexCommand \index{-\/-debug}
15231
15232 \end_inset 
15233
15234 , but dumps more information.
15235 \layout List
15236 \labelwidthstring 00.00.0000
15237
15238 -
15239 \begin_inset ERT
15240 status Collapsed
15241
15242 \layout Standard
15243
15244 \backslash 
15245 /
15246 \end_inset 
15247
15248 -debug-ralloc Force register allocator to dump <source>.d file with debugging
15249  information.
15250  <source> is the name of the file compiled.
15251 \layout List
15252 \labelwidthstring 00.00.0000
15253
15254 -
15255 \begin_inset ERT
15256 status Collapsed
15257
15258 \layout Standard
15259
15260 \backslash 
15261 /
15262 \end_inset 
15263
15264 -pcode-verbose Enable pcode debugging information in translation.
15265 \layout Subsection
15266
15267 Preprocessor Macros
15268 \layout Standard
15269
15270 PIC16 port defines the following preprocessor macros while translating a
15271  source.
15272 \layout Standard
15273 \align center 
15274
15275 \begin_inset  Tabular
15276 <lyxtabular version="3" rows="2" columns="2">
15277 <features>
15278 <column alignment="center" valignment="top" leftline="true" width="0">
15279 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15280 <row topline="true" bottomline="true">
15281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15282 \begin_inset Text
15283
15284 \layout Standard
15285
15286 Macro
15287 \end_inset 
15288 </cell>
15289 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15290 \begin_inset Text
15291
15292 \layout Standard
15293
15294 Description
15295 \end_inset 
15296 </cell>
15297 </row>
15298 <row topline="true" bottomline="true">
15299 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15300 \begin_inset Text
15301
15302 \layout Standard
15303
15304 pic18fxxxx
15305 \end_inset 
15306 </cell>
15307 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15308 \begin_inset Text
15309
15310 \layout Standard
15311
15312 MCU Identification.
15313  
15314 \emph on 
15315 xxxx
15316 \emph default 
15317  is the microcontrol identification number, i.e.
15318  452, 6620, etc
15319 \end_inset 
15320 </cell>
15321 </row>
15322 </lyxtabular>
15323
15324 \end_inset 
15325
15326
15327 \layout Subsection
15328
15329 Directories
15330 \layout Standard
15331
15332 PIC16
15333 \begin_inset LatexCommand \index{PIC16}
15334
15335 \end_inset 
15336
15337  port uses the following directories for searching header files and libraries.
15338 \layout Standard
15339 \align center 
15340
15341 \begin_inset  Tabular
15342 <lyxtabular version="3" rows="3" columns="4">
15343 <features>
15344 <column alignment="center" valignment="top" leftline="true" width="0">
15345 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15346 <column alignment="center" valignment="top" width="0">
15347 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15348 <row topline="true" bottomline="true">
15349 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15350 \begin_inset Text
15351
15352 \layout Standard
15353
15354 Directory
15355 \end_inset 
15356 </cell>
15357 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15358 \begin_inset Text
15359
15360 \layout Standard
15361
15362 Description
15363 \end_inset 
15364 </cell>
15365 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15366 \begin_inset Text
15367
15368 \layout Standard
15369
15370 Target
15371 \end_inset 
15372 </cell>
15373 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15374 \begin_inset Text
15375
15376 \layout Standard
15377
15378 Command prefix
15379 \end_inset 
15380 </cell>
15381 </row>
15382 <row topline="true">
15383 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15384 \begin_inset Text
15385
15386 \layout Standard
15387
15388 PREFIX/sdcc/include/pic16
15389 \end_inset 
15390 </cell>
15391 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15392 \begin_inset Text
15393
15394 \layout Standard
15395
15396 PIC16 specific headers
15397 \end_inset 
15398 </cell>
15399 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15400 \begin_inset Text
15401
15402 \layout Standard
15403
15404 Compiler
15405 \end_inset 
15406 </cell>
15407 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15408 \begin_inset Text
15409
15410 \layout Standard
15411
15412 -I
15413 \end_inset 
15414 </cell>
15415 </row>
15416 <row topline="true" bottomline="true">
15417 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15418 \begin_inset Text
15419
15420 \layout Standard
15421
15422 PREFIX/sdcc/lib/pic16
15423 \end_inset 
15424 </cell>
15425 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15426 \begin_inset Text
15427
15428 \layout Standard
15429
15430 PIC16 specific libraries
15431 \end_inset 
15432 </cell>
15433 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15434 \begin_inset Text
15435
15436 \layout Standard
15437
15438 Linker
15439 \end_inset 
15440 </cell>
15441 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15442 \begin_inset Text
15443
15444 \layout Standard
15445
15446 -L
15447 \end_inset 
15448 </cell>
15449 </row>
15450 </lyxtabular>
15451
15452 \end_inset 
15453
15454
15455 \layout Subsection
15456
15457 Pragmas
15458 \begin_inset LatexCommand \label{sub:PIC16_Pragmas}
15459
15460 \end_inset 
15461
15462
15463 \layout Standard
15464
15465 PIC16 port currently supports the following pragmas:
15466 \layout List
15467 \labelwidthstring 00.00.0000
15468
15469 stack pragma stack forces the code generator to initialize the stack & frame
15470  pointers at a specific address.
15471  This is an adhoc solution since gplink does not support yet stack.
15472  When the gplink issue is resolved the pragma will be deprecated
15473 \begin_inset Foot
15474 collapsed true
15475
15476 \layout Standard
15477
15478
15479 \emph on 
15480 It is important to initialize the stack, otherwise strange things can happen.
15481  Stack is not initialized by default because there are some sources that
15482  do not require it.
15483  (like library sources)
15484 \end_inset 
15485
15486 .
15487 \newline 
15488 The stack pragma should be used only once in a project.
15489  Multiple pragmas may result in indeterminate behaviour of the program.
15490 \layout LyX-Code
15491
15492 Example:
15493 \layout LyX-Code
15494
15495 \layout LyX-Code
15496
15497 /* initializes stack at RAM address 0x5ff */
15498 \layout LyX-Code
15499
15500 #pragma stack 0x5ff
15501 \layout List
15502 \labelwidthstring 00.00.0000
15503
15504 udata pragma udata instructs the compiler to emit code so that linker will
15505  place a variable at a specific memory bank
15506 \layout LyX-Code
15507
15508 Example:
15509 \layout LyX-Code
15510
15511 \layout LyX-Code
15512
15513 /* places variable foo at bank2 */
15514 \layout LyX-Code
15515
15516 #pragma udata bank2 foo
15517 \layout LyX-Code
15518
15519 char foo;
15520 \layout Standard
15521
15522 In order for this pragma to work there are some changes that must be made
15523  in the .lkr script used in link stage.
15524  In the following example a sample .lkr file is shown:
15525 \layout LyX-Code
15526
15527 \layout LyX-Code
15528
15529 // Sample linker script for the PIC18F452 processor
15530 \layout LyX-Code
15531
15532 LIBPATH .
15533 \layout LyX-Code
15534
15535 CODEPAGE   NAME=vectors    START=0x0            END=0x29           PROTECTED
15536 \layout LyX-Code
15537
15538 CODEPAGE   NAME=page       START=0x2A           END=0x7FFF
15539 \layout LyX-Code
15540
15541 CODEPAGE   NAME=idlocs     START=0x200000       END=0x200007       PROTECTED
15542 \layout LyX-Code
15543
15544 CODEPAGE   NAME=config     START=0x300000       END=0x30000D       PROTECTED
15545 \layout LyX-Code
15546
15547 CODEPAGE   NAME=devid      START=0x3FFFFE       END=0x3FFFFF       PROTECTED
15548 \layout LyX-Code
15549
15550 CODEPAGE   NAME=eedata     START=0xF00000       END=0xF000FF       PROTECTED
15551 \layout LyX-Code
15552
15553 ACCESSBANK NAME=accessram  START=0x0            END=0x7F
15554 \layout LyX-Code
15555
15556 \layout LyX-Code
15557
15558 DATABANK   NAME=gpr0       START=0x80           END=0xFF
15559 \layout LyX-Code
15560
15561 DATABANK   NAME=gpr1       START=0x100          END=0x1FF
15562 \layout LyX-Code
15563
15564 DATABANK   NAME=gpr2       START=0x200          END=0x2FF
15565 \layout LyX-Code
15566
15567 DATABANK   NAME=gpr3       START=0x300          END=0x3FF
15568 \layout LyX-Code
15569
15570 DATABANK   NAME=gpr4       START=0x400          END=0x4FF
15571 \layout LyX-Code
15572
15573 DATABANK   NAME=gpr5       START=0x500          END=0x5FF
15574 \layout LyX-Code
15575
15576 ACCESSBANK NAME=accesssfr  START=0xF80          END=0xFFF          PROTECTED
15577 \layout LyX-Code
15578
15579 \layout LyX-Code
15580
15581 SECTION    NAME=CONFIG     ROM=config
15582 \layout LyX-Code
15583
15584 \layout LyX-Code
15585
15586 SECTION    NAME=bank0      RAM=gpr0
15587 \layout LyX-Code
15588
15589 SECTION    NAME=bank1      RAM=gpr1
15590 \layout LyX-Code
15591
15592 SECTION    NAME=bank2      RAM=gpr2
15593 \layout LyX-Code
15594
15595 SECTION    NAME=bank3      RAM=gpr3
15596 \layout LyX-Code
15597
15598 SECTION    NAME=bank4      RAM=gpr4
15599 \layout LyX-Code
15600
15601 SECTION    NAME=bank5      RAM=gpr5
15602 \layout Standard
15603
15604 The linker will recognise the section name set in the pragma statement and
15605  will position the variable at the memory bank set with the RAM field at
15606  the SECTION line in the linker script file.
15607 \layout Subsection
15608
15609 Header Files
15610 \begin_inset LatexCommand \label{sub:PIC16_Header-Files}
15611
15612 \end_inset 
15613
15614
15615 \layout Standard
15616
15617 There is one main header file that can be included to the source files using
15618  the pic16 port.
15619  That file is the 
15620 \series bold 
15621 pic18fregs.h
15622 \series default 
15623 .
15624  This header file contains the definitions for the processor special registers,
15625  so it is necessary if the source accesses them.
15626  It can be included by adding the following line in the beginning of the
15627  file:
15628 \layout LyX-Code
15629
15630 #include <pic18fregs.h>
15631 \layout Standard
15632
15633 The specific microcontroller is selected within the pic18fregs.h automatically,
15634  so the same source can be used with a variety of devices.
15635 \layout Subsection
15636
15637 Libraries
15638 \layout Standard
15639
15640 The libraries that PIC16
15641 \begin_inset LatexCommand \index{PIC16}
15642
15643 \end_inset 
15644
15645  port depends on are the microcontroller device libraries which contain
15646  the symbol definitions for the microcontroller special function registers.
15647  These libraries have the format pic18fxxxx.lib, where 
15648 \emph on 
15649 xxxx
15650 \emph default 
15651  is the microcontroller identification number.
15652  The specific library is selected automatically by the compiler at link
15653  stage according to the selected device.
15654 \layout Standard
15655
15656 Libraries are created with gplib which is part of the gputils package 
15657 \begin_inset LatexCommand \url{http://gputils.sourceforge.net}
15658
15659 \end_inset 
15660
15661 .
15662 \layout Subsection
15663
15664 Memory Models
15665 \layout Standard
15666
15667 The following memory models are supported by the PIC16 port:
15668 \layout Itemize
15669
15670 small model
15671 \layout Itemize
15672
15673 large model
15674 \layout Standard
15675
15676 Memory model affects the default size of pointers within the source.
15677  The sizes are shown in the next table:
15678 \layout Standard
15679 \align center 
15680
15681 \begin_inset  Tabular
15682 <lyxtabular version="3" rows="3" columns="3">
15683 <features>
15684 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15685 <column alignment="center" valignment="top" leftline="true" width="0">
15686 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15687 <row topline="true" bottomline="true">
15688 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15689 \begin_inset Text
15690
15691 \layout Standard
15692
15693 Pointer sizes according to memory model
15694 \end_inset 
15695 </cell>
15696 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15697 \begin_inset Text
15698
15699 \layout Standard
15700
15701 small model
15702 \end_inset 
15703 </cell>
15704 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15705 \begin_inset Text
15706
15707 \layout Standard
15708
15709 large model
15710 \end_inset 
15711 </cell>
15712 </row>
15713 <row topline="true" bottomline="true">
15714 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15715 \begin_inset Text
15716
15717 \layout Standard
15718
15719 code pointers
15720 \end_inset 
15721 </cell>
15722 <cell multicolumn="1" alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15723 \begin_inset Text
15724
15725 \layout Standard
15726
15727 16-bits
15728 \end_inset 
15729 </cell>
15730 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15731 \begin_inset Text
15732
15733 \layout Standard
15734
15735 24-bits
15736 \end_inset 
15737 </cell>
15738 </row>
15739 <row topline="true" bottomline="true">
15740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15741 \begin_inset Text
15742
15743 \layout Standard
15744
15745 data pointers
15746 \end_inset 
15747 </cell>
15748 <cell multicolumn="1" alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
15749 \begin_inset Text
15750
15751 \layout Standard
15752
15753 16-bits
15754 \end_inset 
15755 </cell>
15756 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15757 \begin_inset Text
15758
15759 \layout Standard
15760
15761 16-bits
15762 \end_inset 
15763 </cell>
15764 </row>
15765 </lyxtabular>
15766
15767 \end_inset 
15768
15769
15770 \layout Standard
15771
15772 It is advisable that all sources within a project are compiled with the
15773  same memory model.
15774  If one wants to override the default memory model, this can be done by
15775  declaring a pointer as 
15776 \series bold 
15777 far
15778 \series default 
15779  or 
15780 \series bold 
15781 near
15782 \series default 
15783 .
15784  Far selects large memory model's pointers, while near selects small memory
15785  model's pointers.
15786 \layout Standard
15787
15788 The standard device libraries (see 
15789 \begin_inset LatexCommand \ref{sub:PIC16_Header-Files}
15790
15791 \end_inset 
15792
15793 ) contain no reference to pointers, so they can be used with both memory
15794  models.
15795 \layout Subsection
15796
15797 Stack
15798 \layout Standard
15799
15800 The stack implementation for the PIC16 port uses two indirect registers,
15801  FSR1 and FSR2.
15802 \layout List
15803 \labelwidthstring 00.00.0000
15804
15805 FSR1 is assigned as stack pointer
15806 \layout List
15807 \labelwidthstring 00.00.0000
15808
15809 FSR2 is assigned as frame pointer
15810 \layout Standard
15811
15812 The following stack models are supported by the PIC16 port
15813 \layout Itemize
15814
15815 small model
15816 \layout Itemize
15817
15818 large model
15819 \layout Standard
15820
15821
15822 \noun on 
15823 Small
15824 \noun default 
15825  model means that only the FSRxL byte is used to access stack and frame,
15826  while 
15827 \emph on 
15828 \noun on 
15829 large
15830 \emph default 
15831 \noun default 
15832  uses both FSRxL and FSRxH registers.
15833  The following table shows the stack/frame pointers sizes according to stack
15834  model and the maximum space they can address:
15835 \layout Standard
15836 \align center 
15837
15838 \begin_inset  Tabular
15839 <lyxtabular version="3" rows="3" columns="3">
15840 <features>
15841 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15842 <column alignment="center" valignment="top" leftline="true" width="0">
15843 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15844 <row topline="true" bottomline="true">
15845 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15846 \begin_inset Text
15847
15848 \layout Standard
15849
15850 Stack & Frame pointer sizes according to stack model
15851 \end_inset 
15852 </cell>
15853 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15854 \begin_inset Text
15855
15856 \layout Standard
15857
15858 small
15859 \end_inset 
15860 </cell>
15861 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15862 \begin_inset Text
15863
15864 \layout Standard
15865
15866 large
15867 \end_inset 
15868 </cell>
15869 </row>
15870 <row topline="true">
15871 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15872 \begin_inset Text
15873
15874 \layout Standard
15875
15876 Stack pointer FSR1
15877 \end_inset 
15878 </cell>
15879 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15880 \begin_inset Text
15881
15882 \layout Standard
15883
15884 8-bits
15885 \end_inset 
15886 </cell>
15887 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15888 \begin_inset Text
15889
15890 \layout Standard
15891
15892 16-bits
15893 \end_inset 
15894 </cell>
15895 </row>
15896 <row topline="true" bottomline="true">
15897 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15898 \begin_inset Text
15899
15900 \layout Standard
15901
15902 Frame pointer FSR2
15903 \end_inset 
15904 </cell>
15905 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15906 \begin_inset Text
15907
15908 \layout Standard
15909
15910 8-bits
15911 \end_inset 
15912 </cell>
15913 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15914 \begin_inset Text
15915
15916 \layout Standard
15917
15918 16-bits
15919 \end_inset 
15920 </cell>
15921 </row>
15922 </lyxtabular>
15923
15924 \end_inset 
15925
15926
15927 \layout Standard
15928
15929
15930 \series bold 
15931 Currently stack and frame pointers should be initialized explicit by the
15932  user at the desired Data RAM position (see 
15933 \begin_inset LatexCommand \ref{sub:PIC16_Pragmas}
15934
15935 \end_inset 
15936
15937  Pragma stack).
15938  Uninitialized stack and frame pointers can result in unexpected behavior
15939  of the resulting binary.
15940 \layout Subsection
15941
15942 Function return values
15943 \layout Standard
15944
15945 Return values from functions are placed to the appropriate registers following
15946  a modified Microchip policy optimized for SDCC.
15947  The following table shows these registers:
15948 \layout Standard
15949 \align center 
15950
15951 \begin_inset  Tabular
15952 <lyxtabular version="3" rows="6" columns="2">
15953 <features>
15954 <column alignment="center" valignment="top" leftline="true" width="0">
15955 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0">
15956 <row topline="true" bottomline="true">
15957 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15958 \begin_inset Text
15959
15960 \layout Standard
15961
15962 size
15963 \end_inset 
15964 </cell>
15965 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15966 \begin_inset Text
15967
15968 \layout Standard
15969
15970 destination register
15971 \end_inset 
15972 </cell>
15973 </row>
15974 <row topline="true">
15975 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15976 \begin_inset Text
15977
15978 \layout Standard
15979
15980 8 bits
15981 \end_inset 
15982 </cell>
15983 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
15984 \begin_inset Text
15985
15986 \layout Standard
15987
15988 WREG
15989 \end_inset 
15990 </cell>
15991 </row>
15992 <row topline="true">
15993 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
15994 \begin_inset Text
15995
15996 \layout Standard
15997
15998 16 bits
15999 \end_inset 
16000 </cell>
16001 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16002 \begin_inset Text
16003
16004 \layout Standard
16005
16006 PRODL:WREG
16007 \end_inset 
16008 </cell>
16009 </row>
16010 <row topline="true">
16011 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16012 \begin_inset Text
16013
16014 \layout Standard
16015
16016 24 bits
16017 \end_inset 
16018 </cell>
16019 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16020 \begin_inset Text
16021
16022 \layout Standard
16023
16024 PRODH:PRODL:WREG
16025 \end_inset 
16026 </cell>
16027 </row>
16028 <row topline="true">
16029 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16030 \begin_inset Text
16031
16032 \layout Standard
16033
16034 32 bits
16035 \end_inset 
16036 </cell>
16037 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16038 \begin_inset Text
16039
16040 \layout Standard
16041
16042 FSR0L:PRODH:PRODL:WREG
16043 \end_inset 
16044 </cell>
16045 </row>
16046 <row topline="true" bottomline="true">
16047 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
16048 \begin_inset Text
16049
16050 \layout Standard
16051
16052 >32 bits
16053 \end_inset 
16054 </cell>
16055 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
16056 \begin_inset Text
16057
16058 \layout Standard
16059
16060 on stack, FSR0 points to the beginning
16061 \end_inset 
16062 </cell>
16063 </row>
16064 </lyxtabular>
16065
16066 \end_inset 
16067
16068
16069 \layout Subsection
16070
16071 Interrupts
16072 \layout Standard
16073
16074 When entering an interrupt, currently the PIC16
16075 \begin_inset LatexCommand \index{PIC16}
16076
16077 \end_inset 
16078
16079  port automatically saves the following registers:
16080 \layout Itemize
16081
16082 WREG
16083 \layout Itemize
16084
16085 STATUS
16086 \layout Itemize
16087
16088 BSR
16089 \layout Itemize
16090
16091 PROD (PRODL and PRODH)
16092 \layout Itemize
16093
16094 FSR0 (FSR0L and FSR0H)
16095 \layout Standard
16096
16097 These registers are restored upon return from the interrupt routine.
16098  
16099 \layout Standard
16100
16101 When entering a high priority interrupt WREG, STATUS and BSR are not explicit
16102  saved by software.
16103  The hardware shadow registers for WREG, STATUS and BSR are used in these
16104  cases.
16105 \layout Standard
16106
16107
16108 \begin_inset Foot
16109 collapsed false
16110
16111 \layout Standard
16112
16113 NOTE that when the _naked attribute is specified for an interrupt routine,
16114  then NO registers are stored or restored.
16115 \end_inset 
16116
16117 .
16118 \layout Chapter
16119
16120 Debugging with SDCDB
16121 \begin_inset LatexCommand \label{cha:Debugging-with-SDCDB}
16122
16123 \end_inset 
16124
16125
16126 \begin_inset LatexCommand \index{sdcdb (debugger)}
16127
16128 \end_inset 
16129
16130  
16131 \layout Standard
16132
16133 SDCC is distributed with a source level debugger
16134 \begin_inset LatexCommand \index{Debugger}
16135
16136 \end_inset 
16137
16138 .
16139  The debugger uses a command line interface, the command repertoire of the
16140  debugger has been kept as close to gdb
16141 \begin_inset LatexCommand \index{gdb}
16142
16143 \end_inset 
16144
16145  (the GNU debugger) as possible.
16146  The configuration and build process is part of the standard compiler installati
16147 on, which also builds and installs the debugger in the target directory
16148  specified during configuration.
16149  The debugger allows you debug BOTH at the C source and at the ASM source
16150  level.
16151  Sdcdb is available on Unix platforms only.
16152 \layout Section
16153
16154 Compiling for Debugging
16155 \layout Standard
16156
16157 The -
16158 \begin_inset ERT
16159 status Collapsed
16160
16161 \layout Standard
16162
16163 \backslash 
16164 /
16165 \end_inset 
16166
16167 -debug
16168 \begin_inset LatexCommand \index{-\/-debug}
16169
16170 \end_inset 
16171
16172  option must be specified for all files for which debug information is to
16173  be generated.
16174  The complier generates a .adb file for each of these files.
16175  The linker creates the .cdb
16176 \begin_inset LatexCommand \index{<file>.cdb}
16177
16178 \end_inset 
16179
16180  file from the .adb
16181 \begin_inset LatexCommand \index{<file>.adb}
16182
16183 \end_inset 
16184
16185  files and the address information.
16186  This .cdb is used by the debugger.
16187 \layout Section
16188
16189 How the Debugger Works
16190 \layout Standard
16191
16192 When the -
16193 \begin_inset ERT
16194 status Collapsed
16195
16196 \layout Standard
16197
16198 \backslash 
16199 /
16200 \end_inset 
16201
16202 -debug option is specified the compiler generates extra symbol information
16203  some of which are put into the assembler source and some are put into the
16204  .adb file.
16205   Then the linker creates the .cdb file from the individual .adb files with
16206  the address information for the symbols.
16207  The debugger reads the symbolic information generated by the compiler &
16208  the address information generated by the linker.
16209  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
16210  execution is controlled by the debugger.
16211  When a command is issued for the debugger, it translates it into appropriate
16212  commands for the simulator.
16213 \layout Section
16214
16215 Starting the Debugger
16216 \layout Standard
16217
16218 The debugger can be started using the following command line.
16219  (Assume the file you are debugging has the file name foo).
16220 \newline 
16221
16222 \newline 
16223
16224 \family sans 
16225 \series bold 
16226 sdcdb foo
16227 \newline 
16228
16229 \family default 
16230 \series default 
16231
16232 \newline 
16233 The debugger will look for the following files.
16234 \layout Itemize
16235
16236 foo.c - the source file.
16237 \layout Itemize
16238
16239 foo.cdb - the debugger symbol information file.
16240 \layout Itemize
16241
16242 foo.ihx - the Intel hex format
16243 \begin_inset LatexCommand \index{Intel hex format}
16244
16245 \end_inset 
16246
16247  object file.
16248 \layout Section
16249
16250 Command Line Options.
16251 \layout Itemize
16252
16253 -
16254 \begin_inset ERT
16255 status Collapsed
16256
16257 \layout Standard
16258
16259 \backslash 
16260 /
16261 \end_inset 
16262
16263 -directory=<source file directory> this option can used to specify the directory
16264  search list.
16265  The debugger will look into the directory list specified for source, cdb
16266  & ihx files.
16267  The items in the directory list must be separated by ':', e.g.
16268  if the source files can be in the directories /home/src1 and /home/src2,
16269  the -
16270 \begin_inset ERT
16271 status Collapsed
16272
16273 \layout Standard
16274
16275 \backslash 
16276 /
16277 \end_inset 
16278
16279 -directory option should be -
16280 \begin_inset ERT
16281 status Collapsed
16282
16283 \layout Standard
16284
16285 \backslash 
16286 /
16287 \end_inset 
16288
16289 -directory=/home/src1:/home/src2.
16290  Note there can be no spaces in the option.
16291  
16292 \layout Itemize
16293
16294 -cd <directory> - change to the <directory>.
16295 \layout Itemize
16296
16297 -fullname - used by GUI front ends.
16298 \layout Itemize
16299
16300 -cpu <cpu-type> - this argument is passed to the simulator please see the
16301  simulator docs for details.
16302 \layout Itemize
16303
16304 -X <Clock frequency > this options is passed to the simulator please see
16305  the simulator docs for details.
16306 \layout Itemize
16307
16308 -s <serial port file> passed to simulator see the simulator docs for details.
16309 \layout Itemize
16310
16311 -S <serial in,out> passed to simulator see the simulator docs for details.
16312 \layout Itemize
16313
16314 -k <port number> passed to simulator see the simulator docs for details.
16315 \layout Section
16316
16317 Debugger Commands.
16318 \layout Standard
16319
16320 As mentioned earlier the command interface for the debugger has been deliberatel
16321 y kept as close the GNU debugger gdb, as possible.
16322  This will help the integration with existing graphical user interfaces
16323  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
16324  If you use a graphical user interface for the debugger you can skip the
16325  next sections.
16326 \layout Subsubsection*
16327
16328 break [line | file:line | function | file:function]
16329 \layout Standard
16330
16331 Set breakpoint at specified line or function:
16332 \newline 
16333
16334 \newline 
16335
16336 \family sans 
16337 \series bold 
16338 sdcdb>break 100 
16339 \newline 
16340 sdcdb>break foo.c:100
16341 \newline 
16342 sdcdb>break funcfoo
16343 \newline 
16344 sdcdb>break foo.c:funcfoo
16345 \layout Subsubsection*
16346
16347 clear [line | file:line | function | file:function ]
16348 \layout Standard
16349
16350 Clear breakpoint at specified line or function:
16351 \newline 
16352
16353 \newline 
16354
16355 \family sans 
16356 \series bold 
16357 sdcdb>clear 100
16358 \newline 
16359 sdcdb>clear foo.c:100
16360 \newline 
16361 sdcdb>clear funcfoo
16362 \newline 
16363 sdcdb>clear foo.c:funcfoo
16364 \layout Subsubsection*
16365
16366 continue
16367 \layout Standard
16368
16369 Continue program being debugged, after breakpoint.
16370 \layout Subsubsection*
16371
16372 finish
16373 \layout Standard
16374
16375 Execute till the end of the current function.
16376 \layout Subsubsection*
16377
16378 delete [n]
16379 \layout Standard
16380
16381 Delete breakpoint number 'n'.
16382  If used without any option clear ALL user defined break points.
16383 \layout Subsubsection*
16384
16385 info [break | stack | frame | registers ]
16386 \layout Itemize
16387
16388 info break - list all breakpoints
16389 \layout Itemize
16390
16391 info stack - show the function call stack.
16392 \layout Itemize
16393
16394 info frame - show information about the current execution frame.
16395 \layout Itemize
16396
16397 info registers - show content of all registers.
16398 \layout Subsubsection*
16399
16400 step
16401 \layout Standard
16402
16403 Step program until it reaches a different source line.
16404  Note: pressing <return> repeats the last command.
16405 \layout Subsubsection*
16406
16407 next
16408 \layout Standard
16409
16410 Step program, proceeding through subroutine calls.
16411 \layout Subsubsection*
16412
16413 run
16414 \layout Standard
16415
16416 Start debugged program.
16417 \layout Subsubsection*
16418
16419 ptype variable 
16420 \layout Standard
16421
16422 Print type information of the variable.
16423 \layout Subsubsection*
16424
16425 print variable
16426 \layout Standard
16427
16428 print value of variable.
16429 \layout Subsubsection*
16430
16431 file filename
16432 \layout Standard
16433
16434 load the given file name.
16435  Note this is an alternate method of loading file for debugging.
16436 \layout Subsubsection*
16437
16438 frame
16439 \layout Standard
16440
16441 print information about current frame.
16442 \layout Subsubsection*
16443
16444 set srcmode
16445 \layout Standard
16446
16447 Toggle between C source & assembly source.
16448 \layout Subsubsection*
16449
16450 ! simulator command
16451 \layout Standard
16452
16453 Send the string following '!' to the simulator, the simulator response is
16454  displayed.
16455  Note the debugger does not interpret the command being sent to the simulator,
16456  so if a command like 'go' is sent the debugger can loose its execution
16457  context and may display incorrect values.
16458 \layout Subsubsection*
16459
16460 quit
16461 \layout Standard
16462
16463 "Watch me now.
16464  Iam going Down.
16465  My name is Bobby Brown"
16466 \layout Section
16467
16468 Interfacing with XEmacs
16469 \begin_inset LatexCommand \index{XEmacs}
16470
16471 \end_inset 
16472
16473
16474 \begin_inset LatexCommand \index{Emacs}
16475
16476 \end_inset 
16477
16478 .
16479 \layout Standard
16480
16481 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
16482  sdcdb.el and sdcdbsrc.el.
16483  These two files can be found in the $(prefix)/bin directory after the installat
16484 ion is complete.
16485  These files need to be loaded into XEmacs for the interface to work.
16486  This can be done at XEmacs startup time by inserting the following into
16487  your '.xemacs' file (which can be found in your HOME directory): 
16488 \newline 
16489
16490 \newline 
16491
16492 \family typewriter 
16493 (load-file sdcdbsrc.el) 
16494 \family default 
16495
16496 \newline 
16497
16498 \newline 
16499 .xemacs is a lisp file so the () around the command is REQUIRED.
16500  The files can also be loaded dynamically while XEmacs is running, set the
16501  environment variable 'EMACSLOADPATH' to the installation bin directory
16502  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
16503  To start the interface enter the following command: 
16504 \newline 
16505
16506 \newline 
16507
16508 \family sans 
16509 \series bold 
16510 ESC-x sdcdbsrc
16511 \family default 
16512 \series default 
16513
16514 \newline 
16515
16516 \newline 
16517 You will prompted to enter the file name to be debugged.
16518  
16519 \newline 
16520
16521 \newline 
16522 The command line options that are passed to the simulator directly are bound
16523  to default values in the file sdcdbsrc.el.
16524  The variables are listed below, these values maybe changed as required.
16525 \layout Itemize
16526
16527 sdcdbsrc-cpu-type '51
16528 \layout Itemize
16529
16530 sdcdbsrc-frequency '11059200
16531 \layout Itemize
16532
16533 sdcdbsrc-serial nil
16534 \layout Standard
16535
16536 The following is a list of key mapping for the debugger interface.
16537 \layout Standard
16538
16539 \SpecialChar ~
16540
16541 \family typewriter 
16542
16543 \newline 
16544 ;;\SpecialChar ~
16545 Current Listing :: 
16546 \newline 
16547 ;;key\SpecialChar ~
16548 \SpecialChar ~
16549 \SpecialChar ~
16550 \SpecialChar ~
16551 \SpecialChar ~
16552 \SpecialChar ~
16553 \SpecialChar ~
16554 \SpecialChar ~
16555 \SpecialChar ~
16556 \SpecialChar ~
16557 \SpecialChar ~
16558 \SpecialChar ~
16559 \SpecialChar ~
16560 \SpecialChar ~
16561 binding\SpecialChar ~
16562 \SpecialChar ~
16563 \SpecialChar ~
16564 \SpecialChar ~
16565 \SpecialChar ~
16566 \SpecialChar ~
16567 \SpecialChar ~
16568 \SpecialChar ~
16569 \SpecialChar ~
16570 \SpecialChar ~
16571 \SpecialChar ~
16572 \SpecialChar ~
16573 \SpecialChar ~
16574 \SpecialChar ~
16575 \SpecialChar ~
16576 \SpecialChar ~
16577 \SpecialChar ~
16578 \SpecialChar ~
16579 \SpecialChar ~
16580 \SpecialChar ~
16581 \SpecialChar ~
16582 \SpecialChar ~
16583 Comment 
16584 \newline 
16585 ;;---\SpecialChar ~
16586 \SpecialChar ~
16587 \SpecialChar ~
16588 \SpecialChar ~
16589 \SpecialChar ~
16590 \SpecialChar ~
16591 \SpecialChar ~
16592 \SpecialChar ~
16593 \SpecialChar ~
16594 \SpecialChar ~
16595 \SpecialChar ~
16596 \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 \SpecialChar ~
16619 \SpecialChar ~
16620 \SpecialChar ~
16621 -------
16622 \newline 
16623 ;; 
16624 \newline 
16625 ;;\SpecialChar ~
16626 n\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 sdcdb-next-from-src\SpecialChar ~
16642 \SpecialChar ~
16643 \SpecialChar ~
16644 \SpecialChar ~
16645 \SpecialChar ~
16646 \SpecialChar ~
16647 \SpecialChar ~
16648 \SpecialChar ~
16649 \SpecialChar ~
16650 \SpecialChar ~
16651 SDCDB next command 
16652 \newline 
16653 ;;\SpecialChar ~
16654 b\SpecialChar ~
16655 \SpecialChar ~
16656 \SpecialChar ~
16657 \SpecialChar ~
16658 \SpecialChar ~
16659 \SpecialChar ~
16660 \SpecialChar ~
16661 \SpecialChar ~
16662 \SpecialChar ~
16663 \SpecialChar ~
16664 \SpecialChar ~
16665 \SpecialChar ~
16666 \SpecialChar ~
16667 \SpecialChar ~
16668 \SpecialChar ~
16669 sdcdb-back-from-src\SpecialChar ~
16670 \SpecialChar ~
16671 \SpecialChar ~
16672 \SpecialChar ~
16673 \SpecialChar ~
16674 \SpecialChar ~
16675 \SpecialChar ~
16676 \SpecialChar ~
16677 \SpecialChar ~
16678 \SpecialChar ~
16679 SDCDB back command 
16680 \newline 
16681 ;;\SpecialChar ~
16682 c\SpecialChar ~
16683 \SpecialChar ~
16684 \SpecialChar ~
16685 \SpecialChar ~
16686 \SpecialChar ~
16687 \SpecialChar ~
16688 \SpecialChar ~
16689 \SpecialChar ~
16690 \SpecialChar ~
16691 \SpecialChar ~
16692 \SpecialChar ~
16693 \SpecialChar ~
16694 \SpecialChar ~
16695 \SpecialChar ~
16696 \SpecialChar ~
16697 sdcdb-cont-from-src\SpecialChar ~
16698 \SpecialChar ~
16699 \SpecialChar ~
16700 \SpecialChar ~
16701 \SpecialChar ~
16702 \SpecialChar ~
16703 \SpecialChar ~
16704 \SpecialChar ~
16705 \SpecialChar ~
16706 \SpecialChar ~
16707 SDCDB continue command
16708 \newline 
16709 ;;\SpecialChar ~
16710 s\SpecialChar ~
16711 \SpecialChar ~
16712 \SpecialChar ~
16713 \SpecialChar ~
16714 \SpecialChar ~
16715 \SpecialChar ~
16716 \SpecialChar ~
16717 \SpecialChar ~
16718 \SpecialChar ~
16719 \SpecialChar ~
16720 \SpecialChar ~
16721 \SpecialChar ~
16722 \SpecialChar ~
16723 \SpecialChar ~
16724 \SpecialChar ~
16725 sdcdb-step-from-src\SpecialChar ~
16726 \SpecialChar ~
16727 \SpecialChar ~
16728 \SpecialChar ~
16729 \SpecialChar ~
16730 \SpecialChar ~
16731 \SpecialChar ~
16732 \SpecialChar ~
16733 \SpecialChar ~
16734 \SpecialChar ~
16735 SDCDB step command 
16736 \newline 
16737 ;;\SpecialChar ~
16738 ?\SpecialChar ~
16739 \SpecialChar ~
16740 \SpecialChar ~
16741 \SpecialChar ~
16742 \SpecialChar ~
16743 \SpecialChar ~
16744 \SpecialChar ~
16745 \SpecialChar ~
16746 \SpecialChar ~
16747 \SpecialChar ~
16748 \SpecialChar ~
16749 \SpecialChar ~
16750 \SpecialChar ~
16751 \SpecialChar ~
16752 \SpecialChar ~
16753 sdcdb-whatis-c-sexp\SpecialChar ~
16754 \SpecialChar ~
16755 \SpecialChar ~
16756 \SpecialChar ~
16757 \SpecialChar ~
16758 \SpecialChar ~
16759 \SpecialChar ~
16760 \SpecialChar ~
16761 \SpecialChar ~
16762 \SpecialChar ~
16763 SDCDB ptypecommand for data at 
16764 \newline 
16765 ;;\SpecialChar ~
16766 \SpecialChar ~
16767 \SpecialChar ~
16768 \SpecialChar ~
16769 \SpecialChar ~
16770 \SpecialChar ~
16771 \SpecialChar ~
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 \SpecialChar ~
16789 \SpecialChar ~
16790 \SpecialChar ~
16791 \SpecialChar ~
16792 \SpecialChar ~
16793 \SpecialChar ~
16794 \SpecialChar ~
16795 \SpecialChar ~
16796 \SpecialChar ~
16797 \SpecialChar ~
16798 \SpecialChar ~
16799 \SpecialChar ~
16800 \SpecialChar ~
16801 \SpecialChar ~
16802 \SpecialChar ~
16803 \SpecialChar ~
16804 \SpecialChar ~
16805 \SpecialChar ~
16806 \SpecialChar ~
16807 \SpecialChar ~
16808 \SpecialChar ~
16809 \SpecialChar ~
16810 \SpecialChar ~
16811 \SpecialChar ~
16812 buffer point 
16813 \newline 
16814 ;;\SpecialChar ~
16815 x\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 sdcdbsrc-delete\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 SDCDB Delete all breakpoints if no arg 
16845 \newline 
16846 ;;\SpecialChar ~
16847 \SpecialChar ~
16848 \SpecialChar ~
16849 \SpecialChar ~
16850 \SpecialChar ~
16851 \SpecialChar ~
16852 \SpecialChar ~
16853 \SpecialChar ~
16854 \SpecialChar ~
16855 \SpecialChar ~
16856 \SpecialChar ~
16857 \SpecialChar ~
16858 \SpecialChar ~
16859 \SpecialChar ~
16860 \SpecialChar ~
16861 \SpecialChar ~
16862 \SpecialChar ~
16863 \SpecialChar ~
16864 \SpecialChar ~
16865 \SpecialChar ~
16866 \SpecialChar ~
16867 \SpecialChar ~
16868 \SpecialChar ~
16869 \SpecialChar ~
16870 \SpecialChar ~
16871 \SpecialChar ~
16872 \SpecialChar ~
16873 \SpecialChar ~
16874 \SpecialChar ~
16875 \SpecialChar ~
16876 \SpecialChar ~
16877 \SpecialChar ~
16878 \SpecialChar ~
16879 \SpecialChar ~
16880 \SpecialChar ~
16881 \SpecialChar ~
16882 \SpecialChar ~
16883 \SpecialChar ~
16884 \SpecialChar ~
16885 \SpecialChar ~
16886 \SpecialChar ~
16887 \SpecialChar ~
16888 \SpecialChar ~
16889 \SpecialChar ~
16890 \SpecialChar ~
16891 \SpecialChar ~
16892 \SpecialChar ~
16893 given or delete arg (C-u arg x) 
16894 \newline 
16895 ;;\SpecialChar ~
16896 m\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 sdcdbsrc-frame\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 SDCDB Display current frame if no arg, 
16927 \newline 
16928 ;;\SpecialChar ~
16929 \SpecialChar ~
16930 \SpecialChar ~
16931 \SpecialChar ~
16932 \SpecialChar ~
16933 \SpecialChar ~
16934 \SpecialChar ~
16935 \SpecialChar ~
16936 \SpecialChar ~
16937 \SpecialChar ~
16938 \SpecialChar ~
16939 \SpecialChar ~
16940 \SpecialChar ~
16941 \SpecialChar ~
16942 \SpecialChar ~
16943 \SpecialChar ~
16944 \SpecialChar ~
16945 \SpecialChar ~
16946 \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 \SpecialChar ~
16962 \SpecialChar ~
16963 \SpecialChar ~
16964 \SpecialChar ~
16965 \SpecialChar ~
16966 \SpecialChar ~
16967 \SpecialChar ~
16968 \SpecialChar ~
16969 \SpecialChar ~
16970 \SpecialChar ~
16971 \SpecialChar ~
16972 \SpecialChar ~
16973 \SpecialChar ~
16974 \SpecialChar ~
16975 given or display frame arg 
16976 \newline 
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 \SpecialChar ~
17011 \SpecialChar ~
17012 \SpecialChar ~
17013 \SpecialChar ~
17014 \SpecialChar ~
17015 \SpecialChar ~
17016 \SpecialChar ~
17017 \SpecialChar ~
17018 \SpecialChar ~
17019 \SpecialChar ~
17020 \SpecialChar ~
17021 \SpecialChar ~
17022 \SpecialChar ~
17023 \SpecialChar ~
17024 buffer point 
17025 \newline 
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 sdcdbsrc-goto-sdcdb\SpecialChar ~
17043 \SpecialChar ~
17044 \SpecialChar ~
17045 \SpecialChar ~
17046 \SpecialChar ~
17047 \SpecialChar ~
17048 \SpecialChar ~
17049 \SpecialChar ~
17050 \SpecialChar ~
17051 \SpecialChar ~
17052 Goto the SDCDB output buffer 
17053 \newline 
17054 ;;\SpecialChar ~
17055 p\SpecialChar ~
17056 \SpecialChar ~
17057 \SpecialChar ~
17058 \SpecialChar ~
17059 \SpecialChar ~
17060 \SpecialChar ~
17061 \SpecialChar ~
17062 \SpecialChar ~
17063 \SpecialChar ~
17064 \SpecialChar ~
17065 \SpecialChar ~
17066 \SpecialChar ~
17067 \SpecialChar ~
17068 \SpecialChar ~
17069 \SpecialChar ~
17070 sdcdb-print-c-sexp\SpecialChar ~
17071 \SpecialChar ~
17072 \SpecialChar ~
17073 \SpecialChar ~
17074 \SpecialChar ~
17075 \SpecialChar ~
17076 \SpecialChar ~
17077 \SpecialChar ~
17078 \SpecialChar ~
17079 \SpecialChar ~
17080 \SpecialChar ~
17081 SDCDB print command for data at 
17082 \newline 
17083 ;;\SpecialChar ~
17084 \SpecialChar ~
17085 \SpecialChar ~
17086 \SpecialChar ~
17087 \SpecialChar ~
17088 \SpecialChar ~
17089 \SpecialChar ~
17090 \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 \SpecialChar ~
17106 \SpecialChar ~
17107 \SpecialChar ~
17108 \SpecialChar ~
17109 \SpecialChar ~
17110 \SpecialChar ~
17111 \SpecialChar ~
17112 \SpecialChar ~
17113 \SpecialChar ~
17114 \SpecialChar ~
17115 \SpecialChar ~
17116 \SpecialChar ~
17117 \SpecialChar ~
17118 \SpecialChar ~
17119 \SpecialChar ~
17120 \SpecialChar ~
17121 \SpecialChar ~
17122 \SpecialChar ~
17123 \SpecialChar ~
17124 \SpecialChar ~
17125 \SpecialChar ~
17126 \SpecialChar ~
17127 \SpecialChar ~
17128 \SpecialChar ~
17129 \SpecialChar ~
17130 buffer point 
17131 \newline 
17132 ;;\SpecialChar ~
17133 g\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 sdcdbsrc-goto-sdcdb\SpecialChar ~
17149 \SpecialChar ~
17150 \SpecialChar ~
17151 \SpecialChar ~
17152 \SpecialChar ~
17153 \SpecialChar ~
17154 \SpecialChar ~
17155 \SpecialChar ~
17156 \SpecialChar ~
17157 \SpecialChar ~
17158 Goto the SDCDB output buffer 
17159 \newline 
17160 ;;\SpecialChar ~
17161 t\SpecialChar ~
17162 \SpecialChar ~
17163 \SpecialChar ~
17164 \SpecialChar ~
17165 \SpecialChar ~
17166 \SpecialChar ~
17167 \SpecialChar ~
17168 \SpecialChar ~
17169 \SpecialChar ~
17170 \SpecialChar ~
17171 \SpecialChar ~
17172 \SpecialChar ~
17173 \SpecialChar ~
17174 \SpecialChar ~
17175 \SpecialChar ~
17176 sdcdbsrc-mode\SpecialChar ~
17177 \SpecialChar ~
17178 \SpecialChar ~
17179 \SpecialChar ~
17180 \SpecialChar ~
17181 \SpecialChar ~
17182 \SpecialChar ~
17183 \SpecialChar ~
17184 \SpecialChar ~
17185 \SpecialChar ~
17186 \SpecialChar ~
17187 \SpecialChar ~
17188 \SpecialChar ~
17189 \SpecialChar ~
17190 \SpecialChar ~
17191 \SpecialChar ~
17192 Toggles Sdcdbsrc mode (turns it off) 
17193 \newline 
17194 ;; 
17195 \newline 
17196 ;;\SpecialChar ~
17197 C-c\SpecialChar ~
17198 C-f\SpecialChar ~
17199 \SpecialChar ~
17200 \SpecialChar ~
17201 \SpecialChar ~
17202 \SpecialChar ~
17203 \SpecialChar ~
17204 \SpecialChar ~
17205 \SpecialChar ~
17206 \SpecialChar ~
17207 sdcdb-finish-from-src\SpecialChar ~
17208 \SpecialChar ~
17209 \SpecialChar ~
17210 \SpecialChar ~
17211 \SpecialChar ~
17212 \SpecialChar ~
17213 \SpecialChar ~
17214 \SpecialChar ~
17215 SDCDB finish command 
17216 \newline 
17217 ;; 
17218 \newline 
17219 ;;\SpecialChar ~
17220 C-x\SpecialChar ~
17221 SPC\SpecialChar ~
17222 \SpecialChar ~
17223 \SpecialChar ~
17224 \SpecialChar ~
17225 \SpecialChar ~
17226 \SpecialChar ~
17227 \SpecialChar ~
17228 \SpecialChar ~
17229 \SpecialChar ~
17230 sdcdb-break\SpecialChar ~
17231 \SpecialChar ~
17232 \SpecialChar ~
17233 \SpecialChar ~
17234 \SpecialChar ~
17235 \SpecialChar ~
17236 \SpecialChar ~
17237 \SpecialChar ~
17238 \SpecialChar ~
17239 \SpecialChar ~
17240 \SpecialChar ~
17241 \SpecialChar ~
17242 \SpecialChar ~
17243 \SpecialChar ~
17244 \SpecialChar ~
17245 \SpecialChar ~
17246 \SpecialChar ~
17247 \SpecialChar ~
17248 Set break for line with point 
17249 \newline 
17250 ;;\SpecialChar ~
17251 ESC\SpecialChar ~
17252 t\SpecialChar ~
17253 \SpecialChar ~
17254 \SpecialChar ~
17255 \SpecialChar ~
17256 \SpecialChar ~
17257 \SpecialChar ~
17258 \SpecialChar ~
17259 \SpecialChar ~
17260 \SpecialChar ~
17261 \SpecialChar ~
17262 \SpecialChar ~
17263 sdcdbsrc-mode\SpecialChar ~
17264 \SpecialChar ~
17265 \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 Toggle Sdcdbsrc mode 
17280 \newline 
17281 ;;\SpecialChar ~
17282 ESC\SpecialChar ~
17283 m\SpecialChar ~
17284 \SpecialChar ~
17285 \SpecialChar ~
17286 \SpecialChar ~
17287 \SpecialChar ~
17288 \SpecialChar ~
17289 \SpecialChar ~
17290 \SpecialChar ~
17291 \SpecialChar ~
17292 \SpecialChar ~
17293 \SpecialChar ~
17294 sdcdbsrc-srcmode\SpecialChar ~
17295 \SpecialChar ~
17296 \SpecialChar ~
17297 \SpecialChar ~
17298 \SpecialChar ~
17299 \SpecialChar ~
17300 \SpecialChar ~
17301 \SpecialChar ~
17302 \SpecialChar ~
17303 \SpecialChar ~
17304 \SpecialChar ~
17305 \SpecialChar ~
17306 \SpecialChar ~
17307 Toggle list mode 
17308 \newline 
17309 ;; 
17310 \newline 
17311
17312 \layout Chapter
17313 \pagebreak_top 
17314 TIPS
17315 \layout Standard
17316
17317 Here are a few guidelines that will help the compiler generate more efficient
17318  code, some of the tips are specific to this compiler others are generally
17319  good programming practice.
17320 \layout Itemize
17321
17322 Use the smallest data type to represent your data-value.
17323  If it is known in advance that the value is going to be less than 256 then
17324  use an 'unsigned char' instead of a 'short' or 'int'.
17325  Please note, that ANSI C requires both signed and unsigned chars to be
17326  promoted to 'signed int' before doing any operation.
17327  This promotion can be omitted, if the result is the same.
17328  The effect of the promotion rules together with the sign-extension is often
17329  surprising:
17330 \begin_deeper 
17331 \layout Verse
17332
17333
17334 \family typewriter 
17335 unsigned char uc = 0xfe;
17336 \newline 
17337 if (uc * uc < 0) /* this is true! */
17338 \newline 
17339 {
17340 \newline 
17341 \SpecialChar ~
17342 \SpecialChar ~
17343 \SpecialChar ~
17344 \SpecialChar ~
17345 ....
17346 \newline 
17347 }
17348 \layout Standard
17349
17350
17351 \family typewriter 
17352 uc * uc
17353 \family default 
17354  is evaluated as 
17355 \family typewriter 
17356 (int) uc * (int) uc = (int) 0xfe * (int) 0xfe = (int) 0xfc04 = -1024
17357 \family default 
17358 .
17359  
17360 \newline 
17361 Another one:
17362 \layout Verse
17363
17364
17365 \family typewriter 
17366 (unsigned char) -12 / (signed char) -3 = ...
17367 \layout Standard
17368
17369 No, the result is not 4:
17370 \layout Verse
17371
17372
17373 \family typewriter 
17374 (int) (unsigned char) -12 / (int) (signed char) -3 =
17375 \newline 
17376 (int) (unsigned char) 0xf4 / (int) (signed char) 0xfd =
17377 \newline 
17378 (int) 0x00f4 / (int) 0xfffd =
17379 \newline 
17380 (int) 0x00f4 / (int) 0xfffd =
17381 \newline 
17382 (int) 244 / (int) -3 =
17383 \newline 
17384 (int) -81 = (int) 0xffaf;
17385 \layout Standard
17386
17387 Don't complain, that gcc gives you a different result.
17388  gcc uses 32 bit ints, while SDCC uses 16 bit ints.
17389  Therefore the results are different.
17390 \newline 
17391 From 
17392 \begin_inset Quotes sld
17393 \end_inset 
17394
17395 comp.lang.c FAQ
17396 \begin_inset Quotes srd
17397 \end_inset 
17398
17399 :
17400 \layout Quote
17401
17402 If well-defined overflow characteristics are important and negative values
17403  are not, or if you want to steer clear of sign-extension problems when
17404  manipulating bits or bytes, use one of the corresponding unsigned types.
17405  (Beware when mixing signed and unsigned values in expressions, though.)
17406 \newline 
17407 Although character types (especially unsigned char) can be used as "tiny"
17408  integers, doing so is sometimes more trouble than it's worth, due to unpredicta
17409 ble sign extension and increased code size.
17410 \end_deeper 
17411 \layout Itemize
17412
17413 Use unsigned when it is known in advance that the value is not going to
17414  be negative.
17415  This helps especially if you are doing division or multiplication, bit-shifting
17416  or are using an array index.
17417 \layout Itemize
17418
17419 NEVER jump into a LOOP.
17420 \layout Itemize
17421
17422 Declare the variables to be local
17423 \begin_inset LatexCommand \index{local variables}
17424
17425 \end_inset 
17426
17427  whenever possible, especially loop control variables (induction).
17428 \layout Itemize
17429
17430 Since the compiler does not always do implicit integral promotion, the programme
17431 r should do an explicit cast when integral promotion is required.
17432 \layout Itemize
17433
17434 Reducing the size of division, multiplication & modulus operations can reduce
17435  code size substantially.
17436  Take the following code for example.
17437 \begin_deeper 
17438 \layout Verse
17439
17440
17441 \family typewriter 
17442 foobar(unsigned int p1, unsigned char ch)
17443 \newline 
17444 {
17445 \newline 
17446 \SpecialChar ~
17447 \SpecialChar ~
17448 \SpecialChar ~
17449 \SpecialChar ~
17450 unsigned char ch1 = p1 % ch ;
17451 \newline 
17452 \SpecialChar ~
17453 \SpecialChar ~
17454 \SpecialChar ~
17455 \SpecialChar ~
17456 ....
17457 \newline 
17458 }
17459 \layout Standard
17460
17461 For the modulus operation the variable ch will be promoted to unsigned int
17462  first then the modulus operation will be performed (this will lead to a
17463  call to support routine _moduint()), and the result will be casted to a
17464  char.
17465  If the code is changed to 
17466 \layout Verse
17467
17468
17469 \family typewriter 
17470 foobar(unsigned int p1, unsigned char ch)
17471 \newline 
17472 {
17473 \newline 
17474 \SpecialChar ~
17475 \SpecialChar ~
17476 \SpecialChar ~
17477 \SpecialChar ~
17478 unsigned char ch1 = (unsigned char)p1 % ch ;
17479 \newline 
17480 \SpecialChar ~
17481 \SpecialChar ~
17482 \SpecialChar ~
17483 \SpecialChar ~
17484 ....
17485 \newline 
17486 }
17487 \layout Standard
17488
17489 It would substantially reduce the code generated (future versions of the
17490  compiler will be smart enough to detect such optimization opportunities).
17491 \end_deeper 
17492 \layout Itemize
17493
17494 Have a look at the assembly listing to get a 
17495 \begin_inset Quotes sld
17496 \end_inset 
17497
17498 feeling
17499 \begin_inset Quotes srd
17500 \end_inset 
17501
17502  for the code generation.
17503 \layout Section
17504
17505 Tools
17506 \begin_inset LatexCommand \index{Tools}
17507
17508 \end_inset 
17509
17510  included in the distribution
17511 \layout Standard
17512 \align center 
17513
17514 \begin_inset  Tabular
17515 <lyxtabular version="3" rows="12" columns="3">
17516 <features>
17517 <column alignment="center" valignment="top" leftline="true" width="0pt">
17518 <column alignment="center" valignment="top" leftline="true" width="0pt">
17519 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
17520 <row topline="true" bottomline="true">
17521 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17522 \begin_inset Text
17523
17524 \layout Standard
17525
17526 Name
17527 \end_inset 
17528 </cell>
17529 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17530 \begin_inset Text
17531
17532 \layout Standard
17533
17534 Purpose
17535 \end_inset 
17536 </cell>
17537 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17538 \begin_inset Text
17539
17540 \layout Standard
17541
17542 Directory
17543 \end_inset 
17544 </cell>
17545 </row>
17546 <row topline="true">
17547 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17548 \begin_inset Text
17549
17550 \layout Standard
17551
17552 uCsim
17553 \end_inset 
17554 </cell>
17555 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17556 \begin_inset Text
17557
17558 \layout Standard
17559
17560 Simulator for various architectures
17561 \end_inset 
17562 </cell>
17563 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17564 \begin_inset Text
17565
17566 \layout Standard
17567
17568 sdcc/sim/ucsim
17569 \end_inset 
17570 </cell>
17571 </row>
17572 <row topline="true">
17573 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17574 \begin_inset Text
17575
17576 \layout Standard
17577
17578 keil2sdcc.pl
17579 \end_inset 
17580 </cell>
17581 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17582 \begin_inset Text
17583
17584 \layout Standard
17585
17586 header file conversion
17587 \end_inset 
17588 </cell>
17589 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17590 \begin_inset Text
17591
17592 \layout Standard
17593
17594 sdcc/support/scripts
17595 \end_inset 
17596 </cell>
17597 </row>
17598 <row topline="true">
17599 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17600 \begin_inset Text
17601
17602 \layout Standard
17603
17604 mh2h.c
17605 \end_inset 
17606 </cell>
17607 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17608 \begin_inset Text
17609
17610 \layout Standard
17611
17612 header file conversion
17613 \end_inset 
17614 </cell>
17615 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17616 \begin_inset Text
17617
17618 \layout Standard
17619
17620 sdcc/support/scripts
17621 \end_inset 
17622 </cell>
17623 </row>
17624 <row topline="true">
17625 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17626 \begin_inset Text
17627
17628 \layout Standard
17629
17630 as-gbz80
17631 \end_inset 
17632 </cell>
17633 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17634 \begin_inset Text
17635
17636 \layout Standard
17637
17638 Assembler
17639 \end_inset 
17640 </cell>
17641 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17642 \begin_inset Text
17643
17644 \layout Standard
17645
17646
17647 \family roman 
17648 \series medium 
17649 \shape up 
17650 \size normal 
17651 \emph off 
17652 \bar no 
17653 \noun off 
17654 \color none
17655 sdcc/bin
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-z80
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 asx8051
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 sdcdb
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 Simulator
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 aslink
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 Linker
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 link-z80
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-gbz80
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" bottomline="true">
17870 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17871 \begin_inset Text
17872
17873 \layout Standard
17874
17875 packihx
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 ihx packer
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 </lyxtabular>
17905
17906 \end_inset 
17907
17908
17909 \newline 
17910
17911 \layout Section
17912
17913 Documentation
17914 \begin_inset LatexCommand \index{Documentation}
17915
17916 \end_inset 
17917
17918  included in the distribution
17919 \layout Standard
17920 \align center 
17921
17922 \begin_inset  Tabular
17923 <lyxtabular version="3" rows="10" columns="2">
17924 <features>
17925 <column alignment="left" valignment="top" leftline="true" width="0">
17926 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0pt">
17927 <row topline="true" bottomline="true">
17928 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17929 \begin_inset Text
17930
17931 \layout Standard
17932
17933 Subject / Title
17934 \end_inset 
17935 </cell>
17936 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17937 \begin_inset Text
17938
17939 \layout Standard
17940
17941 Where to get / filename
17942 \end_inset 
17943 </cell>
17944 </row>
17945 <row topline="true">
17946 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17947 \begin_inset Text
17948
17949 \layout Standard
17950
17951 SDCC Compiler User Guide
17952 \end_inset 
17953 </cell>
17954 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17955 \begin_inset Text
17956
17957 \layout Standard
17958
17959 You're reading it right now
17960 \end_inset 
17961 </cell>
17962 </row>
17963 <row topline="true">
17964 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17965 \begin_inset Text
17966
17967 \layout Standard
17968
17969 Changelog of SDCC
17970 \end_inset 
17971 </cell>
17972 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17973 \begin_inset Text
17974
17975 \layout Standard
17976
17977 sdcc/Changelog
17978 \end_inset 
17979 </cell>
17980 </row>
17981 <row topline="true">
17982 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
17983 \begin_inset Text
17984
17985 \layout Standard
17986
17987 ASXXXX Assemblers and ASLINK Relocating Linker
17988 \end_inset 
17989 </cell>
17990 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
17991 \begin_inset Text
17992
17993 \layout Standard
17994
17995 sdcc/as/doc/asxhtm.html
17996 \end_inset 
17997 </cell>
17998 </row>
17999 <row topline="true">
18000 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18001 \begin_inset Text
18002
18003 \layout Standard
18004
18005 SDCC regression test
18006 \begin_inset LatexCommand \index{Regression test}
18007
18008 \end_inset 
18009
18010
18011 \end_inset 
18012 </cell>
18013 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18014 \begin_inset Text
18015
18016 \layout Standard
18017
18018 sdcc/doc/test_suite_spec.pdf
18019 \end_inset 
18020 </cell>
18021 </row>
18022 <row topline="true">
18023 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18024 \begin_inset Text
18025
18026 \layout Standard
18027
18028 Various notes
18029 \end_inset 
18030 </cell>
18031 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18032 \begin_inset Text
18033
18034 \layout Standard
18035
18036 sdcc/doc/*
18037 \end_inset 
18038 </cell>
18039 </row>
18040 <row topline="true">
18041 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18042 \begin_inset Text
18043
18044 \layout Standard
18045
18046 Notes on debugging with sdcdb
18047 \begin_inset LatexCommand \index{sdcdb (debugger)}
18048
18049 \end_inset 
18050
18051
18052 \end_inset 
18053 </cell>
18054 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18055 \begin_inset Text
18056
18057 \layout Standard
18058
18059 sdcc/debugger/README
18060 \end_inset 
18061 </cell>
18062 </row>
18063 <row topline="true">
18064 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18065 \begin_inset Text
18066
18067 \layout Standard
18068
18069 Software simulator for microcontrollers
18070 \end_inset 
18071 </cell>
18072 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18073 \begin_inset Text
18074
18075 \layout Standard
18076
18077
18078 \family roman 
18079 \series medium 
18080 \shape up 
18081 \size normal 
18082 \emph off 
18083 \bar no 
18084 \noun off 
18085 \color none
18086 sdcc/sim/ucsim/doc
18087 \family default 
18088 \series default 
18089 \shape default 
18090 \size default 
18091 \emph default 
18092 \bar default 
18093 \noun default 
18094 \color default
18095 /index.html
18096 \end_inset 
18097 </cell>
18098 </row>
18099 <row topline="true">
18100 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18101 \begin_inset Text
18102
18103 \layout Standard
18104
18105 Temporary notes on the pic16
18106 \begin_inset LatexCommand \index{PIC16}
18107
18108 \end_inset 
18109
18110  port
18111 \end_inset 
18112 </cell>
18113 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18114 \begin_inset Text
18115
18116 \layout Standard
18117
18118 sdcc/src/pic16/NOTES
18119 \end_inset 
18120 </cell>
18121 </row>
18122 <row topline="true" bottomline="true">
18123 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18124 \begin_inset Text
18125
18126 \layout Standard
18127
18128 SDCC internal documentation (debugging file format)
18129 \end_inset 
18130 </cell>
18131 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18132 \begin_inset Text
18133
18134 \layout Standard
18135
18136 sdcc/doc/
18137 \family roman 
18138 \series medium 
18139 \shape up 
18140 \size normal 
18141 \emph off 
18142 \bar no 
18143 \noun off 
18144 \color none
18145 cdbfileformat.pd
18146 \family default 
18147 \series default 
18148 \shape default 
18149 \size default 
18150 \emph default 
18151 \bar default 
18152 \noun default 
18153 \color default
18154 f
18155 \end_inset 
18156 </cell>
18157 </row>
18158 </lyxtabular>
18159
18160 \end_inset 
18161
18162
18163 \newline 
18164
18165 \layout Section
18166
18167 Related open source tools
18168 \begin_inset LatexCommand \index{Related tools}
18169
18170 \end_inset 
18171
18172
18173 \layout Standard
18174 \align center 
18175
18176 \begin_inset  Tabular
18177 <lyxtabular version="3" rows="11" columns="3">
18178 <features>
18179 <column alignment="center" valignment="top" leftline="true" width="0pt">
18180 <column alignment="block" valignment="top" leftline="true" width="30line%">
18181 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18182 <row topline="true" bottomline="true">
18183 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18184 \begin_inset Text
18185
18186 \layout Standard
18187
18188 Name
18189 \end_inset 
18190 </cell>
18191 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18192 \begin_inset Text
18193
18194 \layout Standard
18195
18196 Purpose
18197 \end_inset 
18198 </cell>
18199 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18200 \begin_inset Text
18201
18202 \layout Standard
18203
18204 Where to get
18205 \end_inset 
18206 </cell>
18207 </row>
18208 <row topline="true">
18209 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18210 \begin_inset Text
18211
18212 \layout Standard
18213
18214 gpsim
18215 \begin_inset LatexCommand \index{gpsim (pic simulator)}
18216
18217 \end_inset 
18218
18219
18220 \end_inset 
18221 </cell>
18222 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18223 \begin_inset Text
18224
18225 \layout Standard
18226
18227 PIC simulator
18228 \end_inset 
18229 </cell>
18230 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18231 \begin_inset Text
18232
18233 \layout Standard
18234
18235
18236 \begin_inset LatexCommand \url{http://www.dattalo.com/gnupic/gpsim.html}
18237
18238 \end_inset 
18239
18240
18241 \end_inset 
18242 </cell>
18243 </row>
18244 <row topline="true">
18245 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18246 \begin_inset Text
18247
18248 \layout Standard
18249
18250 gputils
18251 \begin_inset LatexCommand \index{gputils (pic tools)}
18252
18253 \end_inset 
18254
18255
18256 \end_inset 
18257 </cell>
18258 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18259 \begin_inset Text
18260
18261 \layout Standard
18262
18263 GNU PIC utilities
18264 \end_inset 
18265 </cell>
18266 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18267 \begin_inset Text
18268
18269 \layout Standard
18270
18271
18272 \begin_inset LatexCommand \url{http://gputils.sourceforge.net/}
18273
18274 \end_inset 
18275
18276
18277 \end_inset 
18278 </cell>
18279 </row>
18280 <row topline="true">
18281 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18282 \begin_inset Text
18283
18284 \layout Standard
18285
18286 flP5
18287 \end_inset 
18288 </cell>
18289 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18290 \begin_inset Text
18291
18292 \layout Standard
18293
18294 PIC programmer
18295 \end_inset 
18296 </cell>
18297 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18298 \begin_inset Text
18299
18300 \layout Standard
18301
18302
18303 \begin_inset LatexCommand \url{http://digilander.libero.it/fbradasc/FLP5.html}
18304
18305 \end_inset 
18306
18307
18308 \end_inset 
18309 </cell>
18310 </row>
18311 <row topline="true">
18312 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18313 \begin_inset Text
18314
18315 \layout Standard
18316
18317 indent
18318 \begin_inset LatexCommand \index{indent (source formatting tool)}
18319
18320 \end_inset 
18321
18322
18323 \end_inset 
18324 </cell>
18325 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18326 \begin_inset Text
18327
18328 \layout Standard
18329
18330 Formats C source - Master of the white spaces
18331 \end_inset 
18332 </cell>
18333 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18334 \begin_inset Text
18335
18336 \layout Standard
18337
18338
18339 \begin_inset LatexCommand \url{http://home.hccnet.nl/d.ingamells/beautify.html}
18340
18341 \end_inset 
18342
18343
18344 \end_inset 
18345 </cell>
18346 </row>
18347 <row topline="true">
18348 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18349 \begin_inset Text
18350
18351 \layout Standard
18352
18353 srecord
18354 \begin_inset LatexCommand \index{srecord (tool)}
18355
18356 \end_inset 
18357
18358
18359 \end_inset 
18360 </cell>
18361 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18362 \begin_inset Text
18363
18364 \layout Standard
18365
18366 Object file conversion, checksumming, ...
18367 \end_inset 
18368 </cell>
18369 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18370 \begin_inset Text
18371
18372 \layout Standard
18373
18374
18375 \begin_inset LatexCommand \url{http://srecord.sourceforge.net/}
18376
18377 \end_inset 
18378
18379
18380 \end_inset 
18381 </cell>
18382 </row>
18383 <row topline="true">
18384 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18385 \begin_inset Text
18386
18387 \layout Standard
18388
18389 objdump
18390 \begin_inset LatexCommand \index{objdump (tool)}
18391
18392 \end_inset 
18393
18394
18395 \end_inset 
18396 </cell>
18397 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18398 \begin_inset Text
18399
18400 \layout Standard
18401
18402 Object file conversion, ...
18403 \end_inset 
18404 </cell>
18405 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18406 \begin_inset Text
18407
18408 \layout Standard
18409
18410 Part of binutils (should be there anyway)
18411 \end_inset 
18412 </cell>
18413 </row>
18414 <row topline="true">
18415 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18416 \begin_inset Text
18417
18418 \layout Standard
18419
18420 doxygen
18421 \begin_inset LatexCommand \index{doxygen (source documentation tool)}
18422
18423 \end_inset 
18424
18425
18426 \end_inset 
18427 </cell>
18428 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18429 \begin_inset Text
18430
18431 \layout Standard
18432
18433 Source code documentation system
18434 \end_inset 
18435 </cell>
18436 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18437 \begin_inset Text
18438
18439 \layout Standard
18440
18441
18442 \begin_inset LatexCommand \url{http://www.doxygen.org}
18443
18444 \end_inset 
18445
18446
18447 \end_inset 
18448 </cell>
18449 </row>
18450 <row topline="true">
18451 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18452 \begin_inset Text
18453
18454 \layout Standard
18455
18456 kdevelop
18457 \end_inset 
18458 </cell>
18459 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18460 \begin_inset Text
18461
18462 \layout Standard
18463
18464 IDE (has anyone tried integrating SDCC & sdcdb? Unix only)
18465 \end_inset 
18466 </cell>
18467 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18468 \begin_inset Text
18469
18470 \layout Standard
18471
18472
18473 \begin_inset LatexCommand \url{http://www.kdevelop.org}
18474
18475 \end_inset 
18476
18477
18478 \end_inset 
18479 </cell>
18480 </row>
18481 <row topline="true">
18482 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18483 \begin_inset Text
18484
18485 \layout Standard
18486
18487 splint
18488 \begin_inset LatexCommand \index{splint (syntax checking tool)}
18489
18490 \end_inset 
18491
18492
18493 \end_inset 
18494 </cell>
18495 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18496 \begin_inset Text
18497
18498 \layout Standard
18499
18500 Statically checks c sources (has anyone adapted splint for SDCC?)
18501 \end_inset 
18502 </cell>
18503 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18504 \begin_inset Text
18505
18506 \layout Standard
18507
18508
18509 \begin_inset LatexCommand \url{http://www.splint.org}
18510
18511 \end_inset 
18512
18513
18514 \end_inset 
18515 </cell>
18516 </row>
18517 <row topline="true" bottomline="true">
18518 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18519 \begin_inset Text
18520
18521 \layout Standard
18522
18523 ddd
18524 \begin_inset LatexCommand \index{ddd (debugger)}
18525
18526 \end_inset 
18527
18528
18529 \end_inset 
18530 </cell>
18531 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18532 \begin_inset Text
18533
18534 \layout Standard
18535
18536 Debugger, serves nicely as GUI to sdcdb
18537 \begin_inset LatexCommand \index{sdcdb (debugger)}
18538
18539 \end_inset 
18540
18541  (Unix only)
18542 \end_inset 
18543 </cell>
18544 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18545 \begin_inset Text
18546
18547 \layout Standard
18548
18549
18550 \begin_inset LatexCommand \url{http://www.gnu.org/software/ddd/}
18551
18552 \end_inset 
18553
18554
18555 \end_inset 
18556 </cell>
18557 </row>
18558 </lyxtabular>
18559
18560 \end_inset 
18561
18562
18563 \newline 
18564
18565 \layout Section
18566
18567 Related documentation / recommended reading
18568 \layout Standard
18569 \align center 
18570
18571 \begin_inset  Tabular
18572 <lyxtabular version="3" rows="6" columns="3">
18573 <features>
18574 <column alignment="center" valignment="top" leftline="true" width="0pt">
18575 <column alignment="block" valignment="top" leftline="true" width="30line%">
18576 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
18577 <row topline="true" bottomline="true">
18578 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18579 \begin_inset Text
18580
18581 \layout Standard
18582
18583 Name
18584 \end_inset 
18585 </cell>
18586 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18587 \begin_inset Text
18588
18589 \layout Standard
18590
18591 Subject / Title
18592 \end_inset 
18593 </cell>
18594 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18595 \begin_inset Text
18596
18597 \layout Standard
18598
18599 Where to get
18600 \end_inset 
18601 </cell>
18602 </row>
18603 <row topline="true">
18604 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18605 \begin_inset Text
18606
18607 \layout Standard
18608
18609
18610 \family roman 
18611 \series medium 
18612 \shape up 
18613 \size normal 
18614 \emph off 
18615 \bar no 
18616 \noun off 
18617 \color none
18618 c-refcard.pdf
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 C Reference Card
18627 \begin_inset LatexCommand \index{C Reference card}
18628
18629 \end_inset 
18630
18631 , 2 pages
18632 \end_inset 
18633 </cell>
18634 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18635 \begin_inset Text
18636
18637 \layout Standard
18638
18639
18640 \begin_inset LatexCommand \url{http://www.refcards.com/about/c.html}
18641
18642 \end_inset 
18643
18644
18645 \end_inset 
18646 </cell>
18647 </row>
18648 <row topline="true">
18649 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18650 \begin_inset Text
18651
18652 \layout Standard
18653
18654 c-faq
18655 \end_inset 
18656 </cell>
18657 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18658 \begin_inset Text
18659
18660 \layout Standard
18661
18662 C-FAQ-list
18663 \end_inset 
18664 </cell>
18665 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18666 \begin_inset Text
18667
18668 \layout Standard
18669
18670
18671 \begin_inset LatexCommand \url{http://www.eskimo.com/~scs/C-faq/top.html}
18672
18673 \end_inset 
18674
18675
18676 \end_inset 
18677 </cell>
18678 </row>
18679 <row topline="true">
18680 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18681 \begin_inset Text
18682
18683 \layout Standard
18684
18685 \end_inset 
18686 </cell>
18687 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18688 \begin_inset Text
18689
18690 \layout Standard
18691
18692 Latest datasheet of the target CPU
18693 \end_inset 
18694 </cell>
18695 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18696 \begin_inset Text
18697
18698 \layout Standard
18699
18700 vendor
18701 \end_inset 
18702 </cell>
18703 </row>
18704 <row topline="true">
18705 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18706 \begin_inset Text
18707
18708 \layout Standard
18709
18710 \end_inset 
18711 </cell>
18712 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18713 \begin_inset Text
18714
18715 \layout Standard
18716
18717 Revision history of datasheet
18718 \end_inset 
18719 </cell>
18720 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18721 \begin_inset Text
18722
18723 \layout Standard
18724
18725 vendor
18726 \end_inset 
18727 </cell>
18728 </row>
18729 <row topline="true" bottomline="true">
18730 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18731 \begin_inset Text
18732
18733 \layout Standard
18734
18735 S.
18736  S.
18737  Muchnick
18738 \end_inset 
18739 </cell>
18740 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
18741 \begin_inset Text
18742
18743 \layout Standard
18744
18745 Advanced Compiler Design and Implementation
18746 \end_inset 
18747 </cell>
18748 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
18749 \begin_inset Text
18750
18751 \layout Standard
18752
18753 bookstore (very dedicated, probably read other books first)
18754 \end_inset 
18755 </cell>
18756 </row>
18757 </lyxtabular>
18758
18759 \end_inset 
18760
18761
18762 \newline 
18763
18764 \layout Section
18765
18766 Some Questions
18767 \layout Standard
18768
18769 Some questions answered, some pointers given - it might be time to in turn
18770  ask 
18771 \emph on 
18772 you
18773 \emph default 
18774  some questions: 
18775 \layout Itemize
18776
18777 can you solve your project with the selected microcontroller? Would you
18778  find out early or rather late that your target is too small/slow/whatever?
18779  Can you switch to a slightly better device if it doesn't fit?
18780 \layout Itemize
18781
18782 should you solve the problem with an 8 bit CPU? Or would a 16/32 bit CPU
18783  and/or another programming language be more adequate? Would an operating
18784  system on the target device help?
18785 \layout Itemize
18786
18787 if you solved the problem, will the marketing department be happy?
18788 \layout Itemize
18789
18790 if the marketing department is happy, will customers be happy?
18791 \layout Itemize
18792
18793 if you're the project manager, marketing department and maybe even the customer
18794  in one person, have you tried to see the project from the outside?
18795 \layout Itemize
18796
18797 is the project done if you think it is done? Or is just that other interface/pro
18798 tocol/feature/configuration/option missing? How about website, manual(s),
18799  internationali(z|s)ation, packaging, labels, 2nd source for components,
18800  electromagnetic compatability/interference, documentation for production,
18801  production test software, update mechanism, patent issues?
18802 \layout Itemize
18803
18804 is your project adequately positioned in that magic triangle: fame, fortune,
18805  fun?
18806 \layout Standard
18807
18808 Maybe not all answers to these questions are known and some answers may
18809  even be 
18810 \emph on 
18811 no
18812 \emph default 
18813 , nevertheless knowing these questions may help you to avoid burnout
18814 \begin_inset Foot
18815 collapsed false
18816
18817 \layout Standard
18818
18819 burnout is bad for electronic devices, programmers and motorcycle tyres
18820 \end_inset 
18821
18822 .
18823  Chances are you didn't want to hear some of them...
18824 \layout Chapter
18825
18826 Support
18827 \begin_inset LatexCommand \index{Support}
18828
18829 \end_inset 
18830
18831
18832 \layout Standard
18833
18834 SDCC has grown to be a large project.
18835  The compiler alone (without the preprocessor, assembler and linker) is
18836  well over 100,000 lines of code (blank stripped).
18837  The open source nature of this project is a key to its continued growth
18838  and support.
18839  You gain the benefit and support of many active software developers and
18840  end users.
18841  Is SDCC perfect? No, that's why we need your help.
18842  The developers take pride in fixing reported bugs.
18843  You can help by reporting the bugs and helping other SDCC users.
18844  There are lots of ways to contribute, and we encourage you to take part
18845  in making SDCC a great software package.
18846  
18847 \layout Standard
18848
18849 The SDCC project is hosted on the SDCC sourceforge site at 
18850 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/projects/sdcc}
18851
18852 \end_inset 
18853
18854 .
18855  You'll find the complete set of mailing lists
18856 \begin_inset LatexCommand \index{Mailing list(s)}
18857
18858 \end_inset 
18859
18860 , forums, bug reporting system, patch submission
18861 \begin_inset LatexCommand \index{Patch submission}
18862
18863 \end_inset 
18864
18865  system, download
18866 \begin_inset LatexCommand \index{download}
18867
18868 \end_inset 
18869
18870  area and cvs code repository
18871 \begin_inset LatexCommand \index{cvs code repository}
18872
18873 \end_inset 
18874
18875  there.
18876 \layout Section
18877
18878 Reporting Bugs
18879 \begin_inset LatexCommand \index{Bug reporting}
18880
18881 \end_inset 
18882
18883
18884 \begin_inset LatexCommand \index{Reporting bugs}
18885
18886 \end_inset 
18887
18888
18889 \layout Standard
18890
18891 The recommended way of reporting bugs is using the infrastructure of the
18892  sourceforge site.
18893  You can follow the status of bug reports there and have an overview about
18894  the known bugs.
18895 \layout Standard
18896
18897 Bug reports are automatically forwarded to the developer mailing list and
18898  will be fixed ASAP.
18899  When reporting a bug, it is very useful to include a small test program
18900  (the smaller the better) which reproduces the problem.
18901  If you can isolate the problem by looking at the generated assembly code,
18902  this can be very helpful.
18903  Compiling your program with the -
18904 \begin_inset ERT
18905 status Collapsed
18906
18907 \layout Standard
18908
18909 \backslash 
18910 /
18911 \end_inset 
18912
18913 -dumpall
18914 \begin_inset LatexCommand \index{-\/-dumpall}
18915
18916 \end_inset 
18917
18918  option can sometimes be useful in locating optimization problems.
18919  When reporting a bug please maker sure you:
18920 \layout Enumerate
18921
18922 Attach the code you are compiling with SDCC.
18923  
18924 \layout Enumerate
18925
18926 Specify the exact command you use to run SDCC, or attach your Makefile.
18927  
18928 \layout Enumerate
18929
18930 Specify the SDCC version (type "
18931 \family sans 
18932 \series bold 
18933 sdcc -v
18934 \family default 
18935 \series default 
18936 "), your platform, and operating system.
18937  
18938 \layout Enumerate
18939
18940 Provide an exact copy of any error message or incorrect output.
18941  
18942 \layout Enumerate
18943
18944 Put something meaningful in the subject of your message.
18945 \layout Standard
18946
18947 Please attempt to include these 5 important parts, as applicable, in all
18948  requests for support or when reporting any problems or bugs with SDCC.
18949  Though this will make your message lengthy, it will greatly improve your
18950  chance that SDCC users and developers will be able to help you.
18951  Some SDCC developers are frustrated by bug reports without code provided
18952  that they can use to reproduce and ultimately fix the problem, so please
18953  be sure to provide sample code if you are reporting a bug! 
18954 \layout Standard
18955
18956 Please have a short check that you are using a recent version of SDCC and
18957  the bug is not yet known.
18958  This is the link for reporting bugs: 
18959 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=100599}
18960
18961 \end_inset 
18962
18963 .
18964 \layout Section
18965
18966 Requesting Features
18967 \begin_inset LatexCommand \label{sub:Requesting-Features}
18968
18969 \end_inset 
18970
18971
18972 \begin_inset LatexCommand \index{Feature request}
18973
18974 \end_inset 
18975
18976
18977 \begin_inset LatexCommand \index{Requesting features}
18978
18979 \end_inset 
18980
18981
18982 \layout Standard
18983
18984 Like bug reports feature requests are forwarded to the developer mailing
18985  list.
18986  This is the link for requesting features: 
18987 \begin_inset LatexCommand \htmlurl{http://sourceforge.net/tracker/?group_id=599&atid=350599}
18988
18989 \end_inset 
18990
18991 .
18992 \layout Section
18993
18994 Submitting patches
18995 \layout Standard
18996
18997 Like bug reports contributed patches are forwarded to the developer mailing
18998  list.
18999  This is the link for submitting patches
19000 \begin_inset LatexCommand \index{Patch submission}
19001
19002 \end_inset 
19003
19004
19005 \begin_inset LatexCommand \url{http://sourceforge.net/tracker/?group_id=599&atid=300599}
19006
19007 \end_inset 
19008
19009 .
19010 \layout Standard
19011
19012 You need to specify some parameters to the 
19013 \family typewriter 
19014 diff
19015 \family default 
19016  command for the patches to be useful.
19017  If you modified more than one file a patch created f.e.
19018  with 
19019 \family sans 
19020 \series bold 
19021
19022 \begin_inset Quotes sld
19023 \end_inset 
19024
19025 diff -Naur unmodified_directory modified_directory >my_changes.patch
19026 \begin_inset Quotes srd
19027 \end_inset 
19028
19029
19030 \family default 
19031 \series default 
19032  will be fine, otherwise 
19033 \family sans 
19034 \series bold 
19035
19036 \begin_inset Quotes sld
19037 \end_inset 
19038
19039 diff -u sourcefile.c.orig sourcefile.c >my_changes.patch
19040 \begin_inset Quotes srd
19041 \end_inset 
19042
19043
19044 \series default 
19045  
19046 \family default 
19047 will do.
19048 \layout Section
19049
19050 Getting Help
19051 \layout Standard
19052
19053 These links should take you directly to the 
19054 \begin_inset LatexCommand \url[Mailing lists]{http://sourceforge.net/mail/?group_id=599}
19055
19056 \end_inset 
19057
19058
19059 \begin_inset Foot
19060 collapsed false
19061
19062 \layout Standard
19063
19064 Traffic on sdcc-devel and sdcc-user is about 100 mails/month each not counting
19065  automated messages (mid 2003)
19066 \end_inset 
19067
19068  and the 
19069 \begin_inset LatexCommand \url[Forums]{http://sourceforge.net/forum/?group_id=599}
19070
19071 \end_inset 
19072
19073 , lists
19074 \begin_inset LatexCommand \index{Mailing list(s)}
19075
19076 \end_inset 
19077
19078  and forums are archived and searchable so if you are lucky someone already
19079  had a similar problem.
19080  While mails to the lists themselves are delivered promptly their web front
19081  end on sourceforge sometimes shows a severe time lag (up to several weeks),
19082  if you're seriously using SDCC please consider subscribing to the lists.
19083 \layout Section
19084
19085 ChangeLog
19086 \layout Standard
19087
19088 You can follow the status of the cvs version
19089 \begin_inset LatexCommand \index{version}
19090
19091 \end_inset 
19092
19093  of SDCC by watching the Changelog
19094 \begin_inset LatexCommand \index{Changelog}
19095
19096 \end_inset 
19097
19098  in the cvs-repository
19099 \newline 
19100
19101 \size footnotesize 
19102
19103 \begin_inset LatexCommand \htmlurl{http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/*checkout*/sdcc/sdcc/ChangeLog?rev=HEAD&content-type=text/plain}
19104
19105 \end_inset 
19106
19107 .
19108 \layout Section
19109
19110 Release policy
19111 \begin_inset LatexCommand \index{Release policy}
19112
19113 \end_inset 
19114
19115
19116 \layout Standard
19117
19118 Historically there often were long delays between official releases and
19119  the sourceforge download area tends to get not updated at all.
19120  Excuses in the past might have referred to problems with live range analysis,
19121  but as this was fixed a while ago, the current problem is that another
19122  excuse has to be found.
19123  Kidding aside, we have to get better there! On the other hand there are
19124  daily snapshots available at 
19125 \begin_inset LatexCommand \htmlurl[snap]{http://sdcc.sourceforge.net/snap.php}
19126
19127 \end_inset 
19128
19129 , and you can always build the very last version (hopefully with many bugs
19130  fixed, and features added) from the source code available at 
19131 \begin_inset LatexCommand \htmlurl[Source]{http://sdcc.sourceforge.net/snap.php#Source}
19132
19133 \end_inset 
19134
19135 .
19136 \layout Section
19137
19138 Examples
19139 \begin_inset LatexCommand \index{Examples}
19140
19141 \end_inset 
19142
19143
19144 \layout Standard
19145
19146 You'll find some small examples in the directory 
19147 \emph on 
19148 sdcc/device/examples/.
19149  
19150 \emph default 
19151 More examples and libraries are available at
19152 \emph on 
19153  The SDCC Open Knowledge Resource 
19154 \begin_inset LatexCommand \url{http://www.qsl.net/dl9sec/SDCC_OKR.html}
19155
19156 \end_inset 
19157
19158  
19159 \emph default 
19160 web site or at 
19161 \begin_inset LatexCommand \url{http://www.pjrc.com/tech/8051/}
19162
19163 \end_inset 
19164
19165 .
19166 \layout Comment
19167
19168 I did insert a reference to Paul's web site here although it seems rather
19169  dedicated to a specific 8032 board (I think it's okay because it f.e.
19170  shows LCD/Harddisc interface and has a free 8051 monitor.
19171  Independent 8032 board vendors face hard competition of heavily subsidized
19172  development boards anyway).
19173 \layout Comment
19174
19175 Maybe we should include some links to real world applications.
19176  Preferably pointer to pointers (one for each architecture) so this stays
19177  manageable here?
19178 \layout Section
19179
19180 Quality control
19181 \begin_inset LatexCommand \index{Quality control}
19182
19183 \end_inset 
19184
19185
19186 \layout Standard
19187
19188 The compiler is passed through nightly compile and build checks.
19189  The so called 
19190 \shape italic 
19191 regression tests
19192 \shape default 
19193
19194 \begin_inset LatexCommand \index{Regression test}
19195
19196 \end_inset 
19197
19198  check that SDCC itself compiles flawlessly on several platforms and checks
19199  the quality of the code generated by SDCC by running the code through simulator
19200 s.
19201  There is a separate document 
19202 \shape italic 
19203 test_suite.pdf
19204 \begin_inset LatexCommand \index{Test suite}
19205
19206 \end_inset 
19207
19208
19209 \shape default 
19210  about this.
19211 \layout Standard
19212
19213 You'll find the test code in the directory 
19214 \shape italic 
19215 sdcc/support/regression
19216 \shape default 
19217 .
19218  You can run these tests manually by running 
19219 \family sans 
19220 make
19221 \family default 
19222  in this directory (or f.e.
19223  
19224 \family sans 
19225 \series bold 
19226
19227 \begin_inset Quotes sld
19228 \end_inset 
19229
19230 make test-mcs51
19231 \begin_inset Quotes srd
19232 \end_inset 
19233
19234
19235 \family default 
19236 \series default 
19237  if you don't want to run the complete tests).
19238  The test code might also be interesting if you want to look for examples
19239 \begin_inset LatexCommand \index{Examples}
19240
19241 \end_inset 
19242
19243  checking corner cases of SDCC or if you plan to submit patches
19244 \begin_inset LatexCommand \index{Patch submission}
19245
19246 \end_inset 
19247
19248 .
19249 \layout Standard
19250
19251 The pic port uses a different set of regression tests, you'll find them
19252  in the directory 
19253 \shape italic 
19254 sdcc/src/regression
19255 \shape default 
19256 .
19257 \layout Chapter
19258 \pagebreak_top 
19259 SDCC Technical Data
19260 \layout Section
19261
19262 Optimizations
19263 \begin_inset LatexCommand \index{Optimizations}
19264
19265 \end_inset 
19266
19267
19268 \layout Standard
19269
19270 SDCC performs a host of standard optimizations in addition to some MCU specific
19271  optimizations.
19272  
19273 \layout Subsection
19274
19275 Sub-expression Elimination
19276 \begin_inset LatexCommand \index{Subexpression elimination}
19277
19278 \end_inset 
19279
19280
19281 \layout Standard
19282
19283 The compiler does local and 
19284 \emph on 
19285 g
19286 \emph default 
19287 lobal 
19288 \emph on 
19289 c
19290 \emph default 
19291 ommon 
19292 \emph on 
19293 s
19294 \emph default 
19295 ubexpression 
19296 \emph on 
19297 e
19298 \emph default 
19299 limination, e.g.: 
19300 \layout Verse
19301
19302
19303 \family typewriter 
19304 i = x + y + 1; 
19305 \newline 
19306 j = x + y;
19307 \layout Standard
19308
19309 will be translated to
19310 \layout Verse
19311
19312
19313 \family typewriter 
19314 iTemp = x + y; 
19315 \newline 
19316 i = iTemp + 1; 
19317 \newline 
19318 j = iTemp;
19319 \layout Standard
19320
19321 Some subexpressions are not as obvious as the above example, e.g.:
19322 \layout Verse
19323
19324
19325 \family typewriter 
19326 a->b[i].c = 10; 
19327 \newline 
19328 a->b[i].d = 11;
19329 \layout Standard
19330
19331 In this case the address arithmetic a->b[i] will be computed only once;
19332  the equivalent code in C would be.
19333 \layout Verse
19334
19335
19336 \family typewriter 
19337 iTemp = a->b[i]; 
19338 \newline 
19339 iTemp.c = 10; 
19340 \newline 
19341 iTemp.d = 11;
19342 \layout Standard
19343
19344 The compiler will try to keep these temporary variables in registers.
19345 \layout Subsection
19346
19347 Dead-Code Elimination
19348 \begin_inset LatexCommand \index{Dead-code elimination}
19349
19350 \end_inset 
19351
19352
19353 \layout Verse
19354
19355
19356 \family typewriter 
19357 int global;
19358 \newline 
19359
19360 \newline 
19361 void f () { 
19362 \newline 
19363 \SpecialChar ~
19364 \SpecialChar ~
19365 int i; 
19366 \newline 
19367 \SpecialChar ~
19368 \SpecialChar ~
19369 i = 1; \SpecialChar ~
19370 \SpecialChar ~
19371 \SpecialChar ~
19372 \SpecialChar ~
19373 \SpecialChar ~
19374 /* dead store */ 
19375 \newline 
19376 \SpecialChar ~
19377 \SpecialChar ~
19378 global = 1;\SpecialChar ~
19379 /* dead store */ 
19380 \newline 
19381 \SpecialChar ~
19382 \SpecialChar ~
19383 global = 2; 
19384 \newline 
19385 \SpecialChar ~
19386 \SpecialChar ~
19387 return; 
19388 \newline 
19389 \SpecialChar ~
19390 \SpecialChar ~
19391 global = 3;\SpecialChar ~
19392 /* unreachable */ 
19393 \newline 
19394 }
19395 \layout Standard
19396
19397 will be changed to
19398 \layout Verse
19399
19400
19401 \family typewriter 
19402 int global;
19403 \newline 
19404
19405 \newline 
19406 void f () {
19407 \newline 
19408 \SpecialChar ~
19409 \SpecialChar ~
19410 global = 2; 
19411 \newline 
19412 \SpecialChar ~
19413 \SpecialChar ~
19414 return; 
19415 \newline 
19416 }
19417 \layout Subsection
19418
19419 Copy-Propagation
19420 \begin_inset LatexCommand \index{Copy propagation}
19421
19422 \end_inset 
19423
19424
19425 \layout Verse
19426
19427
19428 \family typewriter 
19429 int f() { 
19430 \newline 
19431 \SpecialChar ~
19432 \SpecialChar ~
19433 int i, j; 
19434 \newline 
19435 \SpecialChar ~
19436 \SpecialChar ~
19437 i = 10; 
19438 \newline 
19439 \SpecialChar ~
19440 \SpecialChar ~
19441 j = i; 
19442 \newline 
19443 \SpecialChar ~
19444 \SpecialChar ~
19445 return j; 
19446 \newline 
19447 }
19448 \layout Standard
19449
19450 will be changed to 
19451 \layout Verse
19452
19453
19454 \family typewriter 
19455 int f() { 
19456 \newline 
19457 \SpecialChar ~
19458 \SpecialChar ~
19459 int i, j; 
19460 \newline 
19461 \SpecialChar ~
19462 \SpecialChar ~
19463 i = 10; 
19464 \newline 
19465 \SpecialChar ~
19466 \SpecialChar ~
19467 j = 10; 
19468 \newline 
19469 \SpecialChar ~
19470 \SpecialChar ~
19471 return 10; 
19472 \newline 
19473 }
19474 \layout Standard
19475
19476 Note: the dead stores created by this copy propagation will be eliminated
19477  by dead-code elimination.
19478 \layout Subsection
19479
19480 Loop Optimizations
19481 \begin_inset LatexCommand \index{Loop optimization}
19482
19483 \end_inset 
19484
19485
19486 \begin_inset LatexCommand \label{sub:Loop-Optimizations}
19487
19488 \end_inset 
19489
19490
19491 \layout Standard
19492
19493 Two types of loop optimizations are done by SDCC 
19494 \emph on 
19495 loop invariant
19496 \emph default 
19497  lifting and
19498 \emph on 
19499  strength reduction
19500 \emph default 
19501  of loop induction variables.
19502  In addition to the strength reduction the optimizer marks the induction
19503  variables and the register allocator tries to keep the induction variables
19504  in registers for the duration of the loop.
19505  Because of this preference of the register allocator
19506 \begin_inset LatexCommand \index{Register allocation}
19507
19508 \end_inset 
19509
19510 , loop induction optimization causes an increase in register pressure, which
19511  may cause unwanted spilling of other temporary variables into the stack
19512 \begin_inset LatexCommand \index{stack}
19513
19514 \end_inset 
19515
19516  / data space.
19517  The compiler will generate a warning message when it is forced to allocate
19518  extra space either on the stack or data space.
19519  If this extra space allocation is undesirable then induction optimization
19520  can be eliminated either for the entire source file (with -
19521 \begin_inset ERT
19522 status Collapsed
19523
19524 \layout Standard
19525
19526 \backslash 
19527 /
19528 \end_inset 
19529
19530 -noinduction option) or for a given function only using #pragma\SpecialChar ~
19531 noinduction
19532 \begin_inset LatexCommand \index{\#pragma noinduction}
19533
19534 \end_inset 
19535
19536 .
19537 \newline 
19538
19539 \newline 
19540 Loop Invariant:
19541 \layout Verse
19542
19543
19544 \family typewriter 
19545 for (i = 0 ; i < 100 ; i ++) 
19546 \newline 
19547 \SpecialChar ~
19548 \SpecialChar ~
19549 \SpecialChar ~
19550 \SpecialChar ~
19551 f += k + l;
19552 \layout Standard
19553
19554 changed to
19555 \layout Verse
19556
19557
19558 \family typewriter 
19559 itemp = k + l; 
19560 \newline 
19561 for (i = 0; i < 100; i++) 
19562 \newline 
19563 \SpecialChar ~
19564 \SpecialChar ~
19565 \SpecialChar ~
19566 \SpecialChar ~
19567 f += itemp;
19568 \layout Standard
19569
19570 As mentioned previously some loop invariants are not as apparent, all static
19571  address computations are also moved out of the loop.
19572 \newline 
19573
19574 \newline 
19575 Strength Reduction
19576 \begin_inset LatexCommand \index{Strength reduction}
19577
19578 \end_inset 
19579
19580 , this optimization substitutes an expression by a cheaper expression:
19581 \layout Verse
19582
19583
19584 \family typewriter 
19585 for (i=0;i < 100; i++)
19586 \newline 
19587 \SpecialChar ~
19588 \SpecialChar ~
19589 \SpecialChar ~
19590 \SpecialChar ~
19591 ar[i*5] = i*3;
19592 \layout Standard
19593
19594 changed to
19595 \layout Verse
19596
19597
19598 \family typewriter 
19599 itemp1 = 0; 
19600 \newline 
19601 itemp2 = 0; 
19602 \newline 
19603 for (i=0;i< 100;i++) { 
19604 \newline 
19605 \SpecialChar ~
19606 \SpecialChar ~
19607 \SpecialChar ~
19608 \SpecialChar ~
19609 ar[itemp1] = itemp2; 
19610 \newline 
19611 \SpecialChar ~
19612 \SpecialChar ~
19613 \SpecialChar ~
19614 \SpecialChar ~
19615 itemp1 += 5; 
19616 \newline 
19617 \SpecialChar ~
19618 \SpecialChar ~
19619 \SpecialChar ~
19620 \SpecialChar ~
19621 itemp2 += 3; 
19622 \newline 
19623 }
19624 \layout Standard
19625
19626 The more expensive multiplication
19627 \begin_inset LatexCommand \index{Multiplication}
19628
19629 \end_inset 
19630
19631  is changed to a less expensive addition.
19632 \layout Subsection
19633
19634 Loop Reversing
19635 \begin_inset LatexCommand \index{Loop reversing}
19636
19637 \end_inset 
19638
19639
19640 \layout Standard
19641
19642 This optimization is done to reduce the overhead of checking loop boundaries
19643  for every iteration.
19644  Some simple loops can be reversed and implemented using a 
19645 \begin_inset Quotes eld
19646 \end_inset 
19647
19648 decrement and jump if not zero
19649 \begin_inset Quotes erd
19650 \end_inset 
19651
19652  instruction.
19653  SDCC checks for the following criterion to determine if a loop is reversible
19654  (note: more sophisticated compilers use data-dependency analysis to make
19655  this determination, SDCC uses a more simple minded analysis).
19656 \layout Itemize
19657
19658 The 'for' loop is of the form 
19659 \newline 
19660
19661 \newline 
19662
19663 \family typewriter 
19664 for(<symbol> = <expression>; <sym> [< | <=] <expression>; [<sym>++ | <sym>
19665  += 1])
19666 \newline 
19667 \SpecialChar ~
19668 \SpecialChar ~
19669 \SpecialChar ~
19670 \SpecialChar ~
19671 <for body>
19672 \layout Itemize
19673
19674 The <for body> does not contain 
19675 \begin_inset Quotes eld
19676 \end_inset 
19677
19678 continue
19679 \begin_inset Quotes erd
19680 \end_inset 
19681
19682  or 'break
19683 \begin_inset Quotes erd
19684 \end_inset 
19685
19686 .
19687 \layout Itemize
19688
19689 All goto's are contained within the loop.
19690 \layout Itemize
19691
19692 No function calls within the loop.
19693 \layout Itemize
19694
19695 The loop control variable <sym> is not assigned any value within the loop
19696 \layout Itemize
19697
19698 The loop control variable does NOT participate in any arithmetic operation
19699  within the loop.
19700 \layout Itemize
19701
19702 There are NO switch statements in the loop.
19703 \layout Subsection
19704
19705 Algebraic Simplifications
19706 \layout Standard
19707
19708 SDCC does numerous algebraic simplifications, the following is a small sub-set
19709  of these optimizations.
19710 \layout Verse
19711
19712
19713 \family typewriter 
19714 i = j + 0;\SpecialChar ~
19715 \SpecialChar ~
19716 \SpecialChar ~
19717 \SpecialChar ~
19718  /* changed to: */\SpecialChar ~
19719 \SpecialChar ~
19720 \SpecialChar ~
19721 \SpecialChar ~
19722  i = j; 
19723 \newline 
19724 i /= 2;\SpecialChar ~
19725 \SpecialChar ~
19726 \SpecialChar ~
19727 \SpecialChar ~
19728 \SpecialChar ~
19729 \SpecialChar ~
19730 \SpecialChar ~
19731  /* changed to: */\SpecialChar ~
19732 \SpecialChar ~
19733 \SpecialChar ~
19734 \SpecialChar ~
19735  i >>= 1; 
19736 \newline 
19737 i = j - j;\SpecialChar ~
19738 \SpecialChar ~
19739 \SpecialChar ~
19740 \SpecialChar ~
19741  /* changed to: */\SpecialChar ~
19742 \SpecialChar ~
19743 \SpecialChar ~
19744 \SpecialChar ~
19745  i = 0; 
19746 \newline 
19747 i = j / 1;\SpecialChar ~
19748 \SpecialChar ~
19749 \SpecialChar ~
19750 \SpecialChar ~
19751  /* changed to: */\SpecialChar ~
19752 \SpecialChar ~
19753 \SpecialChar ~
19754 \SpecialChar ~
19755  i = j;
19756 \layout Standard
19757
19758 Note the subexpressions
19759 \begin_inset LatexCommand \index{Subexpression}
19760
19761 \end_inset 
19762
19763  given above are generally introduced by macro expansions or as a result
19764  of copy/constant propagation.
19765 \layout Subsection
19766
19767 'switch' Statements
19768 \begin_inset LatexCommand \label{sub:'switch'-Statements}
19769
19770 \end_inset 
19771
19772
19773 \begin_inset LatexCommand \index{switch statement}
19774
19775 \end_inset 
19776
19777
19778 \layout Standard
19779
19780 SDCC changes switch statements to jump tables
19781 \begin_inset LatexCommand \index{jump tables}
19782
19783 \end_inset 
19784
19785  when the following conditions are true.
19786  
19787 \layout Itemize
19788
19789 The case labels are in numerical sequence, the labels need not be in order,
19790  and the starting number need not be one or zero.
19791 \begin_deeper 
19792 \layout Verse
19793
19794
19795 \family typewriter 
19796 switch(i) {\SpecialChar ~
19797 \SpecialChar ~
19798 \SpecialChar ~
19799 \SpecialChar ~
19800 \SpecialChar ~
19801 \SpecialChar ~
19802 \SpecialChar ~
19803 \SpecialChar ~
19804 \SpecialChar ~
19805 \SpecialChar ~
19806 \SpecialChar ~
19807 \SpecialChar ~
19808 \SpecialChar ~
19809 \SpecialChar ~
19810 \SpecialChar ~
19811 \SpecialChar ~
19812 \SpecialChar ~
19813 \SpecialChar ~
19814 \SpecialChar ~
19815 \SpecialChar ~
19816 \SpecialChar ~
19817 \SpecialChar ~
19818 \SpecialChar ~
19819 \SpecialChar ~
19820 \SpecialChar ~
19821 \SpecialChar ~
19822 switch (i) { 
19823 \newline 
19824 \SpecialChar ~
19825 \SpecialChar ~
19826 \SpecialChar ~
19827 case 4: ...\SpecialChar ~
19828 \SpecialChar ~
19829 \SpecialChar ~
19830 \SpecialChar ~
19831 \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 case 0: ...
19854  
19855 \newline 
19856 \SpecialChar ~
19857 \SpecialChar ~
19858 \SpecialChar ~
19859 case 5: ...\SpecialChar ~
19860 \SpecialChar ~
19861 \SpecialChar ~
19862 \SpecialChar ~
19863 \SpecialChar ~
19864 \SpecialChar ~
19865 \SpecialChar ~
19866 \SpecialChar ~
19867 \SpecialChar ~
19868 \SpecialChar ~
19869 \SpecialChar ~
19870 \SpecialChar ~
19871 \SpecialChar ~
19872 \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 case 1: ...
19886  
19887 \newline 
19888 \SpecialChar ~
19889 \SpecialChar ~
19890 \SpecialChar ~
19891 case 3: ...\SpecialChar ~
19892 \SpecialChar ~
19893 \SpecialChar ~
19894 \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 case 2: ...
19918  
19919 \newline 
19920 \SpecialChar ~
19921 \SpecialChar ~
19922 \SpecialChar ~
19923 case 6: ...\SpecialChar ~
19924 \SpecialChar ~
19925 \SpecialChar ~
19926 \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 case 3: ...
19950  
19951 \newline 
19952 }\SpecialChar ~
19953 \SpecialChar ~
19954 \SpecialChar ~
19955 \SpecialChar ~
19956 \SpecialChar ~
19957 \SpecialChar ~
19958 \SpecialChar ~
19959 \SpecialChar ~
19960 \SpecialChar ~
19961 \SpecialChar ~
19962 \SpecialChar ~
19963 \SpecialChar ~
19964 \SpecialChar ~
19965 \SpecialChar ~
19966 \SpecialChar ~
19967 \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 \SpecialChar ~
19985 \SpecialChar ~
19986 \SpecialChar ~
19987 \SpecialChar ~
19988 }
19989 \layout Standard
19990
19991 Both the above switch statements will be implemented using a jump-table.
19992  The example to the right side is slightly more efficient as the check for
19993  the lower boundary of the jump-table is not needed.
19994 \end_deeper 
19995 \layout Itemize
19996
19997 The number of case labels is at least three, since it takes two conditional
19998  statements to handle the boundary conditions.
19999 \layout Itemize
20000
20001 The number of case labels is less than 84, since each label takes 3 bytes
20002  and a jump-table can be utmost 256 bytes long.
20003 \layout Standard
20004
20005 Switch statements which have gaps in the numeric sequence or those that
20006  have more that 84 case labels can be split into more than one switch statement
20007  for efficient code generation, e.g.:
20008 \layout Verse
20009
20010
20011 \family typewriter 
20012 switch (i) { 
20013 \newline 
20014 \SpecialChar ~
20015 \SpecialChar ~
20016 case 1: ...
20017  
20018 \newline 
20019 \SpecialChar ~
20020 \SpecialChar ~
20021 case 2: ...
20022  
20023 \newline 
20024 \SpecialChar ~
20025 \SpecialChar ~
20026 case 3: ...
20027  
20028 \newline 
20029 \SpecialChar ~
20030 \SpecialChar ~
20031 case 4: ...
20032  
20033 \newline 
20034 \SpecialChar ~
20035 \SpecialChar ~
20036 case 9: ...
20037  
20038 \newline 
20039 \SpecialChar ~
20040 \SpecialChar ~
20041 case 10: ...
20042  
20043 \newline 
20044 \SpecialChar ~
20045 \SpecialChar ~
20046 case 11: ...
20047  
20048 \newline 
20049 \SpecialChar ~
20050 \SpecialChar ~
20051 case 12: ...
20052  
20053 \newline 
20054 }
20055 \layout Standard
20056
20057 If the above switch statement is broken down into two switch statements
20058 \layout Verse
20059
20060
20061 \family typewriter 
20062 switch (i) { 
20063 \newline 
20064 \SpecialChar ~
20065 \SpecialChar ~
20066 case 1: ...
20067  
20068 \newline 
20069 \SpecialChar ~
20070 \SpecialChar ~
20071 case 2: ...
20072  
20073 \newline 
20074 \SpecialChar ~
20075 \SpecialChar ~
20076 case 3: ...
20077  
20078 \newline 
20079 \SpecialChar ~
20080 \SpecialChar ~
20081 case 4: ...
20082  
20083 \newline 
20084 }
20085 \layout Standard
20086
20087 and
20088 \layout Verse
20089
20090
20091 \family typewriter 
20092 switch (i) { 
20093 \newline 
20094 \SpecialChar ~
20095 \SpecialChar ~
20096 case 9:\SpecialChar ~
20097 \SpecialChar ~
20098 ...
20099  
20100 \newline 
20101 \SpecialChar ~
20102 \SpecialChar ~
20103 case 10:\SpecialChar ~
20104 ...
20105  
20106 \newline 
20107 \SpecialChar ~
20108 \SpecialChar ~
20109 case 11:\SpecialChar ~
20110 ...
20111  
20112 \newline 
20113 \SpecialChar ~
20114 \SpecialChar ~
20115 case 12:\SpecialChar ~
20116 ...
20117  
20118 \newline 
20119 }
20120 \layout Standard
20121
20122 then both the switch statements will be implemented using jump-tables whereas
20123  the unmodified switch statement will not be.
20124  You might also consider inserting dummy cases 0 and 5 to 8 in this example.
20125  
20126 \newline 
20127 The pragma nojtbound
20128 \begin_inset LatexCommand \index{\#pragma nojtbound}
20129
20130 \end_inset 
20131
20132  can be used to turn off checking the 
20133 \emph on 
20134 j
20135 \emph default 
20136 ump 
20137 \emph on 
20138 t
20139 \emph default 
20140 able 
20141 \emph on 
20142 bound
20143 \emph default 
20144 aries.
20145  It has no effect if a default label is supplied.
20146  Use of this pragma is dangerous: if the switch argument is not matched
20147  by a case statement the processor will happily jump into Nirvana.
20148 \layout Subsection
20149
20150 Bit-shifting Operations
20151 \begin_inset LatexCommand \index{Bit shifting}
20152
20153 \end_inset 
20154
20155 .
20156 \layout Standard
20157
20158 Bit shifting is one of the most frequently used operation in embedded programmin
20159 g.
20160  SDCC tries to implement bit-shift operations in the most efficient way
20161  possible, e.g.:
20162 \layout Verse
20163
20164
20165 \family typewriter 
20166 unsigned char i;
20167 \newline 
20168 ...
20169  
20170 \newline 
20171 i >>= 4; 
20172 \newline 
20173 ...
20174 \layout Standard
20175
20176 generates the following code:
20177 \layout Verse
20178
20179
20180 \family typewriter 
20181 mov\SpecialChar ~
20182  a,_i 
20183 \newline 
20184 swap a 
20185 \newline 
20186 anl\SpecialChar ~
20187  a,#0x0f 
20188 \newline 
20189 mov\SpecialChar ~
20190  _i,a
20191 \layout Standard
20192
20193 In general SDCC will never setup a loop if the shift count is known.
20194  Another example:
20195 \layout Verse
20196
20197
20198 \family typewriter 
20199 unsigned int i; 
20200 \newline 
20201 ...
20202  
20203 \newline 
20204 i >>= 9; 
20205 \newline 
20206 ...
20207 \layout Standard
20208
20209 will generate:
20210 \layout Verse
20211
20212
20213 \family typewriter 
20214 mov\SpecialChar ~
20215 \SpecialChar ~
20216 a,(_i + 1) 
20217 \newline 
20218 mov\SpecialChar ~
20219 \SpecialChar ~
20220 (_i + 1),#0x00 
20221 \newline 
20222 clr\SpecialChar ~
20223 \SpecialChar ~
20224
20225 \newline 
20226 rrc\SpecialChar ~
20227 \SpecialChar ~
20228
20229 \newline 
20230 mov\SpecialChar ~
20231 \SpecialChar ~
20232 _i,a
20233 \layout Subsection
20234
20235 Bit-rotation
20236 \begin_inset LatexCommand \index{Bit rotation}
20237
20238 \end_inset 
20239
20240
20241 \layout Standard
20242
20243 A special case of the bit-shift operation is bit rotation
20244 \begin_inset LatexCommand \index{rotating bits}
20245
20246 \end_inset 
20247
20248 , SDCC recognizes the following expression to be a left bit-rotation:
20249 \layout Verse
20250
20251
20252 \family typewriter 
20253 \series bold 
20254 unsigned
20255 \series default 
20256 \SpecialChar ~
20257 \SpecialChar ~
20258 char i;\SpecialChar ~
20259 \SpecialChar ~
20260 \SpecialChar ~
20261 \SpecialChar ~
20262 \SpecialChar ~
20263 \SpecialChar ~
20264 \SpecialChar ~
20265 \SpecialChar ~
20266 \SpecialChar ~
20267 \SpecialChar ~
20268 \SpecialChar ~
20269 /* unsigned is needed for rotation */ 
20270 \newline 
20271 ...
20272  
20273 \newline 
20274 i = ((i << 1) | (i >> 7)); 
20275 \family default 
20276
20277 \newline 
20278
20279 \family typewriter 
20280 ...
20281 \layout Standard
20282
20283 will generate the following code:
20284 \layout Verse
20285
20286
20287 \family typewriter 
20288 mov\SpecialChar ~
20289 \SpecialChar ~
20290 a,_i 
20291 \newline 
20292 rl\SpecialChar ~
20293 \SpecialChar ~
20294 \SpecialChar ~
20295
20296 \newline 
20297 mov\SpecialChar ~
20298 \SpecialChar ~
20299 _i,a
20300 \layout Standard
20301
20302 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
20303 ns of this case will also be recognized as bit-rotation, i.e.: 
20304 \layout Verse
20305
20306
20307 \family typewriter 
20308 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
20309 \layout Subsection
20310
20311 Nibble and Byte Swapping
20312 \layout Standard
20313
20314 Other special cases of the bit-shift operations are nibble or byte swapping
20315 \begin_inset LatexCommand \index{swapping nibbles/bytes}
20316
20317 \end_inset 
20318
20319 , SDCC recognizes the following expressions:
20320 \layout Verse
20321
20322
20323 \family typewriter 
20324 \series bold 
20325 unsigned
20326 \series default 
20327 \SpecialChar ~
20328 \SpecialChar ~
20329 char i; 
20330 \newline 
20331
20332 \series bold 
20333 unsigned
20334 \series default 
20335 \SpecialChar ~
20336 \SpecialChar ~
20337 int j; 
20338 \newline 
20339 ...
20340  
20341 \newline 
20342 i = ((i << 4) | (i >> 4)); 
20343 \family default 
20344
20345 \newline 
20346
20347 \family typewriter 
20348 j = ((j << 8) | (j >> 8)); 
20349 \layout Standard
20350
20351 and generates a swap instruction for the nibble swapping
20352 \begin_inset LatexCommand \index{Nibble swapping}
20353
20354 \end_inset 
20355
20356  or move instructions for the byte swapping
20357 \begin_inset LatexCommand \index{Byte swapping}
20358
20359 \end_inset 
20360
20361 .
20362  The 
20363 \begin_inset Quotes sld
20364 \end_inset 
20365
20366 j
20367 \begin_inset Quotes srd
20368 \end_inset 
20369
20370  example can be used to convert from little to big-endian or vice versa.
20371  If you want to change the endianness of a 
20372 \emph on 
20373 signed
20374 \emph default 
20375  integer you have to cast to 
20376 \family typewriter 
20377 (unsigned int)
20378 \family default 
20379  first.
20380 \layout Standard
20381
20382 Note that SDCC stores numbers in little-endian
20383 \begin_inset Foot
20384 collapsed false
20385
20386 \layout Standard
20387
20388 Usually 8-bit processors don't care much about endianness.
20389  This is not the case for the standard 8051 which only has an instruction
20390  to increment its 
20391 \emph on 
20392 dptr
20393 \emph default 
20394
20395 \begin_inset LatexCommand \index{DPTR}
20396
20397 \end_inset 
20398
20399 -datapointer
20400 \emph on 
20401  
20402 \emph default 
20403 so little-endian is the more efficient byte order.
20404 \end_inset 
20405
20406
20407 \begin_inset LatexCommand \index{little-endian}
20408
20409 \end_inset 
20410
20411
20412 \begin_inset LatexCommand \index{Endianness}
20413
20414 \end_inset 
20415
20416  format (i.e.
20417  lowest order first).
20418 \layout Subsection
20419
20420 Highest Order Bit
20421 \begin_inset LatexCommand \index{Highest Order Bit}
20422
20423 \end_inset 
20424
20425
20426 \layout Standard
20427
20428 It is frequently required to obtain the highest order bit of an integral
20429  type (long, int, short or char types).
20430  SDCC recognizes the following expression to yield the highest order bit
20431  and generates optimized code for it, e.g.:
20432 \layout Verse
20433
20434
20435 \family typewriter 
20436 unsigned int gint; 
20437 \newline 
20438
20439 \newline 
20440 foo () { 
20441 \newline 
20442 \SpecialChar ~
20443 \SpecialChar ~
20444 unsigned char hob; 
20445 \newline 
20446 \SpecialChar ~
20447 \SpecialChar ~
20448 ...
20449  
20450 \newline 
20451 \SpecialChar ~
20452 \SpecialChar ~
20453 hob = (gint >> 15) & 1; 
20454 \newline 
20455 \SpecialChar ~
20456 \SpecialChar ~
20457 ..
20458  
20459 \newline 
20460 }
20461 \layout Standard
20462
20463 will generate the following code:
20464 \layout Verse
20465
20466
20467 \family typewriter 
20468 \SpecialChar ~
20469 \SpecialChar ~
20470 \SpecialChar ~
20471 \SpecialChar ~
20472 \SpecialChar ~
20473 \SpecialChar ~
20474 \SpecialChar ~
20475 \SpecialChar ~
20476 \SpecialChar ~
20477 \SpecialChar ~
20478 \SpecialChar ~
20479 \SpecialChar ~
20480 \SpecialChar ~
20481 \SpecialChar ~
20482 \SpecialChar ~
20483 \SpecialChar ~
20484 \SpecialChar ~
20485 \SpecialChar ~
20486 \SpecialChar ~
20487 \SpecialChar ~
20488 \SpecialChar ~
20489 \SpecialChar ~
20490 \SpecialChar ~
20491 \SpecialChar ~
20492 \SpecialChar ~
20493  61 ;\SpecialChar ~
20494  hob.c 7 
20495 \newline 
20496 000A E5*01\SpecialChar ~
20497 \SpecialChar ~
20498 \SpecialChar ~
20499 \SpecialChar ~
20500 \SpecialChar ~
20501 \SpecialChar ~
20502 \SpecialChar ~
20503 \SpecialChar ~
20504 \SpecialChar ~
20505 \SpecialChar ~
20506 \SpecialChar ~
20507 \SpecialChar ~
20508 \SpecialChar ~
20509 \SpecialChar ~
20510 \SpecialChar ~
20511  62\SpecialChar ~
20512 \SpecialChar ~
20513 \SpecialChar ~
20514 \SpecialChar ~
20515 \SpecialChar ~
20516 \SpecialChar ~
20517 \SpecialChar ~
20518 \SpecialChar ~
20519  mov\SpecialChar ~
20520 \SpecialChar ~
20521  a,(_gint + 1) 
20522 \newline 
20523 000C 23\SpecialChar ~
20524 \SpecialChar ~
20525 \SpecialChar ~
20526 \SpecialChar ~
20527 \SpecialChar ~
20528 \SpecialChar ~
20529 \SpecialChar ~
20530 \SpecialChar ~
20531 \SpecialChar ~
20532 \SpecialChar ~
20533 \SpecialChar ~
20534 \SpecialChar ~
20535 \SpecialChar ~
20536 \SpecialChar ~
20537 \SpecialChar ~
20538 \SpecialChar ~
20539 \SpecialChar ~
20540 \SpecialChar ~
20541  63\SpecialChar ~
20542 \SpecialChar ~
20543 \SpecialChar ~
20544 \SpecialChar ~
20545 \SpecialChar ~
20546 \SpecialChar ~
20547 \SpecialChar ~
20548 \SpecialChar ~
20549  rl\SpecialChar ~
20550 \SpecialChar ~
20551 \SpecialChar ~
20552  a 
20553 \newline 
20554 000D 54 01\SpecialChar ~
20555 \SpecialChar ~
20556 \SpecialChar ~
20557 \SpecialChar ~
20558 \SpecialChar ~
20559 \SpecialChar ~
20560 \SpecialChar ~
20561 \SpecialChar ~
20562 \SpecialChar ~
20563 \SpecialChar ~
20564 \SpecialChar ~
20565 \SpecialChar ~
20566 \SpecialChar ~
20567 \SpecialChar ~
20568 \SpecialChar ~
20569  64\SpecialChar ~
20570 \SpecialChar ~
20571 \SpecialChar ~
20572 \SpecialChar ~
20573 \SpecialChar ~
20574 \SpecialChar ~
20575 \SpecialChar ~
20576 \SpecialChar ~
20577  anl\SpecialChar ~
20578 \SpecialChar ~
20579  a,#0x01 
20580 \newline 
20581 000F F5*02\SpecialChar ~
20582 \SpecialChar ~
20583 \SpecialChar ~
20584 \SpecialChar ~
20585 \SpecialChar ~
20586 \SpecialChar ~
20587 \SpecialChar ~
20588 \SpecialChar ~
20589 \SpecialChar ~
20590 \SpecialChar ~
20591 \SpecialChar ~
20592 \SpecialChar ~
20593 \SpecialChar ~
20594 \SpecialChar ~
20595 \SpecialChar ~
20596  65\SpecialChar ~
20597 \SpecialChar ~
20598 \SpecialChar ~
20599 \SpecialChar ~
20600 \SpecialChar ~
20601 \SpecialChar ~
20602 \SpecialChar ~
20603 \SpecialChar ~
20604  mov\SpecialChar ~
20605 \SpecialChar ~
20606  _foo_hob_1_1,a
20607 \layout Standard
20608
20609 Variations of this case however will 
20610 \emph on 
20611 not
20612 \emph default 
20613  be recognized.
20614  It is a standard C expression, so I heartily recommend this be the only
20615  way to get the highest order bit, (it is portable).
20616  Of course it will be recognized even if it is embedded in other expressions,
20617  e.g.:
20618 \layout Verse
20619
20620
20621 \family typewriter 
20622 xyz = gint + ((gint >> 15) & 1);
20623 \layout Standard
20624
20625 will still be recognized.
20626 \layout Subsection
20627
20628 Peephole Optimizer
20629 \begin_inset LatexCommand \label{sub:Peephole-Optimizer}
20630
20631 \end_inset 
20632
20633
20634 \begin_inset LatexCommand \index{Peephole optimizer}
20635
20636 \end_inset 
20637
20638
20639 \layout Standard
20640
20641 The compiler uses a rule based, pattern matching and re-writing mechanism
20642  for peep-hole optimization.
20643  It is inspired by 
20644 \emph on 
20645 copt
20646 \emph default 
20647  a peep-hole optimizer by Christopher W.
20648  Fraser (cwfraser@microsoft.com).
20649  A default set of rules are compiled into the compiler, additional rules
20650  may be added with the 
20651 \emph on 
20652 -
20653 \begin_inset ERT
20654 status Collapsed
20655
20656 \layout Standard
20657
20658 \backslash 
20659 /
20660 \end_inset 
20661
20662 -peep-file
20663 \begin_inset LatexCommand \index{-\/-peep-file}
20664
20665 \end_inset 
20666
20667  <filename>
20668 \emph default 
20669  option.
20670  The rule language is best illustrated with examples.
20671 \layout Verse
20672
20673
20674 \family typewriter 
20675 replace { 
20676 \newline 
20677 \SpecialChar ~
20678 \SpecialChar ~
20679 mov %1,a 
20680 \newline 
20681 \SpecialChar ~
20682 \SpecialChar ~
20683 mov a,%1
20684 \newline 
20685 } by {
20686 \newline 
20687 \SpecialChar ~
20688 \SpecialChar ~
20689 mov %1,a
20690 \newline 
20691 }
20692 \layout Standard
20693
20694 The above rule will change the following assembly
20695 \begin_inset LatexCommand \index{Assembler routines}
20696
20697 \end_inset 
20698
20699  sequence:
20700 \layout Verse
20701
20702
20703 \family typewriter 
20704 mov r1,a 
20705 \newline 
20706 mov a,r1
20707 \layout Standard
20708
20709 to
20710 \layout Verse
20711
20712
20713 \family typewriter 
20714 mov r1,a
20715 \layout Standard
20716
20717 Note: All occurrences of a 
20718 \emph on 
20719 %n
20720 \emph default 
20721  (pattern variable) must denote the same string.
20722  With the above rule, the assembly sequence:
20723 \layout Verse
20724
20725
20726 \family typewriter 
20727 mov r1,a 
20728 \newline 
20729 mov a,r2
20730 \layout Standard
20731
20732 will remain unmodified.
20733 \newline 
20734
20735 \newline 
20736 Other special case optimizations may be added by the user (via 
20737 \emph on 
20738 -
20739 \begin_inset ERT
20740 status Collapsed
20741
20742 \layout Standard
20743
20744 \backslash 
20745 /
20746 \end_inset 
20747
20748 -peep-file option
20749 \emph default 
20750 ).
20751  E.g.
20752  some variants of the 8051 MCU
20753 \begin_inset LatexCommand \index{MCS51 variants}
20754
20755 \end_inset 
20756
20757  allow only 
20758 \family typewriter 
20759 ajmp
20760 \family default 
20761  and 
20762 \family typewriter 
20763 acall
20764 \family default 
20765 .
20766  The following two rules will change all 
20767 \family typewriter 
20768 ljmp
20769 \family default 
20770  and 
20771 \family typewriter 
20772 lcall
20773 \family default 
20774  to 
20775 \family typewriter 
20776 ajmp
20777 \family default 
20778  and 
20779 \family typewriter 
20780 acall
20781 \layout Verse
20782
20783
20784 \family typewriter 
20785 replace { lcall %1 } by { acall %1 } 
20786 \newline 
20787 replace { ljmp %1 } by { ajmp %1 }
20788 \layout Standard
20789
20790 The 
20791 \emph on 
20792 inline-assembler code
20793 \emph default 
20794  is also passed through the peep hole optimizer, thus the peephole optimizer
20795  can also be used as an assembly level macro expander.
20796  The rules themselves are MCU dependent whereas the rule language infra-structur
20797 e is MCU independent.
20798  Peephole optimization rules for other MCU can be easily programmed using
20799  the rule language.
20800 \newline 
20801
20802 \newline 
20803 The syntax for a rule is as follows:
20804 \layout Verse
20805
20806
20807 \family typewriter 
20808 rule := replace [ restart ] '{' <assembly sequence> '
20809 \backslash 
20810 n' 
20811 \newline 
20812 \SpecialChar ~
20813  \SpecialChar ~
20814  \SpecialChar ~
20815  \SpecialChar ~
20816  \SpecialChar ~
20817  \SpecialChar ~
20818  \SpecialChar ~
20819  \SpecialChar ~
20820  \SpecialChar ~
20821  \SpecialChar ~
20822  \SpecialChar ~
20823  \SpecialChar ~
20824  \SpecialChar ~
20825  \SpecialChar ~
20826  '}' by '{' '
20827 \backslash 
20828 n' 
20829 \newline 
20830 \SpecialChar ~
20831  \SpecialChar ~
20832  \SpecialChar ~
20833  \SpecialChar ~
20834  \SpecialChar ~
20835  \SpecialChar ~
20836  \SpecialChar ~
20837  \SpecialChar ~
20838  \SpecialChar ~
20839  \SpecialChar ~
20840  \SpecialChar ~
20841  \SpecialChar ~
20842  \SpecialChar ~
20843  \SpecialChar ~
20844  \SpecialChar ~
20845  \SpecialChar ~
20846  <assembly sequence> '
20847 \backslash 
20848 n' 
20849 \newline 
20850 \SpecialChar ~
20851  \SpecialChar ~
20852  \SpecialChar ~
20853  \SpecialChar ~
20854  \SpecialChar ~
20855  \SpecialChar ~
20856  \SpecialChar ~
20857  \SpecialChar ~
20858  \SpecialChar ~
20859  \SpecialChar ~
20860  \SpecialChar ~
20861  \SpecialChar ~
20862  \SpecialChar ~
20863  \SpecialChar ~
20864  '}' [if <functionName> ] '
20865 \backslash 
20866 n' 
20867 \layout Standard
20868
20869 <assembly sequence> := assembly instruction (each instruction including
20870  labels must be on a separate line).
20871 \newline 
20872
20873 \newline 
20874 The optimizer will apply to the rules one by one from the top in the sequence
20875  of their appearance, it will terminate when all rules are exhausted.
20876  If the 'restart' option is specified, then the optimizer will start matching
20877  the rules again from the top, this option for a rule is expensive (performance)
20878 , it is intended to be used in situations where a transformation will trigger
20879  the same rule again.
20880  An example of this (not a good one, it has side effects) is the following
20881  rule:
20882 \layout Verse
20883
20884
20885 \family typewriter 
20886 replace restart { 
20887 \newline 
20888 \SpecialChar ~
20889 \SpecialChar ~
20890 pop %1 
20891 \newline 
20892 \SpecialChar ~
20893 \SpecialChar ~
20894 push %1 } by { 
20895 \newline 
20896 \SpecialChar ~
20897 \SpecialChar ~
20898 ; nop 
20899 \newline 
20900 }
20901 \layout Standard
20902
20903 Note that the replace pattern cannot be a blank, but can be a comment line.
20904  Without the 'restart' option only the innermost 'pop' 'push' pair would
20905  be eliminated, i.e.:
20906 \layout Verse
20907
20908
20909 \family typewriter 
20910 pop ar1 
20911 \newline 
20912 pop ar2 
20913 \newline 
20914 push ar2 
20915 \newline 
20916 push ar1
20917 \layout Standard
20918
20919 would result in:
20920 \layout Verse
20921
20922
20923 \family typewriter 
20924 pop ar1 
20925 \newline 
20926 ; nop 
20927 \newline 
20928 push ar1
20929 \layout Standard
20930
20931
20932 \emph on 
20933 with
20934 \emph default 
20935  the restart option the rule will be applied again to the resulting code
20936  and then all the pop-push pairs will be eliminated to yield:
20937 \layout Verse
20938
20939
20940 \family typewriter 
20941 ; nop 
20942 \newline 
20943 ; nop
20944 \layout Standard
20945
20946 A conditional function can be attached to a rule.
20947  Attaching rules are somewhat more involved, let me illustrate this with
20948  an example.
20949 \layout Verse
20950
20951
20952 \family typewriter 
20953 replace { 
20954 \newline 
20955 \SpecialChar ~
20956  \SpecialChar ~
20957  \SpecialChar ~
20958 ljmp %5 
20959 \newline 
20960 %2:
20961 \newline 
20962 } by { 
20963 \newline 
20964 \SpecialChar ~
20965  \SpecialChar ~
20966  \SpecialChar ~
20967 sjmp %5 
20968 \newline 
20969 %2:
20970 \newline 
20971 } if labelInRange
20972 \layout Standard
20973
20974 The optimizer does a look-up of a function name table defined in function
20975  
20976 \emph on 
20977 callFuncByName
20978 \emph default 
20979  in the source file SDCCpeeph.c, with the name 
20980 \emph on 
20981 labelInRange
20982 \emph default 
20983 .
20984  If it finds a corresponding entry the function is called.
20985  Note there can be no parameters specified for these functions, in this
20986  case the use of 
20987 \emph on 
20988 %5
20989 \emph default 
20990  is crucial, since the function 
20991 \emph on 
20992 labelInRange
20993 \emph default 
20994  expects to find the label in that particular variable (the hash table containin
20995 g the variable bindings is passed as a parameter).
20996  If you want to code more such functions, take a close look at the function
20997  labelInRange and the calling mechanism in source file SDCCpeeph.c.
20998  Currently implemented are 
20999 \emph on 
21000 labelInRange, labelRefCount, labelIsReturnOnly, operandsNotSame, xramMovcOption,
21001  24bitMode, portIsDS390, 24bitModeAndPortDS390 
21002 \emph default 
21003 and
21004 \emph on 
21005  notVolatile
21006 \emph default 
21007 .
21008 \layout Standard
21009
21010 I know this whole thing is a little kludgey, but maybe some day we will
21011  have some better means.
21012  If you are looking at this file, you will see the default rules that are
21013  compiled into the compiler, you can add your own rules in the default set
21014  there if you get tired of specifying the -
21015 \begin_inset ERT
21016 status Collapsed
21017
21018 \layout Standard
21019
21020 \backslash 
21021 /
21022 \end_inset 
21023
21024 -peep-file option.
21025 \layout Section
21026
21027 ANSI-Compliance
21028 \begin_inset LatexCommand \index{ANSI-compliance}
21029
21030 \end_inset 
21031
21032
21033 \begin_inset LatexCommand \label{sub:ANSI-Compliance}
21034
21035 \end_inset 
21036
21037
21038 \layout Standard
21039
21040 Deviations from the compliance:
21041 \layout Itemize
21042
21043 functions are not always reentrant
21044 \begin_inset LatexCommand \index{reentrant}
21045
21046 \end_inset 
21047
21048 .
21049 \layout Itemize
21050
21051 structures cannot be assigned values directly, cannot be passed as function
21052  parameters or assigned to each other and cannot be a return value from
21053  a function, e.g.:
21054 \begin_deeper 
21055 \layout Verse
21056
21057
21058 \family typewriter 
21059 struct s { ...
21060  }; 
21061 \newline 
21062 struct s s1, s2; 
21063 \newline 
21064 foo() 
21065 \newline 
21066
21067 \newline 
21068 \SpecialChar ~
21069 \SpecialChar ~
21070 \SpecialChar ~
21071 \SpecialChar ~
21072 ...
21073  
21074 \newline 
21075 \SpecialChar ~
21076 \SpecialChar ~
21077 \SpecialChar ~
21078 \SpecialChar ~
21079 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
21080 \newline 
21081 \SpecialChar ~
21082 \SpecialChar ~
21083 \SpecialChar ~
21084 \SpecialChar ~
21085 ...
21086  
21087 \newline 
21088 }
21089 \newline 
21090 struct s foo1 (struct s parms) /* invalid in SDCC although allowed in ANSI
21091  */
21092 \newline 
21093
21094 \newline 
21095 \SpecialChar ~
21096 \SpecialChar ~
21097 \SpecialChar ~
21098 \SpecialChar ~
21099 struct s rets; 
21100 \newline 
21101 \SpecialChar ~
21102 \SpecialChar ~
21103 \SpecialChar ~
21104 \SpecialChar ~
21105 ...
21106  
21107 \newline 
21108 \SpecialChar ~
21109 \SpecialChar ~
21110 \SpecialChar ~
21111 \SpecialChar ~
21112 return rets;/* is invalid in SDCC although allowed in ANSI */ 
21113 \newline 
21114 }
21115 \end_deeper 
21116 \layout Itemize
21117
21118 'long long
21119 \begin_inset LatexCommand \index{long long (not supported)}
21120
21121 \end_inset 
21122
21123 ' (64 bit integers
21124 \begin_inset LatexCommand \index{int (64 bit) (not supported)}
21125
21126 \end_inset 
21127
21128 ) not supported.
21129 \layout Itemize
21130
21131 'double
21132 \begin_inset LatexCommand \index{double (not supported)}
21133
21134 \end_inset 
21135
21136 ' precision floating point 
21137 \begin_inset LatexCommand \index{Floating point support}
21138
21139 \end_inset 
21140
21141 not supported.
21142 \layout Itemize
21143
21144 No support for setjmp
21145 \begin_inset LatexCommand \index{setjmp (not supported)}
21146
21147 \end_inset 
21148
21149  and longjmp
21150 \begin_inset LatexCommand \index{longjmp (not supported)}
21151
21152 \end_inset 
21153
21154  (for now).
21155 \layout Itemize
21156
21157 Old K&R style
21158 \begin_inset LatexCommand \index{K\&R style}
21159
21160 \end_inset 
21161
21162  function declarations are NOT allowed.
21163 \begin_deeper 
21164 \layout Verse
21165
21166
21167 \family typewriter 
21168 foo(i,j) /* this old style of function declarations */ 
21169 \newline 
21170 int i,j; /* are valid in ANSI but not valid in SDCC */ 
21171 \newline 
21172
21173 \newline 
21174 \SpecialChar ~
21175 \SpecialChar ~
21176 \SpecialChar ~
21177 \SpecialChar ~
21178 ...
21179  
21180 \newline 
21181 }
21182 \end_deeper 
21183 \layout Section
21184
21185 Cyclomatic Complexity
21186 \begin_inset LatexCommand \index{Cyclomatic complexity}
21187
21188 \end_inset 
21189
21190
21191 \layout Standard
21192
21193 Cyclomatic complexity of a function is defined as the number of independent
21194  paths the program can take during execution of the function.
21195  This is an important number since it defines the number test cases you
21196  have to generate to validate the function.
21197  The accepted industry standard for complexity number is 10, if the cyclomatic
21198  complexity reported by SDCC exceeds 10 you should think about simplification
21199  of the function logic.
21200  Note that the complexity level is not related to the number of lines of
21201  code in a function.
21202  Large functions can have low complexity, and small functions can have large
21203  complexity levels.
21204  
21205 \newline 
21206
21207 \newline 
21208 SDCC uses the following formula to compute the complexity:
21209 \newline 
21210
21211 \layout Standard
21212
21213 complexity = (number of edges in control flow graph) - (number of nodes
21214  in control flow graph) + 2;
21215 \newline 
21216
21217 \newline 
21218 Having said that the industry standard is 10, you should be aware that in
21219  some cases it be may unavoidable to have a complexity level of less than
21220  10.
21221  For example if you have switch statement with more than 10 case labels,
21222  each case label adds one to the complexity level.
21223  The complexity level is by no means an absolute measure of the algorithmic
21224  complexity of the function, it does however provide a good starting point
21225  for which functions you might look at for further optimization.
21226 \layout Section
21227
21228 Retargetting for other Processors
21229 \layout Standard
21230
21231 The issues for retargetting the compiler are far too numerous to be covered
21232  by this document.
21233  What follows is a brief description of each of the seven phases of the
21234  compiler and its MCU dependency.
21235 \layout Itemize
21236
21237 Parsing the source and building the annotated parse tree.
21238  This phase is largely MCU independent (except for the language extensions).
21239  Syntax & semantic checks are also done in this phase, along with some initial
21240  optimizations like back patching labels and the pattern matching optimizations
21241  like bit-rotation etc.
21242 \layout Itemize
21243
21244 The second phase involves generating an intermediate code which can be easy
21245  manipulated during the later phases.
21246  This phase is entirely MCU independent.
21247  The intermediate code generation assumes the target machine has unlimited
21248  number of registers, and designates them with the name iTemp.
21249  The compiler can be made to dump a human readable form of the code generated
21250  by using the -
21251 \begin_inset ERT
21252 status Collapsed
21253
21254 \layout Standard
21255
21256 \backslash 
21257 /
21258 \end_inset 
21259
21260 -dumpraw option.
21261 \layout Itemize
21262
21263 This phase does the bulk of the standard optimizations and is also MCU independe
21264 nt.
21265  This phase can be broken down into several sub-phases:
21266 \newline 
21267
21268 \newline 
21269 Break down intermediate code (iCode) into basic blocks.
21270 \newline 
21271 Do control flow & data flow analysis on the basic blocks.
21272 \newline 
21273 Do local common subexpression elimination, then global subexpression elimination
21274 \newline 
21275 Dead code elimination
21276 \newline 
21277 Loop optimizations
21278 \newline 
21279 If loop optimizations caused any changes then do 'global subexpression eliminati
21280 on' and 'dead code elimination' again.
21281 \layout Itemize
21282
21283 This phase determines the live-ranges; by live range I mean those iTemp
21284  variables defined by the compiler that still survive after all the optimization
21285 s.
21286  Live range analysis
21287 \begin_inset LatexCommand \index{Live range analysis}
21288
21289 \end_inset 
21290
21291  is essential for register allocation, since these computation determines
21292  which of these iTemps will be assigned to registers, and for how long.
21293 \layout Itemize
21294
21295 Phase five is register allocation.
21296  There are two parts to this process.
21297 \newline 
21298
21299 \newline 
21300 The first part I call 'register packing' (for lack of a better term).
21301  In this case several MCU specific expression folding is done to reduce
21302  register pressure.
21303 \newline 
21304
21305 \newline 
21306 The second part is more MCU independent and deals with allocating registers
21307  to the remaining live ranges.
21308  A lot of MCU specific code does creep into this phase because of the limited
21309  number of index registers available in the 8051.
21310 \layout Itemize
21311
21312 The Code generation phase is (unhappily), entirely MCU dependent and very
21313  little (if any at all) of this code can be reused for other MCU.
21314  However the scheme for allocating a homogenized assembler operand for each
21315  iCode operand may be reused.
21316 \layout Itemize
21317
21318 As mentioned in the optimization section the peep-hole optimizer is rule
21319  based system, which can reprogrammed for other MCUs.
21320 \layout Chapter
21321
21322 Compiler internals
21323 \begin_inset LatexCommand \index{Compiler internals}
21324
21325 \end_inset 
21326
21327
21328 \layout Section
21329
21330 The anatomy of the compiler
21331 \begin_inset LatexCommand \label{sub:The-anatomy-of}
21332
21333 \end_inset 
21334
21335
21336 \layout Standard
21337
21338
21339 \shape italic 
21340 This is an excerpt from an article published in Circuit Cellar Magazine
21341  in august 2000.
21342  It's a little outdated (the compiler is much more efficient now and user/develo
21343 per friendly), but pretty well exposes the guts of it all.
21344 \shape default 
21345
21346 \newline 
21347
21348 \newline 
21349 The current version of SDCC can generate code for Intel 8051 and Z80 MCU.
21350  It is fairly easy to retarget for other 8-bit MCU.
21351  Here we take a look at some of the internals of the compiler.
21352  
21353 \layout Paragraph*
21354
21355 Parsing
21356 \begin_inset LatexCommand \index{Parsing}
21357
21358 \end_inset 
21359
21360  
21361 \layout Standard
21362
21363 Parsing the input source file and creating an AST (Annotated Syntax Tree
21364 \begin_inset LatexCommand \index{Annotated syntax tree}
21365
21366 \end_inset 
21367
21368 ).
21369  This phase also involves propagating types (annotating each node of the
21370  parse tree with type information) and semantic analysis.
21371  There are some MCU specific parsing rules.
21372  For example the storage classes, the extended storage classes are MCU specific
21373  while there may be a xdata storage class for 8051 there is no such storage
21374  class for z80 or Atmel AVR.
21375  SDCC allows MCU specific storage class extensions, i.e.
21376  xdata will be treated as a storage class specifier when parsing 8051 C
21377  code but will be treated as a C identifier when parsing z80 or ATMEL AVR
21378  C code.
21379 \layout Paragraph*
21380
21381 Generating iCode
21382 \begin_inset LatexCommand \index{iCode}
21383
21384 \end_inset 
21385
21386
21387 \layout Standard
21388
21389 Intermediate code generation.
21390  In this phase the AST is broken down into three-operand form (iCode).
21391  These three operand forms are represented as doubly linked lists.
21392  ICode is the term given to the intermediate form generated by the compiler.
21393  ICode example section shows some examples of iCode generated for some simple
21394  C source functions.
21395 \layout Paragraph*
21396
21397 Optimizations
21398 \begin_inset LatexCommand \index{Optimizations}
21399
21400 \end_inset 
21401
21402 .
21403 \layout Standard
21404
21405 Bulk of the target independent optimizations is performed in this phase.
21406  The optimizations include constant propagation, common sub-expression eliminati
21407 on, loop invariant code movement, strength reduction of loop induction variables
21408  and dead-code elimination.
21409 \layout Paragraph*
21410
21411 Live range analysis
21412 \begin_inset LatexCommand \index{Live range analysis}
21413
21414 \end_inset 
21415
21416
21417 \layout Standard
21418
21419 During intermediate code generation phase, the compiler assumes the target
21420  machine has infinite number of registers and generates a lot of temporary
21421  variables.
21422  The live range computation determines the lifetime of each of these compiler-ge
21423 nerated temporaries.
21424  A picture speaks a thousand words.
21425  ICode example sections show the live range annotations for each of the
21426  operand.
21427  It is important to note here, each iCode is assigned a number in the order
21428  of its execution in the function.
21429  The live ranges are computed in terms of these numbers.
21430  The from number is the number of the iCode which first defines the operand
21431  and the to number signifies the iCode which uses this operand last.
21432 \layout Paragraph*
21433
21434 Register Allocation
21435 \begin_inset LatexCommand \index{Register allocation}
21436
21437 \end_inset 
21438
21439
21440 \layout Standard
21441
21442 The register allocation determines the type and number of registers needed
21443  by each operand.
21444  In most MCUs only a few registers can be used for indirect addressing.
21445  In case of 8051 for example the registers R0 & R1 can be used to indirectly
21446  address the internal ram and DPTR to indirectly address the external ram.
21447  The compiler will try to allocate the appropriate register to pointer variables
21448  if it can.
21449  ICode example section shows the operands annotated with the registers assigned
21450  to them.
21451  The compiler will try to keep operands in registers as much as possible;
21452  there are several schemes the compiler uses to do achieve this.
21453  When the compiler runs out of registers the compiler will check to see
21454  if there are any live operands which is not used or defined in the current
21455  basic block being processed, if there are any found then it will push that
21456  operand and use the registers in this block, the operand will then be popped
21457  at the end of the basic block.
21458  
21459 \layout Standard
21460
21461 There are other MCU specific considerations in this phase.
21462  Some MCUs have an accumulator; very short-lived operands could be assigned
21463  to the accumulator instead of a general-purpose register.
21464 \layout Paragraph*
21465
21466 Code generation
21467 \layout Standard
21468
21469 Figure II gives a table of iCode operations supported by the compiler.
21470  The code generation involves translating these operations into corresponding
21471  assembly code for the processor.
21472  This sounds overly simple but that is the essence of code generation.
21473  Some of the iCode operations are generated on a MCU specific manner for
21474  example, the z80 port does not use registers to pass parameters so the
21475  SEND and RECV iCode operations will not be generated, and it also does
21476  not support JUMPTABLES.
21477  
21478 \newline 
21479
21480 \series bold 
21481 \shape italic 
21482 \color red
21483 <Where is Figure II ?>
21484 \layout Paragraph*
21485
21486 ICode Example
21487 \begin_inset LatexCommand \index{iCode}
21488
21489 \end_inset 
21490
21491
21492 \layout Standard
21493
21494 This section shows some details of iCode.
21495  The example C code does not do anything useful; it is used as an example
21496  to illustrate the intermediate code generated by the compiler.
21497 \layout Verse
21498
21499
21500 \family typewriter 
21501 1.\SpecialChar ~
21502 xdata int * p;
21503 \newline 
21504 2.\SpecialChar ~
21505 int gint;
21506 \newline 
21507 3.\SpecialChar ~
21508 /* This function does nothing useful.
21509  It is used
21510 \newline 
21511 4.\SpecialChar ~
21512 \SpecialChar ~
21513 \SpecialChar ~
21514 \SpecialChar ~
21515 for the purpose of explaining iCode */
21516 \newline 
21517 5.\SpecialChar ~
21518 short function (data int *x)
21519 \newline 
21520 6.\SpecialChar ~
21521 {
21522 \newline 
21523 7.\SpecialChar ~
21524 \SpecialChar ~
21525 \SpecialChar ~
21526 short i=10; \SpecialChar ~
21527 \SpecialChar ~
21528 /* dead initialization eliminated */
21529 \newline 
21530 8.\SpecialChar ~
21531 \SpecialChar ~
21532 \SpecialChar ~
21533 short sum=10; /* dead initialization eliminated */
21534 \newline 
21535 9.\SpecialChar ~
21536 \SpecialChar ~
21537 \SpecialChar ~
21538 short mul;
21539 \newline 
21540 10.\SpecialChar ~
21541 \SpecialChar ~
21542 int j ;
21543 \newline 
21544 11.\SpecialChar ~
21545 \SpecialChar ~
21546 while (*x) *x++ = *p++; 
21547 \newline 
21548 12.\SpecialChar ~
21549 \SpecialChar ~
21550 \SpecialChar ~
21551 \SpecialChar ~
21552 sum = 0 ; 
21553 \newline 
21554 13.\SpecialChar ~
21555 \SpecialChar ~
21556 mul = 0;
21557 \newline 
21558 14.\SpecialChar ~
21559 \SpecialChar ~
21560 /* compiler detects i,j to be induction variables */
21561 \newline 
21562 15.\SpecialChar ~
21563 \SpecialChar ~
21564 for (i = 0, j = 10 ; i < 10 ; i++, j
21565 \family default 
21566 -
21567 \begin_inset ERT
21568 status Collapsed
21569
21570 \layout Standard
21571
21572 \backslash 
21573 /
21574 \end_inset 
21575
21576 -
21577 \family typewriter 
21578 ) {
21579 \newline 
21580 16.\SpecialChar ~
21581 \SpecialChar ~
21582 \SpecialChar ~
21583 \SpecialChar ~
21584 sum += i;
21585 \newline 
21586 17.\SpecialChar ~
21587 \SpecialChar ~
21588 \SpecialChar ~
21589 \SpecialChar ~
21590 mul += i * 3; \SpecialChar ~
21591 \SpecialChar ~
21592 /* this multiplication remains */
21593 \newline 
21594 18.\SpecialChar ~
21595 \SpecialChar ~
21596 \SpecialChar ~
21597 \SpecialChar ~
21598 gint += j * 3;\SpecialChar ~
21599 \SpecialChar ~
21600 /* this multiplication changed to addition */
21601 \newline 
21602 19.\SpecialChar ~
21603 \SpecialChar ~
21604 }
21605 \newline 
21606 20.\SpecialChar ~
21607 \SpecialChar ~
21608 return sum+mul;
21609 \newline 
21610 21.\SpecialChar ~
21611 }
21612 \layout Standard
21613
21614 In addition to the operands each iCode contains information about the filename
21615  and line it corresponds to in the source file.
21616  The first field in the listing should be interpreted as follows:
21617 \newline 
21618
21619 \shape italic 
21620 \size footnotesize 
21621 Filename(linenumber: iCode Execution sequence number : ICode hash table
21622  key : loop depth of the iCode).
21623 \shape default 
21624 \size default 
21625
21626 \newline 
21627 Then follows the human readable form of the ICode operation.
21628  Each operand of this triplet form can be of three basic types a) compiler
21629  generated temporary b) user defined variable c) a constant value.
21630  Note that local variables and parameters are replaced by compiler generated
21631  temporaries.
21632  Live ranges
21633 \begin_inset LatexCommand \index{Live range analysis}
21634
21635 \end_inset 
21636
21637  are computed only for temporaries (i.e.
21638  live ranges are not computed for global variables).
21639  Registers
21640 \begin_inset LatexCommand \index{Register allocation}
21641
21642 \end_inset 
21643
21644  are allocated for temporaries only.
21645  Operands are formatted in the following manner:
21646 \newline 
21647
21648 \shape italic 
21649 \size footnotesize 
21650 Operand Name [lr live-from : live-to ] { type information } [ registers
21651  allocated ].
21652 \shape default 
21653 \size default 
21654
21655 \newline 
21656 As mentioned earlier the live ranges are computed in terms of the execution
21657  sequence number of the iCodes, for example 
21658 \newline 
21659 the iTemp0 is live from (i.e.
21660  first defined in iCode with execution sequence number 3, and is last used
21661  in the iCode with sequence number 5).
21662  For induction variables such as iTemp21 the live range computation extends
21663  the lifetime from the start to the end of the loop.
21664 \newline 
21665 The register allocator used the live range information to allocate registers,
21666  the same registers may be used for different temporaries if their live
21667  ranges do not overlap, for example r0 is allocated to both iTemp6 and to
21668  iTemp17 since their live ranges do not overlap.
21669  In addition the allocator also takes into consideration the type and usage
21670  of a temporary, for example itemp6 is a pointer to near space and is used
21671  as to fetch data from (i.e.
21672  used in GET_VALUE_AT_ADDRESS) so it is allocated a pointer register (r0).
21673  Some short lived temporaries are allocated to special registers which have
21674  meaning to the code generator e.g.
21675  iTemp13 is allocated to a pseudo register CC which tells the back end that
21676  the temporary is used only for a conditional jump the code generation makes
21677  use of this information to optimize a compare and jump ICode.
21678 \newline 
21679 There are several loop optimizations
21680 \begin_inset LatexCommand \index{Loop optimization}
21681
21682 \end_inset 
21683
21684  performed by the compiler.
21685  It can detect induction variables iTemp21(i) and iTemp23(j).
21686  Also note the compiler does selective strength reduction
21687 \begin_inset LatexCommand \index{Strength reduction}
21688
21689 \end_inset 
21690
21691 , i.e.
21692  the multiplication of an induction variable in line 18 (gint = j * 3) is
21693  changed to addition, a new temporary iTemp17 is allocated and assigned
21694  a initial value, a constant 3 is then added for each iteration of the loop.
21695  The compiler does not change the multiplication
21696 \begin_inset LatexCommand \index{Multiplication}
21697
21698 \end_inset 
21699
21700  in line 17 however since the processor does support an 8 * 8 bit multiplication.
21701 \newline 
21702 Note the dead code elimination
21703 \begin_inset LatexCommand \index{Dead-code elimination}
21704
21705 \end_inset 
21706
21707  optimization eliminated the dead assignments in line 7 & 8 to I and sum
21708  respectively.
21709 \newline 
21710
21711 \layout Standard
21712
21713
21714 \size footnotesize 
21715 Sample.c (5:1:0:0) _entry($9) :
21716 \layout Standard
21717
21718
21719 \size footnotesize 
21720 Sample.c(5:2:1:0) proc _function [lr0:0]{function short}
21721 \layout Standard
21722
21723
21724 \size footnotesize 
21725 Sample.c(11:3:2:0) iTemp0 [lr3:5]{_near * int}[r2] = recv 
21726 \layout Standard
21727
21728
21729 \size footnotesize 
21730 Sample.c(11:4:53:0) preHeaderLbl0($11) :
21731 \layout Standard
21732
21733
21734 \size footnotesize 
21735 Sample.c(11:5:55:0) iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near
21736  * int}[r2]
21737 \layout Standard
21738
21739
21740 \size footnotesize 
21741 Sample.c(11:6:5:1) _whilecontinue_0($1) :
21742 \layout Standard
21743
21744
21745 \size footnotesize 
21746 Sample.c(11:7:7:1) iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near *
21747  int}[r0]]
21748 \layout Standard
21749
21750
21751 \size footnotesize 
21752 Sample.c(11:8:8:1) if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
21753 \layout Standard
21754
21755
21756 \size footnotesize 
21757 Sample.c(11:9:14:1) iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far
21758  * int}
21759 \layout Standard
21760
21761
21762 \size footnotesize 
21763 Sample.c(11:10:15:1) _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2
21764  {short}
21765 \layout Standard
21766
21767
21768 \size footnotesize 
21769 Sample.c(11:13:18:1) iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far
21770  * int}[DPTR]]
21771 \layout Standard
21772
21773
21774 \size footnotesize 
21775 Sample.c(11:14:19:1) *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int
21776 }[r2 r3]
21777 \layout Standard
21778
21779
21780 \size footnotesize 
21781 Sample.c(11:15:12:1) iTemp6 [lr5:16]{_near * int}[r0] = iTemp6 [lr5:16]{_near
21782  * int}[r0] + 0x2 {short}
21783 \layout Standard
21784
21785
21786 \size footnotesize 
21787 Sample.c(11:16:20:1) goto _whilecontinue_0($1)
21788 \layout Standard
21789
21790
21791 \size footnotesize 
21792 Sample.c(11:17:21:0)_whilebreak_0($3) :
21793 \layout Standard
21794
21795
21796 \size footnotesize 
21797 Sample.c(12:18:22:0) iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
21798 \layout Standard
21799
21800
21801 \size footnotesize 
21802 Sample.c(13:19:23:0) iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
21803 \layout Standard
21804
21805
21806 \size footnotesize 
21807 Sample.c(15:20:54:0)preHeaderLbl1($13) :
21808 \layout Standard
21809
21810
21811 \size footnotesize 
21812 Sample.c(15:21:56:0) iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
21813 \layout Standard
21814
21815
21816 \size footnotesize 
21817 Sample.c(15:22:57:0) iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
21818 \layout Standard
21819
21820
21821 \size footnotesize 
21822 Sample.c(15:23:58:0) iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
21823 \layout Standard
21824
21825
21826 \size footnotesize 
21827 Sample.c(15:24:26:1)_forcond_0($4) :
21828 \layout Standard
21829
21830
21831 \size footnotesize 
21832 Sample.c(15:25:27:1) iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4]
21833  < 0xa {short}
21834 \layout Standard
21835
21836
21837 \size footnotesize 
21838 Sample.c(15:26:28:1) if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
21839 \layout Standard
21840
21841
21842 \size footnotesize 
21843 Sample.c(16:27:31:1) iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2]
21844  + ITemp21 [lr21:38]{short}[r4]
21845 \layout Standard
21846
21847
21848 \size footnotesize 
21849 Sample.c(17:29:33:1) iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4]
21850  * 0x3 {short}
21851 \layout Standard
21852
21853
21854 \size footnotesize 
21855 Sample.c(17:30:34:1) iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3]
21856  + iTemp15 [lr29:30]{short}[r1]
21857 \layout Standard
21858
21859
21860 \size footnotesize 
21861 Sample.c(18:32:36:1:1) iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7
21862  r0]- 0x3 {short}
21863 \layout Standard
21864
21865
21866 \size footnotesize 
21867 Sample.c(18:33:37:1) _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{
21868 int}[r7 r0]
21869 \layout Standard
21870
21871
21872 \size footnotesize 
21873 Sample.c(15:36:42:1) iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4]
21874  + 0x1 {short}
21875 \layout Standard
21876
21877
21878 \size footnotesize 
21879 Sample.c(15:37:45:1) iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5
21880  r6]- 0x1 {short}
21881 \layout Standard
21882
21883
21884 \size footnotesize 
21885 Sample.c(19:38:47:1) goto _forcond_0($4)
21886 \layout Standard
21887
21888
21889 \size footnotesize 
21890 Sample.c(19:39:48:0)_forbreak_0($7) :
21891 \layout Standard
21892
21893
21894 \size footnotesize 
21895 Sample.c(20:40:49:0) iTemp24 [lr40:41]{short}[DPTR] = iTemp2 [lr18:40]{short}[r2]
21896  + ITemp11 [lr19:40]{short}[r3]
21897 \layout Standard
21898
21899
21900 \size footnotesize 
21901 Sample.c(20:41:50:0) ret iTemp24 [lr40:41]{short}
21902 \layout Standard
21903
21904
21905 \size footnotesize 
21906 Sample.c(20:42:51:0)_return($8) :
21907 \layout Standard
21908
21909
21910 \size footnotesize 
21911 Sample.c(20:43:52:0) eproc _function [lr0:0]{ ia0 re0 rm0}{function short}
21912 \size default 
21913
21914 \newline 
21915
21916 \newline 
21917 Finally the code generated for this function:
21918 \newline 
21919
21920 \layout Standard
21921
21922
21923 \size footnotesize 
21924 .area DSEG (DATA)
21925 \layout Standard
21926
21927
21928 \size footnotesize 
21929 _p::
21930 \layout Standard
21931
21932
21933 \size footnotesize 
21934 \SpecialChar ~
21935 \SpecialChar ~
21936 .ds 2
21937 \layout Standard
21938
21939
21940 \size footnotesize 
21941 _gint::
21942 \layout Standard
21943
21944
21945 \size footnotesize 
21946 \SpecialChar ~
21947 \SpecialChar ~
21948 .ds 2
21949 \layout Standard
21950
21951
21952 \size footnotesize 
21953 ; sample.c 5
21954 \layout Standard
21955
21956
21957 \size footnotesize 
21958 ; ----------------------------------------------
21959 \layout Standard
21960
21961
21962 \size footnotesize 
21963 ; function function
21964 \layout Standard
21965
21966
21967 \size footnotesize 
21968 ; ----------------------------------------------
21969 \layout Standard
21970
21971
21972 \size footnotesize 
21973 _function:
21974 \layout Standard
21975
21976
21977 \size footnotesize 
21978 ; iTemp0 [lr3:5]{_near * int}[r2] = recv 
21979 \layout Standard
21980
21981
21982 \size footnotesize 
21983 \SpecialChar ~
21984 \SpecialChar ~
21985 mov r2,dpl
21986 \layout Standard
21987
21988
21989 \size footnotesize 
21990 ; iTemp6 [lr5:16]{_near * int}[r0] := iTemp0 [lr3:5]{_near * int}[r2]
21991 \layout Standard
21992
21993
21994 \size footnotesize 
21995 \SpecialChar ~
21996 \SpecialChar ~
21997 mov ar0,r2
21998 \layout Standard
21999
22000
22001 \size footnotesize 
22002 ;_whilecontinue_0($1) :
22003 \layout Standard
22004
22005
22006 \size footnotesize 
22007 00101$:
22008 \layout Standard
22009
22010
22011 \size footnotesize 
22012 ; iTemp4 [lr7:8]{int}[r2 r3] = @[iTemp6 [lr5:16]{_near * int}[r0]]
22013 \layout Standard
22014
22015
22016 \size footnotesize 
22017 ; if iTemp4 [lr7:8]{int}[r2 r3] == 0 goto _whilebreak_0($3)
22018 \layout Standard
22019
22020
22021 \size footnotesize 
22022 \SpecialChar ~
22023 \SpecialChar ~
22024 mov ar2,@r0
22025 \layout Standard
22026
22027
22028 \size footnotesize 
22029 \SpecialChar ~
22030 \SpecialChar ~
22031 inc r0
22032 \layout Standard
22033
22034
22035 \size footnotesize 
22036 \SpecialChar ~
22037 \SpecialChar ~
22038 mov ar3,@r0
22039 \layout Standard
22040
22041
22042 \size footnotesize 
22043 \SpecialChar ~
22044 \SpecialChar ~
22045 dec r0
22046 \layout Standard
22047
22048
22049 \size footnotesize 
22050 \SpecialChar ~
22051 \SpecialChar ~
22052 mov a,r2
22053 \layout Standard
22054
22055
22056 \size footnotesize 
22057 \SpecialChar ~
22058 \SpecialChar ~
22059 orl a,r3
22060 \layout Standard
22061
22062
22063 \size footnotesize 
22064 \SpecialChar ~
22065 \SpecialChar ~
22066 jz 00103$
22067 \layout Standard
22068
22069
22070 \size footnotesize 
22071 00114$:
22072 \layout Standard
22073
22074
22075 \size footnotesize 
22076 ; iTemp7 [lr9:13]{_far * int}[DPTR] := _p [lr0:0]{_far * int}
22077 \layout Standard
22078
22079
22080 \size footnotesize 
22081 \SpecialChar ~
22082 \SpecialChar ~
22083 mov dpl,_p
22084 \layout Standard
22085
22086
22087 \size footnotesize 
22088 \SpecialChar ~
22089 \SpecialChar ~
22090 mov dph,(_p + 1)
22091 \layout Standard
22092
22093
22094 \size footnotesize 
22095 ; _p [lr0:0]{_far * int} = _p [lr0:0]{_far * int} + 0x2 {short}
22096 \layout Standard
22097
22098
22099 \size footnotesize 
22100 \SpecialChar ~
22101 \SpecialChar ~
22102 mov a,#0x02
22103 \layout Standard
22104
22105
22106 \size footnotesize 
22107 \SpecialChar ~
22108 \SpecialChar ~
22109 add a,_p
22110 \layout Standard
22111
22112
22113 \size footnotesize 
22114 \SpecialChar ~
22115 \SpecialChar ~
22116 mov _p,a
22117 \layout Standard
22118
22119
22120 \size footnotesize 
22121 \SpecialChar ~
22122 \SpecialChar ~
22123 clr a
22124 \layout Standard
22125
22126
22127 \size footnotesize 
22128 \SpecialChar ~
22129 \SpecialChar ~
22130 addc a,(_p + 1)
22131 \layout Standard
22132
22133
22134 \size footnotesize 
22135 \SpecialChar ~
22136 \SpecialChar ~
22137 mov (_p + 1),a
22138 \layout Standard
22139
22140
22141 \size footnotesize 
22142 ; iTemp10 [lr13:14]{int}[r2 r3] = @[iTemp7 [lr9:13]{_far * int}[DPTR]]
22143 \layout Standard
22144
22145
22146 \size footnotesize 
22147 \SpecialChar ~
22148 \SpecialChar ~
22149 movx a,@dptr
22150 \layout Standard
22151
22152
22153 \size footnotesize 
22154 \SpecialChar ~
22155 \SpecialChar ~
22156 mov r2,a
22157 \layout Standard
22158
22159
22160 \size footnotesize 
22161 \SpecialChar ~
22162 \SpecialChar ~
22163 inc dptr
22164 \layout Standard
22165
22166
22167 \size footnotesize 
22168 \SpecialChar ~
22169 \SpecialChar ~
22170 movx a,@dptr
22171 \layout Standard
22172
22173
22174 \size footnotesize 
22175 \SpecialChar ~
22176 \SpecialChar ~
22177 mov r3,a
22178 \layout Standard
22179
22180
22181 \size footnotesize 
22182 ; *(iTemp6 [lr5:16]{_near * int}[r0]) := iTemp10 [lr13:14]{int}[r2 r3]
22183 \layout Standard
22184
22185
22186 \size footnotesize 
22187 \SpecialChar ~
22188 \SpecialChar ~
22189 mov @r0,ar2
22190 \layout Standard
22191
22192
22193 \size footnotesize 
22194 \SpecialChar ~
22195 \SpecialChar ~
22196 inc r0
22197 \layout Standard
22198
22199
22200 \size footnotesize 
22201 \SpecialChar ~
22202 \SpecialChar ~
22203 mov @r0,ar3
22204 \layout Standard
22205
22206
22207 \size footnotesize 
22208 ; iTemp6 [lr5:16]{_near * int}[r0] = 
22209 \layout Standard
22210
22211
22212 \size footnotesize 
22213 ; iTemp6 [lr5:16]{_near * int}[r0] + 
22214 \layout Standard
22215
22216
22217 \size footnotesize 
22218 ; 0x2 {short}
22219 \layout Standard
22220
22221
22222 \size footnotesize 
22223 \SpecialChar ~
22224 \SpecialChar ~
22225 inc r0
22226 \layout Standard
22227
22228
22229 \size footnotesize 
22230 ; goto _whilecontinue_0($1)
22231 \layout Standard
22232
22233
22234 \size footnotesize 
22235 \SpecialChar ~
22236 \SpecialChar ~
22237 sjmp 00101$
22238 \layout Standard
22239
22240
22241 \size footnotesize 
22242 ; _whilebreak_0($3) :
22243 \layout Standard
22244
22245
22246 \size footnotesize 
22247 00103$:
22248 \layout Standard
22249
22250
22251 \size footnotesize 
22252 ; iTemp2 [lr18:40]{short}[r2] := 0x0 {short}
22253 \layout Standard
22254
22255
22256 \size footnotesize 
22257 \SpecialChar ~
22258 \SpecialChar ~
22259 mov r2,#0x00
22260 \layout Standard
22261
22262
22263 \size footnotesize 
22264 ; iTemp11 [lr19:40]{short}[r3] := 0x0 {short}
22265 \layout Standard
22266
22267
22268 \size footnotesize 
22269 \SpecialChar ~
22270 \SpecialChar ~
22271 mov r3,#0x00
22272 \layout Standard
22273
22274
22275 \size footnotesize 
22276 ; iTemp21 [lr21:38]{short}[r4] := 0x0 {short}
22277 \layout Standard
22278
22279
22280 \size footnotesize 
22281 \SpecialChar ~
22282 \SpecialChar ~
22283 mov r4,#0x00
22284 \layout Standard
22285
22286
22287 \size footnotesize 
22288 ; iTemp23 [lr22:38]{int}[r5 r6] := 0xa {int}
22289 \layout Standard
22290
22291
22292 \size footnotesize 
22293 \SpecialChar ~
22294 \SpecialChar ~
22295 mov r5,#0x0A
22296 \layout Standard
22297
22298
22299 \size footnotesize 
22300 \SpecialChar ~
22301 \SpecialChar ~
22302 mov r6,#0x00
22303 \layout Standard
22304
22305
22306 \size footnotesize 
22307 ; iTemp17 [lr23:38]{int}[r7 r0] := 0x1e {int}
22308 \layout Standard
22309
22310
22311 \size footnotesize 
22312 \SpecialChar ~
22313 \SpecialChar ~
22314 mov r7,#0x1E
22315 \layout Standard
22316
22317
22318 \size footnotesize 
22319 \SpecialChar ~
22320 \SpecialChar ~
22321 mov r0,#0x00
22322 \layout Standard
22323
22324
22325 \size footnotesize 
22326 ; _forcond_0($4) :
22327 \layout Standard
22328
22329
22330 \size footnotesize 
22331 00104$:
22332 \layout Standard
22333
22334
22335 \size footnotesize 
22336 ; iTemp13 [lr25:26]{char}[CC] = iTemp21 [lr21:38]{short}[r4] < 0xa {short}
22337 \layout Standard
22338
22339
22340 \size footnotesize 
22341 ; if iTemp13 [lr25:26]{char}[CC] == 0 goto _forbreak_0($7)
22342 \layout Standard
22343
22344
22345 \size footnotesize 
22346 \SpecialChar ~
22347 \SpecialChar ~
22348 clr c
22349 \layout Standard
22350
22351
22352 \size footnotesize 
22353 \SpecialChar ~
22354 \SpecialChar ~
22355 mov a,r4
22356 \layout Standard
22357
22358
22359 \size footnotesize 
22360 \SpecialChar ~
22361 \SpecialChar ~
22362 xrl a,#0x80
22363 \layout Standard
22364
22365
22366 \size footnotesize 
22367 \SpecialChar ~
22368 \SpecialChar ~
22369 subb a,#0x8a
22370 \layout Standard
22371
22372
22373 \size footnotesize 
22374 \SpecialChar ~
22375 \SpecialChar ~
22376 jnc 00107$
22377 \layout Standard
22378
22379
22380 \size footnotesize 
22381 00115$:
22382 \layout Standard
22383
22384
22385 \size footnotesize 
22386 ; iTemp2 [lr18:40]{short}[r2] = iTemp2 [lr18:40]{short}[r2] + 
22387 \layout Standard
22388
22389
22390 \size footnotesize 
22391 ; iTemp21 [lr21:38]{short}[r4]
22392 \layout Standard
22393
22394
22395 \size footnotesize 
22396 \SpecialChar ~
22397 \SpecialChar ~
22398 mov a,r4
22399 \layout Standard
22400
22401
22402 \size footnotesize 
22403 \SpecialChar ~
22404 \SpecialChar ~
22405 add a,r2
22406 \layout Standard
22407
22408
22409 \size footnotesize 
22410 \SpecialChar ~
22411 \SpecialChar ~
22412 mov r2,a
22413 \layout Standard
22414
22415
22416 \size footnotesize 
22417 ; iTemp15 [lr29:30]{short}[r1] = iTemp21 [lr21:38]{short}[r4] * 0x3 {short}
22418 \layout Standard
22419
22420
22421 \size footnotesize 
22422 \SpecialChar ~
22423 \SpecialChar ~
22424 mov b,#0x03
22425 \layout Standard
22426
22427
22428 \size footnotesize 
22429 \SpecialChar ~
22430 \SpecialChar ~
22431 mov a,r4
22432 \layout Standard
22433
22434
22435 \size footnotesize 
22436 \SpecialChar ~
22437 \SpecialChar ~
22438 mul ab
22439 \layout Standard
22440
22441
22442 \size footnotesize 
22443 \SpecialChar ~
22444 \SpecialChar ~
22445 mov r1,a
22446 \layout Standard
22447
22448
22449 \size footnotesize 
22450 ; iTemp11 [lr19:40]{short}[r3] = iTemp11 [lr19:40]{short}[r3] + 
22451 \layout Standard
22452
22453
22454 \size footnotesize 
22455 ; iTemp15 [lr29:30]{short}[r1]
22456 \layout Standard
22457
22458
22459 \size footnotesize 
22460 \SpecialChar ~
22461 \SpecialChar ~
22462 add a,r3
22463 \layout Standard
22464
22465
22466 \size footnotesize 
22467 \SpecialChar ~
22468 \SpecialChar ~
22469 mov r3,a
22470 \layout Standard
22471
22472
22473 \size footnotesize 
22474 ; iTemp17 [lr23:38]{int}[r7 r0]= iTemp17 [lr23:38]{int}[r7 r0]- 0x3 {short}
22475 \layout Standard
22476
22477
22478 \size footnotesize 
22479 \SpecialChar ~
22480 \SpecialChar ~
22481 mov a,r7
22482 \layout Standard
22483
22484
22485 \size footnotesize 
22486 \SpecialChar ~
22487 \SpecialChar ~
22488 add a,#0xfd
22489 \layout Standard
22490
22491
22492 \size footnotesize 
22493 \SpecialChar ~
22494 \SpecialChar ~
22495 mov r7,a
22496 \layout Standard
22497
22498
22499 \size footnotesize 
22500 \SpecialChar ~
22501 \SpecialChar ~
22502 mov a,r0
22503 \layout Standard
22504
22505
22506 \size footnotesize 
22507 \SpecialChar ~
22508 \SpecialChar ~
22509 addc a,#0xff
22510 \layout Standard
22511
22512
22513 \size footnotesize 
22514 \SpecialChar ~
22515 \SpecialChar ~
22516 mov r0,a
22517 \layout Standard
22518
22519
22520 \size footnotesize 
22521 ; _gint [lr0:0]{int} = _gint [lr0:0]{int} + iTemp17 [lr23:38]{int}[r7 r0]
22522 \layout Standard
22523
22524
22525 \size footnotesize 
22526 \SpecialChar ~
22527 \SpecialChar ~
22528 mov a,r7
22529 \layout Standard
22530
22531
22532 \size footnotesize 
22533 \SpecialChar ~
22534 \SpecialChar ~
22535 add a,_gint
22536 \layout Standard
22537
22538
22539 \size footnotesize 
22540 \SpecialChar ~
22541 \SpecialChar ~
22542 mov _gint,a
22543 \layout Standard
22544
22545
22546 \size footnotesize 
22547 \SpecialChar ~
22548 \SpecialChar ~
22549 mov a,r0
22550 \layout Standard
22551
22552
22553 \size footnotesize 
22554 \SpecialChar ~
22555 \SpecialChar ~
22556 addc a,(_gint + 1)
22557 \layout Standard
22558
22559
22560 \size footnotesize 
22561 \SpecialChar ~
22562 \SpecialChar ~
22563 mov (_gint + 1),a
22564 \layout Standard
22565
22566
22567 \size footnotesize 
22568 ; iTemp21 [lr21:38]{short}[r4] = iTemp21 [lr21:38]{short}[r4] + 0x1 {short}
22569 \layout Standard
22570
22571
22572 \size footnotesize 
22573 \SpecialChar ~
22574 \SpecialChar ~
22575 inc r4
22576 \layout Standard
22577
22578
22579 \size footnotesize 
22580 ; iTemp23 [lr22:38]{int}[r5 r6]= iTemp23 [lr22:38]{int}[r5 r6]- 0x1 {short}
22581 \layout Standard
22582
22583
22584 \size footnotesize 
22585 \SpecialChar ~
22586 \SpecialChar ~
22587 dec r5
22588 \layout Standard
22589
22590
22591 \size footnotesize 
22592 \SpecialChar ~
22593 \SpecialChar ~
22594 cjne r5,#0xff,00104$
22595 \layout Standard
22596
22597
22598 \size footnotesize 
22599 \SpecialChar ~
22600 \SpecialChar ~
22601 dec r6
22602 \layout Standard
22603
22604
22605 \size footnotesize 
22606 ; goto _forcond_0($4)
22607 \layout Standard
22608
22609
22610 \size footnotesize 
22611 \SpecialChar ~
22612 \SpecialChar ~
22613 sjmp 00104$
22614 \layout Standard
22615
22616
22617 \size footnotesize 
22618 ; _forbreak_0($7) :
22619 \layout Standard
22620
22621
22622 \size footnotesize 
22623 00107$:
22624 \layout Standard
22625
22626
22627 \size footnotesize 
22628 ; ret iTemp24 [lr40:41]{short}
22629 \layout Standard
22630
22631
22632 \size footnotesize 
22633 \SpecialChar ~
22634 \SpecialChar ~
22635 mov a,r3
22636 \layout Standard
22637
22638
22639 \size footnotesize 
22640 \SpecialChar ~
22641 \SpecialChar ~
22642 add a,r2
22643 \layout Standard
22644
22645
22646 \size footnotesize 
22647 \SpecialChar ~
22648 \SpecialChar ~
22649 mov dpl,a
22650 \layout Standard
22651
22652
22653 \size footnotesize 
22654 ; _return($8) :
22655 \layout Standard
22656
22657
22658 \size footnotesize 
22659 00108$:
22660 \layout Standard
22661
22662
22663 \size footnotesize 
22664 \SpecialChar ~
22665 \SpecialChar ~
22666 ret
22667 \newline 
22668
22669 \layout Section
22670
22671 A few words about basic block successors, predecessors and dominators
22672 \layout Standard
22673
22674 Successors are basic blocks
22675 \begin_inset LatexCommand \index{Basic blocks}
22676
22677 \end_inset 
22678
22679  that might execute after this basic block.
22680 \newline 
22681 Predecessors are basic blocks that might execute before reaching this basic
22682  block.
22683 \newline 
22684 Dominators are basic blocks that WILL execute before reaching this basic
22685  block.
22686 \newline 
22687
22688 \layout Standard
22689
22690 [basic block 1]
22691 \layout Standard
22692
22693 if (something)
22694 \layout Standard
22695
22696 \SpecialChar ~
22697 \SpecialChar ~
22698 \SpecialChar ~
22699 \SpecialChar ~
22700 [basic block 2]
22701 \layout Standard
22702
22703 else
22704 \layout Standard
22705
22706 \SpecialChar ~
22707 \SpecialChar ~
22708 \SpecialChar ~
22709 \SpecialChar ~
22710 [basic block 3]
22711 \layout Standard
22712
22713 [basic block 4]
22714 \newline 
22715
22716 \layout Standard
22717
22718 a) succList of [BB2] = [BB4], of [BB3] = [BB4], of [BB1] = [BB2,BB3]
22719 \layout Standard
22720
22721 b) predList of [BB2] = [BB1], of [BB3] = [BB1], of [BB4] = [BB2,BB3]
22722 \layout Standard
22723
22724 c) domVect of [BB4] = BB1 ...
22725  here we are not sure if BB2 or BB3 was executed but we are SURE that BB1
22726  was executed.
22727 \layout Chapter
22728
22729 Acknowledgments
22730 \layout Standard
22731
22732
22733 \begin_inset LatexCommand \url{http://sdcc.sourceforge.net#Who}
22734
22735 \end_inset 
22736
22737
22738 \newline 
22739
22740 \newline 
22741
22742 \emph on 
22743 Thanks to all the other volunteer developers who have helped with coding,
22744  testing, web-page creation, distribution sets, etc.
22745  You know who you are :-)
22746 \emph default 
22747
22748 \newline 
22749
22750 \layout Standard
22751
22752 This document was initially written by Sandeep Dutta
22753 \layout Standard
22754
22755 All product names mentioned herein may be trademarks
22756 \begin_inset LatexCommand \index{Trademarks}
22757
22758 \end_inset 
22759
22760  of their respective companies.
22761  
22762 \layout Section*
22763
22764 Alphabetical index
22765 \layout Standard
22766
22767 To avoid confusion, the installation and building options for SDCC itself
22768  (chapter 2) are not part of the index.
22769 \layout Standard
22770
22771
22772 \begin_inset LatexCommand \printindex{}
22773
22774 \end_inset 
22775
22776
22777 \the_end