added Jesus's MSVC build notes
[fw/sdcc] / doc / sdccman.lyx
1 #LyX 1.2 created this file. For more info see http://www.lyx.org/
2 \lyxformat 220
3 \textclass article
4 \language english
5 \inputencoding default
6 \fontscheme pslatex
7 \graphics default
8 \paperfontsize default
9 \spacing single 
10 \papersize Default
11 \paperpackage a4
12 \use_geometry 0
13 \use_amsmath 0
14 \use_natbib 0
15 \use_numerical_citations 0
16 \paperorientation portrait
17 \secnumdepth 3
18 \tocdepth 3
19 \paragraph_separation indent
20 \defskip medskip
21 \quotes_language swedish
22 \quotes_times 2
23 \papercolumns 1
24 \papersides 1
25 \paperpagestyle fancy
26
27 \layout Title
28
29 SDCC Compiler User Guide
30 \layout Standard
31
32
33 \begin_inset LatexCommand \tableofcontents{}
34
35 \end_inset 
36
37
38 \layout Section
39
40 Introduction
41 \layout Subsection
42
43 About SDCC
44 \layout Standard
45
46
47 \series bold 
48 SDCC
49 \series default 
50  is a Freeware, retargettable, optimizing ANSI-C compiler by 
51 \series bold 
52 Sandeep Dutta
53 \series default 
54  designed for 8 bit Microprocessors.
55  The current version targets Intel MCS51 based Microprocessors(8051,8052,
56  etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant.
57  It can be retargetted for other microprocessors, support for PIC, AVR and
58  186 is under development.
59  The entire source code for the compiler is distributed under GPL.
60  SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker.
61  SDCC has extensive language extensions suitable for utilizing various microcont
62 rollers and underlying hardware effectively.
63  
64 \newline 
65
66 \newline 
67 In addition to the MCU specific optimizations SDCC also does a host of standard
68  optimizations like:
69 \layout Itemize
70
71 global sub expression elimination, 
72 \layout Itemize
73
74 loop optimizations (loop invariant, strength reduction of induction variables
75  and loop reversing), 
76 \layout Itemize
77
78 constant folding & propagation, 
79 \layout Itemize
80
81 copy propagation, 
82 \layout Itemize
83
84 dead code elimination 
85 \layout Itemize
86
87 jumptables for 
88 \emph on 
89 switch
90 \emph default 
91  statements.
92 \layout Standard
93
94 For the back-end SDCC uses a global register allocation scheme which should
95  be well suited for other 8 bit MCUs.
96  
97 \newline 
98
99 \newline 
100 The peep hole optimizer uses a rule based substitution mechanism which is
101  MCU independent.
102  
103 \newline 
104
105 \newline 
106 Supported data-types are:
107 \layout Itemize
108
109 char (8 bits, 1 byte), 
110 \layout Itemize
111
112 short and int (16 bits, 2 bytes), 
113 \layout Itemize
114
115 long (32 bit, 4 bytes)
116 \layout Itemize
117
118 float (4 byte IEEE).
119  
120 \layout Standard
121
122 The compiler also allows 
123 \emph on 
124 inline assembler code
125 \emph default 
126  to be embedded anywhere in a function.
127  In addition, routines developed in assembly can also be called.
128 \newline 
129
130 \newline 
131 SDCC also provides an option (--cyclomatic) to report the relative complexity
132  of a function.
133  These functions can then be further optimized, or hand coded in assembly
134  if needed.
135  
136 \newline 
137
138 \newline 
139 SDCC also comes with a companion source level debugger SDCDB, the debugger
140  currently uses ucSim a freeware simulator for 8051 and other micro-controllers.
141  
142 \newline 
143
144 \newline 
145 The latest version can be downloaded from 
146 \begin_inset LatexCommand \htmlurl{http://sdcc.sourceforge.net/}
147
148 \end_inset 
149
150
151 \series bold 
152 .
153 \layout Subsection
154
155 Open Source
156 \layout Standard
157
158 All packages used in this compiler system are 
159 \emph on 
160 opensource
161 \emph default 
162  and 
163 \emph on 
164 freeware
165 \emph default 
166 ; source code for all the sub-packages (pre-processor, assemblers, linkers
167  etc) is distributed with the package.
168  This documentation is maintained using a freeware word processor (LyX).
169 \newline 
170 This program is free software; you can redistribute it and/or modify it
171  under the terms of the GNU General Public License as published by the Free
172  Software Foundation; either version 2, or (at your option) any later version.
173  This program is distributed in the hope that it will be useful, but WITHOUT
174  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
175  FOR A PARTICULAR PURPOSE.
176  See the GNU General Public License for more details.
177  You should have received a copy of the GNU General Public License along
178  with this program; if not, write to the Free Software Foundation, 59 Temple
179  Place - Suite 330, Boston, MA 02111-1307, USA.
180  In other words, you are welcome to use, share and improve this program.
181  You are forbidden to forbid anyone else to use, share and improve what
182  you give them.
183  Help stamp out software-hoarding! 
184 \layout Subsection
185
186 Typographic conventions
187 \layout Standard
188
189 Throughout this manual, we will use the following convention.
190  Commands you have to type in are printed in 
191 \family sans 
192 \series bold 
193 "sans serif"
194 \series default 
195 .
196
197 \family default 
198  Code samples are printed in 
199 \family typewriter 
200 typewriter font.
201
202 \family default 
203  Interesting items and new terms are printed in 
204 \emph on 
205 italic.
206 \layout Subsection
207
208 Compatibility with previous versions
209 \layout Standard
210
211 This version has numerous bug fixes compared with the previous version.
212  But we also introduced some incompatibilities with older versions.
213  Not just for the fun of it, but to make the compiler more stable, efficient
214  and ANSI compliant.
215  
216 \newline 
217
218 \layout Itemize
219
220 short is now equivalent to int (16 bits), it used to be equivalent to char
221  (8 bits) which is not ANSI compliant
222 \layout Itemize
223
224 the default directory where include, library and documention files are stored
225  is now in /usr/local/share
226 \layout Itemize
227
228 char type parameters to vararg functions are casted to int unless explicitly
229  casted, e.g.: 
230 \newline 
231
232 \family typewriter 
233 \SpecialChar ~
234 \SpecialChar ~
235 char a=3;
236 \newline 
237 \SpecialChar ~
238 \SpecialChar ~
239 printf ("%d %c
240 \backslash 
241 n", a, (char)a);
242 \family default 
243
244 \newline 
245  will push a as an int and as a char resp.
246 \layout Itemize
247
248 option --regextend has been removed
249 \layout Itemize
250
251 option --noregparms has been removed
252 \layout Itemize
253
254 option --stack-after-data has been removed
255 \layout Standard
256
257
258 \emph on 
259 <pending: more incompatibilities?>
260 \layout Subsection
261
262 System Requirements
263 \layout Standard
264
265 What do you need before you start installation of SDCC? A computer, and
266  a desire to compute.
267  The preferred method of installation is to compile SDCC from source using
268  GNU gcc and make.
269  For Windows some pre-compiled binary distributions are available for your
270  convenience.
271  You should have some experience with command line tools and compiler use.
272 \layout Subsection
273
274 Other Resources
275 \layout Standard
276
277 The SDCC home page at 
278 \begin_inset LatexCommand \htmlurl{http://sdcc.sourceforge.net/}
279
280 \end_inset 
281
282  is a great place to find distribution sets.
283  You can also find links to the user mailing lists that offer help or discuss
284  SDCC with other SDCC users.
285  Web links to other SDCC related sites can also be found here.
286  This document can be found in the DOC directory of the source package as
287  a text or HTML file.
288  Some of the other tools (simulator and assembler) included with SDCC contain
289  their own documentation and can be found in the source distribution.
290  If you want the latest unreleased software, the complete source package
291  is available directly by anonymous CVS on cvs.sdcc.sourceforge.net.
292 \layout Subsection
293
294 Wishes for the future
295 \layout Standard
296
297 There are (and always will be) some things that could be done.
298  Here are some I can think of:
299 \newline 
300
301 \layout Standard
302
303
304 \family typewriter 
305 char KernelFunction3(char p) at 0x340;
306 \newline 
307
308 \newline 
309
310 \family default 
311 If you can think of some more, please send them to the list.
312 \newline 
313
314 \newline 
315
316 \emph on 
317 <pending: And then of course a proper index-table
318 \begin_inset LatexCommand \index{index}
319
320 \end_inset 
321
322 >
323 \layout Section
324
325 Installation
326 \layout Subsection
327
328 Linux/Unix Installation
329 \layout Enumerate
330
331
332 \series medium 
333 Download the source package, it will be named something like sdcc-
334 \series default 
335 x
336 \series medium 
337 .x.x.tgz.
338 \layout Enumerate
339
340
341 \series medium 
342 Bring up a command line terminal, such as xterm.
343 \layout Enumerate
344
345
346 \series medium 
347 Unpack the file using a command like: 
348 \family sans 
349 \series bold 
350 "tar -xzf sdcc-x.x.x.tgz
351 \family default 
352 \series default 
353 "
354 \series medium 
355 , this will create a sub-directory called sdcc with all of the sources.
356 \layout Enumerate
357
358 Change directory into the main SDCC directory, for example type: 
359 \family sans 
360 \series bold 
361 "cd sdcc
362 \series default 
363 ".
364 \layout Enumerate
365
366
367 \series medium 
368 Type 
369 \family sans 
370 \series bold 
371 "./configure
372 \family default 
373 \series default 
374 ".
375  This configures the package for compilation on your system.
376 \layout Enumerate
377
378
379 \series medium 
380 Type 
381 \family sans 
382 \series bold 
383 "make
384 \family default 
385 \series default 
386 "
387 \series medium 
388 .
389
390 \series default 
391  All of the source packages will compile, this can take a while.
392 \layout Enumerate
393
394
395 \series medium 
396 Type 
397 \family sans 
398 \series bold 
399 "make install"
400 \family default 
401 \series default 
402  as root
403 \series medium 
404 .
405
406 \series default 
407  This copies the binary executables, the include files, the libraries and
408  the documentation to the install directories.
409 \layout Subsection
410
411 Windows Installation
412 \layout Standard
413
414
415 \emph on 
416 <pending: is this complete? where is borland, mingw>
417 \newline 
418
419 \layout Subsubsection
420
421 Windows Install Using a Binary Package
422 \layout Enumerate
423
424 Download the binary package and unpack it using your favorite unpacking
425  tool (gunzip, WinZip, etc).
426  This should unpack to a group of sub-directories.
427  An example directory structure after unpacking is: c:
428 \backslash 
429 usr
430 \backslash 
431 local
432 \backslash 
433 bin for the executables, c:
434 \backslash 
435 usr
436 \backslash 
437 local
438 \backslash 
439 share
440 \backslash 
441 sdcc
442 \backslash 
443 include and c:
444 \backslash 
445 usr
446 \backslash 
447 local
448 \backslash 
449 share
450 \backslash 
451 sdcc
452 \backslash 
453 lib for the include and libraries.
454 \layout Enumerate
455
456 Adjust your environment PATH to include the location of the bin directory.
457  For example, make a setsdcc.bat file with the following: set PATH=c:
458 \backslash 
459 usr
460 \backslash 
461 local
462 \backslash 
463 bin;%PATH%
464 \layout Enumerate
465
466 When you compile with sdcc, you may need to specify the location of the
467  lib and include folders.
468  For example, sdcc test.c -I c:
469 \backslash 
470 usr
471 \backslash 
472 local
473 \backslash 
474 share
475 \backslash 
476 sdcc
477 \backslash 
478 include -L c:
479 \backslash 
480 usr
481 \backslash 
482 local
483 \backslash 
484 share
485 \backslash 
486 sdcc
487 \backslash 
488 lib
489 \backslash 
490 small
491 \layout Subsubsection
492
493 Windows Install Using Cygwin
494 \layout Enumerate
495
496
497 \series medium 
498 Download and install the cygwin package from the redhat site
499 \series default 
500
501 \begin_inset LatexCommand \htmlurl{http://sources.redhat.com/cygwin/}
502
503 \end_inset 
504
505
506 \series medium 
507 .
508  Currently, this involved downloading a small install program which then
509  automates downloading and installing 
510 \series default 
511 selected parts of
512 \series medium 
513  the package
514 \series default 
515  (a large 80M byte sized dowload for the whole thing)
516 \series medium 
517 .
518
519 \series default 
520  
521 \layout Enumerate
522
523
524 \series medium 
525 Bring up a 
526 \series default 
527 Unix/Bash 
528 \series medium 
529 command line terminal from the Cygwin menu.
530 \layout Enumerate
531
532
533 \series medium 
534 Follow the instructions in the preceding Linux/Unix installation section
535 \layout Subsubsection
536
537 Windows Install Using Microsoft Visual C++ 6.0/NET
538 \layout Standard
539
540 (By Jesus Calvino-Fraga (jesus@ieee.org) Jan/31/2003, many thanks to "Borut
541  Razem" <borut.razem@siol.net> for fixing all the sources, projects, and workspace
542  so to build SDCC with Visual C++).
543 \newline 
544
545 \newline 
546 SDCC is distributed with all the projects, workspaces, and files you need
547  to build it using Visual C++ 6.0/NET.
548  The workspace name is 'sdcc.dsw'.
549  Please note that as it is now, all the executables are created in a folder
550  called sdcc
551 \backslash 
552 bin_vc.
553  Once built you need to copy the executables from sdcc
554 \backslash 
555 bin_vc to sdcc
556 \backslash 
557 bin before runnng SDCC.
558  
559 \newline 
560
561 \newline 
562 In order to build SDCC with Visual C++ 6.0/NET you need win32 executables
563  of bison.exe, flex.exe, and gawk.exe.
564  One good place to get them is 
565 \begin_inset LatexCommand \url[here]{http://unxutils.sourceforge.net}
566
567 \end_inset 
568
569
570 \newline 
571
572 \newline 
573 Download the file UnxUtils.zip.
574  Now you have to install the utilities and setup Visual C++ so it can locate
575  the required programs.
576  Here there are two alternatives (choose one!):
577 \layout Enumerate
578
579 The easy way:
580 \newline 
581
582 \newline 
583 a) Extract UnxUtils.zip to your C:
584 \backslash 
585  hard disk PRESERVING the original paths, otherwise bison won't work.
586  (If you are using WinZip make certain that 'Use folder names' is selected)
587 \newline 
588
589 \newline 
590 b) In the Visual C++ IDE click Tools, Options, select the Directory tab,
591  in 'Show directories for:' select 'Executable files', and in the directories
592  window add a new path: 'C:
593 \backslash 
594 user
595 \backslash 
596 local
597 \backslash 
598 wbin', click ok.
599 \newline 
600
601 \newline 
602 (As a side effect, you get a bunch of Unix utilities that could be useful,
603  such as diff and patch.)
604 \layout Enumerate
605
606 A more compact way:
607 \newline 
608
609 \newline 
610 This one avoids extracting a bunch of files you may not use, but requires
611  some extra work:
612 \newline 
613
614 \newline 
615 a) Create a directory were to put the tools needed, or use a directory already
616  present.
617  Say for example 'C:
618 \backslash 
619 util'.
620 \newline 
621
622 \newline 
623 b) Extract 'bison.exe', 'bison.hairy', 'bison.simple', 'flex.exe', and gawk.exe
624  to such directory WITHOUT preserving the original paths.
625  (If you are using WinZip make certain that 'Use folder names' is not selected)
626 \newline 
627
628 \newline 
629 c) Rename bison.exe to '_bison.exe'.
630 \newline 
631
632 \newline 
633 d) Create a batch file 'bison.bat' in 'C:
634 \backslash 
635 util
636 \backslash 
637 ' and add these lines: 
638 \newline 
639 \SpecialChar ~
640 \SpecialChar ~
641 set BISON_SIMPLE=C:
642 \backslash 
643 util
644 \backslash 
645 bison.simple 
646 \newline 
647 \SpecialChar ~
648 \SpecialChar ~
649 set BISON_HAIRY=C:
650 \backslash 
651 util
652 \backslash 
653 bison.hairy
654 \newline 
655 \SpecialChar ~
656 \SpecialChar ~
657 _bison %1 %2 %3 %4 %5 %6 %7 %8 %9
658 \newline 
659
660 \newline 
661 Steps 'c' and 'd' are needed because bison requires by default that the
662  files 'bison.simple' and 'bison.hairy' reside in some weird Unix directory,
663  '/usr/local/share/' I think.
664  So it is necessary to tell bison where those files are located if they
665  are not in such directory.
666  That is the function of the environment variables BISON_SIMPLE and BISON_HAIRY.
667 \newline 
668
669 \newline 
670 e) In the Visual C++ IDE click Tools, Options, select the Directory tab,
671  in 'Show directories for:' select 'Executable files', and in the directories
672  window add a new path: 'c:
673 \backslash 
674 util', click ok.
675  Note that you can use any other path instead of 'c:
676 \backslash 
677 util', even the path where the Visual C++ tools are, probably: 'C:
678 \backslash 
679 Program Files
680 \backslash 
681 Microsoft Visual Studio
682 \backslash 
683 Common
684 \backslash 
685 Tools'.
686  So you don't have to execute step 'e' :)
687 \layout Standard
688
689 That is it.
690  Open 'sdcc.dsw' in Visual Studio, click 'build all', when it finishes copy
691  the executables from sdcc
692 \backslash 
693 bin_vc to sdcc
694 \backslash 
695 bin, and you can compile using sdcc.
696 \layout Subsection
697
698 Testing out the SDCC Compiler
699 \layout Standard
700
701 The first thing you should do after installing your SDCC compiler is to
702  see if it runs.
703  Type 
704 \family sans 
705 \series bold 
706 "sdcc --version"
707 \family default 
708 \series default 
709  at the prompt, and the program should run and tell you the version.
710  If it doesn't run, or gives a message about not finding sdcc program, then
711  you need to check over your installation.
712  Make sure that the sdcc bin directory is in your executable search path
713  defined by the PATH environment setting (see the Trouble-shooting section
714  for suggestions).
715  Make sure that the sdcc program is in the bin folder, if not perhaps something
716  did not install correctly.
717 \newline 
718
719 \newline 
720
721 \series medium 
722 SDCC binaries are commonly installed in a directory arrangement like this:
723 \series default 
724
725 \newline 
726
727 \newline 
728
729 \begin_inset  Tabular
730 <lyxtabular version="3" rows="3" columns="2">
731 <features>
732 <column alignment="left" valignment="top" leftline="true" width="0(null)">
733 <column alignment="left" valignment="top" leftline="true" rightline="true" width="0(null)">
734 <row topline="true" bottomline="true">
735 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
736 \begin_inset Text
737
738 \layout Standard
739
740 /
741 \series medium 
742 usr/local/bin
743 \end_inset 
744 </cell>
745 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
746 \begin_inset Text
747
748 \layout Standard
749
750
751 \series medium 
752 Holds executables(sdcc, s51, aslink, 
753 \series default 
754 ...
755 \series medium 
756 )
757 \end_inset 
758 </cell>
759 </row>
760 <row topline="true">
761 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
762 \begin_inset Text
763
764 \layout Standard
765
766 /
767 \series medium 
768 usr/local/share/sdcc/lib 
769 \end_inset 
770 </cell>
771 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
772 \begin_inset Text
773
774 \layout Standard
775
776
777 \series medium 
778 Holds common C 
779 \series default 
780 libraries
781 \end_inset 
782 </cell>
783 </row>
784 <row topline="true" bottomline="true">
785 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
786 \begin_inset Text
787
788 \layout Standard
789
790 /
791 \series medium 
792 usr/local/share/sdcc/include
793 \end_inset 
794 </cell>
795 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
796 \begin_inset Text
797
798 \layout Standard
799
800
801 \series medium 
802 Holds common C header files
803 \end_inset 
804 </cell>
805 </row>
806 </lyxtabular>
807
808 \end_inset 
809
810
811 \newline 
812
813 \newline 
814
815 \series medium 
816 Make sure the compiler works on a very simple example.
817  Type in the following test.c program using your favorite editor:
818 \series default 
819
820 \newline 
821
822 \family typewriter 
823
824 \newline 
825 char test;
826 \newline 
827
828 \newline 
829 void main(void) {
830 \newline 
831 \SpecialChar ~
832 \SpecialChar ~
833 \SpecialChar ~
834 \SpecialChar ~
835 test=0;
836 \newline 
837 }
838 \family default 
839
840 \newline 
841
842 \emph on 
843
844 \newline 
845
846 \series medium 
847 \emph default 
848 Compile this using the following command: 
849 \family sans 
850 \series bold 
851 "sdcc -c test.c".
852
853 \family default 
854 \series default 
855  
856 \series medium 
857 If all goes well, the compiler will generate a test.asm and test.rel file.
858  Congratulations, you've just compiled your first program with SDCC.
859  We used the -c option to tell SDCC not to link the generated code, just
860  to keep things simple for this step.
861 \series default 
862
863 \newline 
864
865 \newline 
866
867 \series medium 
868 The next step is to try it with the linker.
869  Type in 
870 \family sans 
871 \series bold 
872 "sdcc test.c
873 \family default 
874 \series default 
875 "
876 \series medium 
877 .
878  If all goes well the compiler will link with the libraries and produce
879  a test.ihx output file.
880  If this step fails
881 \series default 
882  
883 \series medium 
884 (no test.ihx, and the linker generates warnings), then the problem is most
885  likely that sdcc cannot find the 
886 \series default 
887 /
888 \series medium 
889 usr/local/share/sdcc/lib directory
890 \series default 
891  
892 \series medium 
893 (see the Install trouble-shooting section for suggestions).
894 \series default 
895
896 \newline 
897
898 \newline 
899
900 \series medium 
901 The final test is to ensure sdcc can use the 
902 \series default 
903 standard
904 \series medium 
905  header files and libraries.
906  Edit test.c and change it to the following:
907 \series default 
908
909 \newline 
910
911 \newline 
912
913 \family typewriter 
914 #include <string.h>
915 \newline 
916
917 \newline 
918 char str1[10];
919 \newline 
920
921 \newline 
922 void main(void) {
923 \newline 
924 \SpecialChar ~
925 \SpecialChar ~
926 strcpy(str1, "testing");
927 \newline 
928 }
929 \newline 
930
931 \newline 
932
933 \family default 
934 \series medium 
935 Compile this by typing 
936 \family sans 
937 \series bold 
938 "sdcc test.c"
939 \family default 
940 \series medium 
941 .
942  This should generate a test.ihx output file, and it should give no warnings
943  such as not finding the string.h file.
944  If it cannot find the string.h file, then the problem is that sdcc cannot
945  find the /usr/local/share/sdcc/include directory
946 \series default 
947  
948 \series medium 
949 (see the Install trouble-shooting section for suggestions).
950 \layout Subsection
951
952 Install Trouble-shooting
953 \layout Subsubsection
954
955 SDCC cannot find libraries or header files.
956 \layout Standard
957
958 The default installation assumes the libraries and header files are located
959  at 
960 \begin_inset Quotes eld
961 \end_inset 
962
963 /usr/local/share/sdcc/lib
964 \begin_inset Quotes erd
965 \end_inset 
966
967  and 
968 \begin_inset Quotes eld
969 \end_inset 
970
971 /usr/local/share/sdcc/include
972 \begin_inset Quotes erd
973 \end_inset 
974
975 .
976  An alternative is to specify these locations as compiler options like this:
977  
978 \family sans 
979 \series bold 
980 "sdcc\SpecialChar ~
981 -L\SpecialChar ~
982 /usr/local/sdcc/lib/small\SpecialChar ~
983 -I\SpecialChar ~
984 /usr/local/sdcc/include\SpecialChar ~
985 test.c"
986 \family default 
987 \series default 
988 .
989 \layout Subsubsection
990
991 SDCC does not compile correctly.
992 \layout Standard
993
994 A thing to try is starting from scratch by unpacking the .tgz source package
995  again in an empty directory.
996  Confure it like:
997 \newline 
998
999 \newline 
1000
1001 \family typewriter 
1002 ./configure 2&>1 | tee configure.log
1003 \family default 
1004
1005 \newline 
1006
1007 \newline 
1008 and build it like:
1009 \newline 
1010
1011 \newline 
1012
1013 \family typewriter 
1014 make 2&>1 | tee make.log
1015 \family default 
1016
1017 \newline 
1018
1019 \newline 
1020 If anything goes wrong, you can review the log files to locate the problem.
1021  Or a relevant part of this can be attached to an email that could be helpful
1022  when requesting help from the mailing list.
1023 \layout Subsubsection
1024
1025 What the 
1026 \begin_inset Quotes sld
1027 \end_inset 
1028
1029 ./configure
1030 \begin_inset Quotes srd
1031 \end_inset 
1032
1033  does
1034 \layout Standard
1035
1036 The 
1037 \begin_inset Quotes sld
1038 \end_inset 
1039
1040 ./configure
1041 \begin_inset Quotes srd
1042 \end_inset 
1043
1044  command is a script that analyzes your system and performs some configuration
1045  to ensure the source package compiles on your system.
1046  It will take a few minutes to run, and will compile a few tests to determine
1047  what compiler features are installed.
1048 \layout Subsubsection
1049
1050 What the 
1051 \begin_inset Quotes sld
1052 \end_inset 
1053
1054 make
1055 \begin_inset Quotes srd
1056 \end_inset 
1057
1058  does.
1059 \layout Standard
1060
1061 This runs the GNU make tool, which automatically compiles all the source
1062  packages into the final installed binary executables.
1063 \layout Subsubsection
1064
1065 What the 
1066 \begin_inset Quotes sld
1067 \end_inset 
1068
1069 make install
1070 \begin_inset Quotes erd
1071 \end_inset 
1072
1073  command does.
1074 \layout Standard
1075
1076 This will install the compiler, other executables and libraries in to the
1077  appropriate system directories.
1078  The default is to copy the executables to /usr/local/bin and the libraries
1079  and header files to /usr/local/share/sdcc/lib and /usr/local/share/sdcc/include.
1080  On most systems you will need super-user privilages to do this.
1081 \layout Subsection
1082
1083 Advanced Install Options
1084 \layout Standard
1085
1086 The 
1087 \begin_inset Quotes eld
1088 \end_inset 
1089
1090 configure
1091 \begin_inset Quotes erd
1092 \end_inset 
1093
1094  command has several options.
1095  The most commonly used option is --prefix=<directory name>, where <directory
1096  name> is the final location for the sdcc executables and libraries, (default
1097  location is /usr/local).
1098  The installation process will create the following directory structure
1099  under the <directory name> specified (if they do not already exist).
1100  
1101 \newline 
1102
1103 \newline 
1104 bin/ - binary exectables (add to PATH environment variable)
1105 \newline 
1106 bin/share/
1107 \newline 
1108 bin/share/sdcc/include/ - include header files
1109 \newline 
1110 bin/share/sdcc/lib/
1111 \newline 
1112 bin/share/sdcc/lib/small/ - Object & library files for small model library
1113 \newline 
1114 bin/share/sdcc/lib/large/ - Object & library files for large model library
1115 \newline 
1116 bin/share/sdcc/lib/ds390/ - Object & library files forDS80C390 library
1117 \newline 
1118
1119 \newline 
1120 The command 
1121 \family sans 
1122 \series bold 
1123
1124 \begin_inset Quotes sld
1125 \end_inset 
1126
1127 ./configure --prefix=/usr/local
1128 \begin_inset Quotes erd
1129 \end_inset 
1130
1131  
1132 \family default 
1133 \series default 
1134 will configure the compiler to be installed in directory /usr/local.
1135 \layout Subsection
1136
1137 Components of SDCC
1138 \layout Standard
1139
1140 SDCC is not just a compiler, but a collection of tools by various developers.
1141  These include linkers, assemblers, simulators and other components.
1142  Here is a summary of some of the components.
1143  Note that the included simulator and assembler have separate documentation
1144  which you can find in the source package in their respective directories.
1145  As SDCC grows to include support for other processors, other packages from
1146  various developers are included and may have their own sets of documentation.
1147 \newline 
1148
1149 \newline 
1150 You might want to look at the files which are installed in <installdir>.
1151  At the time of this writing, we find the following programs:
1152 \newline 
1153  
1154 \newline 
1155 In <installdir>/bin:
1156 \layout Itemize
1157
1158 sdcc - The compiler.
1159 \layout Itemize
1160
1161 sdcpp - The C preprocessor.
1162 \layout Itemize
1163
1164 asx8051 - The assembler for 8051 type processors.
1165 \layout Itemize
1166
1167 as-z80
1168 \series bold 
1169
1170 \series default 
1171 as-gbz80 - The Z80 and GameBoy Z80 assemblers.
1172 \layout Itemize
1173
1174 aslink -The linker for 8051 type processors.
1175 \layout Itemize
1176
1177 link-z80
1178 \series bold 
1179
1180 \series default 
1181 link-gbz80 - The Z80 and GameBoy Z80 linkers.
1182 \layout Itemize
1183
1184 s51 - The ucSim 8051 simulator.
1185 \layout Itemize
1186
1187 sdcdb - The source debugger.
1188 \layout Itemize
1189
1190 packihx - A tool to pack (compress) Intel hex files.
1191 \layout Standard
1192
1193 In <installdir>/share/sdcc/include
1194 \layout Itemize
1195
1196 the include files
1197 \layout Standard
1198
1199 In <installdir>/share/sdcc/lib
1200 \layout Itemize
1201
1202 the sources of the runtime library and the subdirs small large and ds390
1203  with the precompiled relocatables.
1204 \layout Standard
1205
1206 In <installdir>/share/sdcc/doc
1207 \layout Itemize
1208
1209 the documentation
1210 \layout Standard
1211
1212 As development for other processors proceeds, this list will expand to include
1213  executables to support processors like AVR, PIC, etc.
1214 \layout Subsubsection
1215
1216 sdcc - The Compiler
1217 \layout Standard
1218
1219 This is the actual compiler, it in turn uses the c-preprocessor and invokes
1220  the assembler and linkage editor.
1221 \layout Subsubsection
1222
1223 sdcpp - The C-Preprocessor)
1224 \layout Standard
1225
1226 The preprocessor is a modified version of the GNU preprocessor.
1227  The C preprocessor is used to pull in #include sources, process #ifdef
1228  statements, #defines and so on.
1229 \layout Subsubsection
1230
1231 asx8051, as-z80, as-gbz80, aslink, link-z80, link-gbz80 - The Assemblers
1232  and Linkage Editors
1233 \layout Standard
1234
1235 This is retargettable assembler & linkage editor, it was developed by Alan
1236  Baldwin.
1237  John Hartman created the version for 8051, and I (Sandeep) have made some
1238  enhancements and bug fixes for it to work properly with the SDCC.
1239 \layout Subsubsection
1240
1241 s51 - The Simulator
1242 \layout Standard
1243
1244 S51 is a freeware, opensource simulator developed by Daniel Drotos (
1245 \begin_inset LatexCommand \url{mailto:drdani@mazsola.iit.uni-miskolc.hu}
1246
1247 \end_inset 
1248
1249 ).
1250  The simulator is built as part of the build process.
1251  For more information visit Daniel's website at: 
1252 \begin_inset LatexCommand \url{http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51}
1253
1254 \end_inset 
1255
1256 .
1257  It currently support the core mcs51, the Dallas DS80C390 and the Philips
1258  XA51 family.
1259 \layout Subsubsection
1260
1261 sdcdb - Source Level Debugger
1262 \layout Standard
1263
1264
1265 \family typewriter 
1266 \shape italic 
1267 <todo: is this thing alive?>
1268 \newline 
1269
1270 \newline 
1271
1272 \family default 
1273 \shape default 
1274 Sdcdb is the companion source level debugger.
1275  The current version of the debugger uses Daniel's Simulator S51, but can
1276  be easily changed to use other simulators.
1277 \layout Section
1278
1279 Using SDCC
1280 \layout Subsection
1281
1282 Compiling
1283 \layout Subsubsection
1284
1285 Single Source File Projects
1286 \layout Standard
1287
1288 For single source file 8051 projects the process is very simple.
1289  Compile your programs with the following command 
1290 \family sans 
1291 \series bold 
1292 "sdcc sourcefile.c".
1293
1294 \family default 
1295 \series default 
1296  This will compile, assemble and link your source file.
1297  Output files are as follows
1298 \newline 
1299
1300 \newline 
1301 sourcefile.asm - Assembler source file created by the compiler
1302 \newline 
1303 sourcefile.lst - Assembler listing file created by the Assembler
1304 \newline 
1305 sourcefile.rst - Assembler listing file updated with linkedit information,
1306  created by linkage editor
1307 \newline 
1308 sourcefile.sym - symbol listing for the sourcefile, created by the assembler
1309 \newline 
1310 sourcefile.rel - Object file created by the assembler, input to Linkage editor
1311 \newline 
1312 sourcefile.map - The memory map for the load module, created by the Linker
1313 \newline 
1314 sourcefile.ihx - The load module in Intel hex format (you can select the
1315  Motorola S19 format with --out-fmt-s19)
1316 \newline 
1317 sourcefile.cdb - An optional file (with --debug) containing debug information
1318 \newline 
1319
1320 \layout Subsubsection
1321
1322 Projects with Multiple Source Files
1323 \layout Standard
1324
1325 SDCC can compile only ONE file at a time.
1326  Let us for example assume that you have a project containing the following
1327  files:
1328 \newline 
1329
1330 \newline 
1331 foo1.c (contains some functions)
1332 \newline 
1333 foo2.c (contains some more functions)
1334 \newline 
1335 foomain.c (contains more functions and the function main)
1336 \newline 
1337
1338 \size footnotesize 
1339
1340 \newline 
1341
1342 \size default 
1343 The first two files will need to be compiled separately with the commands:
1344 \size footnotesize 
1345  
1346 \size default 
1347
1348 \newline 
1349
1350 \newline 
1351
1352 \family sans 
1353 \series bold 
1354 sdcc\SpecialChar ~
1355 -c\SpecialChar ~
1356 foo1.c
1357 \family default 
1358 \series default 
1359 \size footnotesize 
1360
1361 \newline 
1362
1363 \family sans 
1364 \series bold 
1365 \size default 
1366 sdcc\SpecialChar ~
1367 -c\SpecialChar ~
1368 foo2.c
1369 \family default 
1370 \series default 
1371
1372 \newline 
1373
1374 \newline 
1375 Then compile the source file containing the 
1376 \emph on 
1377 main()
1378 \emph default 
1379  function and link the files together with the following command: 
1380 \newline 
1381
1382 \newline 
1383
1384 \family sans 
1385 \series bold 
1386 sdcc\SpecialChar ~
1387 foomain.c\SpecialChar ~
1388 foo1.rel\SpecialChar ~
1389 foo2.rel
1390 \family default 
1391 \series default 
1392
1393 \newline 
1394
1395 \newline 
1396 Alternatively, 
1397 \emph on 
1398 foomain.c 
1399 \emph default 
1400 can be separately compiled as well: 
1401 \family sans 
1402 \series bold 
1403
1404 \newline 
1405
1406 \newline 
1407 sdcc\SpecialChar ~
1408 -c\SpecialChar ~
1409 foomain.c
1410 \newline 
1411 sdcc foomain.rel foo1.rel foo2.rel
1412 \newline 
1413
1414 \newline 
1415
1416 \family default 
1417 \series default 
1418 The file containing the 
1419 \emph on 
1420 main()
1421 \emph default 
1422  function
1423 \emph on 
1424  
1425 \emph default 
1426 \noun on 
1427 must
1428 \noun default 
1429  be the 
1430 \noun on 
1431 first
1432 \noun default 
1433  file specified in the command line, since the linkage editor processes
1434  file in the order they are presented to it.
1435 \layout Subsubsection
1436
1437 Projects with Additional Libraries
1438 \layout Standard
1439
1440 Some reusable routines may be compiled into a library, see the documentation
1441  for the assembler and linkage editor (which are in <installdir>/share/sdcc/doc)
1442  for how to create a 
1443 \emph on 
1444 .lib
1445 \emph default 
1446  library file.
1447  Libraries created in this manner can be included in the command line.
1448  Make sure you include the -L <library-path> option to tell the linker where
1449  to look for these files if they are not in the current directory.
1450  Here is an example, assuming you have the source file 
1451 \emph on 
1452 foomain.c
1453 \emph default 
1454  and a library
1455 \emph on 
1456  foolib.lib
1457 \emph default 
1458  in the directory 
1459 \emph on 
1460 mylib
1461 \emph default 
1462  (if that is not the same as your current project):
1463 \newline 
1464
1465 \newline 
1466
1467 \family sans 
1468 \series bold 
1469 sdcc foomain.c foolib.lib -L mylib
1470 \newline 
1471
1472 \newline 
1473
1474 \family default 
1475 \series default 
1476 Note here that
1477 \emph on 
1478  mylib
1479 \emph default 
1480  must be an absolute path name.
1481 \newline 
1482
1483 \newline 
1484 The most efficient way to use libraries is to keep seperate modules in seperate
1485  source files.
1486  The lib file now should name all the modules.rel files.
1487  For an example see the standard library file 
1488 \emph on 
1489 libsdcc.lib
1490 \emph default 
1491  in the directory <installdir>/share/lib/small.
1492 \layout Subsection
1493
1494 Command Line Options
1495 \layout Subsubsection
1496
1497 Processor Selection Options
1498 \layout List
1499 \labelwidthstring 00.00.0000
1500
1501
1502 \series bold 
1503 -mmcs51
1504 \series default 
1505  Generate code for the MCS51 (8051) family of processors.
1506  This is the default processor target.
1507 \layout List
1508 \labelwidthstring 00.00.0000
1509
1510
1511 \series bold 
1512 -mds390
1513 \series default 
1514  Generate code for the DS80C390 processor.
1515 \layout List
1516 \labelwidthstring 00.00.0000
1517
1518
1519 \series bold 
1520 -mz80
1521 \series default 
1522  Generate code for the Z80 family of processors.
1523 \layout List
1524 \labelwidthstring 00.00.0000
1525
1526
1527 \series bold 
1528 -mgbz80
1529 \series default 
1530  Generate code for the GameBoy Z80 processor.
1531 \layout List
1532 \labelwidthstring 00.00.0000
1533
1534
1535 \series bold 
1536 -mavr
1537 \series default 
1538  Generate code for the Atmel AVR processor (In development, not complete).
1539 \layout List
1540 \labelwidthstring 00.00.0000
1541
1542
1543 \series bold 
1544 -mpic14
1545 \series default 
1546  Generate code for the PIC 14-bit processors (In development, not complete).
1547 \layout List
1548 \labelwidthstring 00.00.0000
1549
1550
1551 \series bold 
1552 -mtlcs900h
1553 \series default 
1554  Generate code for the Toshiba TLCS-900H processor (In development, not
1555  complete).
1556 \layout List
1557 \labelwidthstring 00.00.0000
1558
1559
1560 \series bold 
1561 -mxa51
1562 \series default 
1563  Generate code for the Philips XA51 processor (In development, not complete).
1564 \layout Subsubsection
1565
1566 Preprocessor Options
1567 \layout List
1568 \labelwidthstring 00.00.0000
1569
1570
1571 \series bold 
1572 -I<path>
1573 \series default 
1574  The additional location where the pre processor will look for <..h> or 
1575 \begin_inset Quotes eld
1576 \end_inset 
1577
1578 ..h
1579 \begin_inset Quotes erd
1580 \end_inset 
1581
1582  files.
1583 \layout List
1584 \labelwidthstring 00.00.0000
1585
1586
1587 \series bold 
1588 -D<macro[=value]>
1589 \series default 
1590  Command line definition of macros.
1591  Passed to the pre processor.
1592 \layout List
1593 \labelwidthstring 00.00.0000
1594
1595
1596 \series bold 
1597 -M
1598 \series default 
1599  Tell the preprocessor to output a rule suitable for make describing the
1600  dependencies of each object file.
1601  For each source file, the preprocessor outputs one make-rule whose target
1602  is the object file name for that source file and whose dependencies are
1603  all the files `#include'd in it.
1604  This rule may be a single line or may be continued with `
1605 \backslash 
1606 '-newline if it is long.
1607  The list of rules is printed on standard output instead of the preprocessed
1608  C program.
1609  `-M' implies `-E'.
1610 \layout List
1611 \labelwidthstring 00.00.0000
1612
1613
1614 \series bold 
1615 -C
1616 \series default 
1617  Tell the preprocessor not to discard comments.
1618  Used with the `-E' option.
1619 \layout List
1620 \labelwidthstring 00.00.0000
1621
1622
1623 \series bold 
1624 -MM
1625 \size large 
1626 \bar under 
1627  
1628 \series default 
1629 \size default 
1630 \bar default 
1631 Like `-M' but the output mentions only the user header files included with
1632  `#include 
1633 \begin_inset Quotes eld
1634 \end_inset 
1635
1636 file"'.
1637  System header files included with `#include <file>' are omitted.
1638 \layout List
1639 \labelwidthstring 00.00.0000
1640
1641
1642 \series bold 
1643 -Aquestion(answer)
1644 \series default 
1645  Assert the answer answer for question, in case it is tested with a preprocessor
1646  conditional such as `#if #question(answer)'.
1647  `-A-' disables the standard assertions that normally describe the target
1648  machine.
1649 \layout List
1650 \labelwidthstring 00.00.0000
1651
1652
1653 \series bold 
1654 -Aquestion
1655 \series default 
1656  (answer) Assert the answer answer for question, in case it is tested with
1657  a preprocessor conditional such as `#if #question(answer)'.
1658  `-A-' disables the standard assertions that normally describe the target
1659  machine.
1660 \layout List
1661 \labelwidthstring 00.00.0000
1662
1663
1664 \series bold 
1665 -Umacro
1666 \series default 
1667  Undefine macro macro.
1668  `-U' options are evaluated after all `-D' options, but before any `-include'
1669  and `-imacros' options.
1670 \layout List
1671 \labelwidthstring 00.00.0000
1672
1673
1674 \series bold 
1675 -dM
1676 \series default 
1677  Tell the preprocessor to output only a list of the macro definitions that
1678  are in effect at the end of preprocessing.
1679  Used with the `-E' option.
1680 \layout List
1681 \labelwidthstring 00.00.0000
1682
1683
1684 \series bold 
1685 -dD
1686 \series default 
1687  Tell the preprocessor to pass all macro definitions into the output, in
1688  their proper sequence in the rest of the output.
1689 \layout List
1690 \labelwidthstring 00.00.0000
1691
1692
1693 \series bold 
1694 -dN
1695 \size large 
1696 \bar under 
1697  
1698 \series default 
1699 \size default 
1700 \bar default 
1701 Like `-dD' except that the macro arguments and contents are omitted.
1702  Only `#define name' is included in the output.
1703 \layout Subsubsection
1704
1705 Linker Options
1706 \layout List
1707 \labelwidthstring 00.00.0000
1708
1709
1710 \series bold 
1711 -L\SpecialChar ~
1712 --lib-path
1713 \bar under 
1714  
1715 \series default 
1716 \bar default 
1717 <absolute path to additional libraries> This option is passed to the linkage
1718  editor's additional libraries search path.
1719  The path name must be absolute.
1720  Additional library files may be specified in the command line.
1721  See section Compiling programs for more details.
1722 \layout List
1723 \labelwidthstring 00.00.0000
1724
1725
1726 \series bold 
1727 --xram-loc
1728 \series default 
1729 <Value> The start location of the external ram, default value is 0.
1730  The value entered can be in Hexadecimal or Decimal format, e.g.: --xram-loc
1731  0x8000 or --xram-loc 32768.
1732 \layout List
1733 \labelwidthstring 00.00.0000
1734
1735
1736 \series bold 
1737 --code-loc
1738 \series default 
1739 <Value> The start location of the code segment, default value 0.
1740  Note when this option is used the interrupt vector table is also relocated
1741  to the given address.
1742  The value entered can be in Hexadecimal or Decimal format, e.g.: --code-loc
1743  0x8000 or --code-loc 32768.
1744 \layout List
1745 \labelwidthstring 00.00.0000
1746
1747
1748 \series bold 
1749 --stack-loc
1750 \series default 
1751 <Value> The initial value of the stack pointer.
1752  The default value of the stack pointer is 0x07 if only register bank 0
1753  is used, if other register banks are used then the stack pointer is initialized
1754  to the location above the highest register bank used.
1755  eg.
1756  if register banks 1 & 2 are used the stack pointer will default to location
1757  0x18.
1758  The value entered can be in Hexadecimal or Decimal format, eg.
1759  --stack-loc 0x20 or --stack-loc 32.
1760  If all four register banks are used the stack will be placed after the
1761  data segment (equivalent to --stack-after-data)
1762 \layout List
1763 \labelwidthstring 00.00.0000
1764
1765
1766 \series bold 
1767 --data-loc
1768 \series default 
1769 <Value> The start location of the internal ram data segment, the default
1770  value is 0x30.The value entered can be in Hexadecimal or Decimal format,
1771  eg.
1772  --data-loc 0x20 or --data-loc 32.
1773 \layout List
1774 \labelwidthstring 00.00.0000
1775
1776
1777 \series bold 
1778 --idata-loc
1779 \series default 
1780 <Value> The start location of the indirectly addressable internal ram, default
1781  value is 0x80.
1782  The value entered can be in Hexadecimal or Decimal format, eg.
1783  --idata-loc 0x88 or --idata-loc 136.
1784 \layout List
1785 \labelwidthstring 00.00.0000
1786
1787
1788 \series bold 
1789 --out-fmt-ihx
1790 \bar under 
1791  
1792 \series default 
1793 \bar default 
1794 The linker output (final object code) is in Intel Hex format.
1795  (This is the default option).
1796 \layout List
1797 \labelwidthstring 00.00.0000
1798
1799
1800 \series bold 
1801 --out-fmt-s19
1802 \bar under 
1803  
1804 \series default 
1805 \bar default 
1806 The linker output (final object code) is in Motorola S19 format.
1807 \layout Subsubsection
1808
1809 MCS51 Options
1810 \layout List
1811 \labelwidthstring 00.00.0000
1812
1813
1814 \series bold 
1815 --model-large
1816 \series default 
1817  Generate code for Large model programs see section Memory Models for more
1818  details.
1819  If this option is used all source files in the project should be compiled
1820  with this option.
1821  In addition the standard library routines are compiled with small model,
1822  they will need to be recompiled.
1823 \layout List
1824 \labelwidthstring 00.00.0000
1825
1826
1827 \series bold 
1828 --model-small
1829 \series default 
1830 \size large 
1831 \emph on 
1832  
1833 \size default 
1834 \emph default 
1835 Generate code for Small Model programs see section Memory Models for more
1836  details.
1837  This is the default model.
1838 \layout Subsubsection
1839
1840 DS390 Options
1841 \layout List
1842 \labelwidthstring 00.00.0000
1843
1844
1845 \series bold 
1846 --model-flat24
1847 \series default 
1848 \size large 
1849 \emph on 
1850  
1851 \size default 
1852 \emph default 
1853 Generate 24-bit flat mode code.
1854  This is the one and only that the ds390 code generator supports right now
1855  and is default when using 
1856 \emph on 
1857 -mds390
1858 \emph default 
1859 .
1860  See section Memory Models for more details.
1861 \layout List
1862 \labelwidthstring 00.00.0000
1863
1864
1865 \series bold 
1866 --stack-10bit
1867 \series default 
1868  Generate code for the 10 bit stack mode of the Dallas DS80C390 part.
1869  This is the one and only that the ds390 code generator supports right now
1870  and is default when using 
1871 \emph on 
1872 -mds390
1873 \emph default 
1874 .
1875  In this mode, the stack is located in the lower 1K of the internal RAM,
1876  which is mapped to 0x400000.
1877  Note that the support is incomplete, since it still uses a single byte
1878  as the stack pointer.
1879  This means that only the lower 256 bytes of the potential 1K stack space
1880  will actually be used.
1881  However, this does allow you to reclaim the precious 256 bytes of low RAM
1882  for use for the DATA and IDATA segments.
1883  The compiler will not generate any code to put the processor into 10 bit
1884  stack mode.
1885  It is important to ensure that the processor is in this mode before calling
1886  any re-entrant functions compiled with this option.
1887  In principle, this should work with the 
1888 \emph on 
1889 --stack-auto
1890 \emph default 
1891  option, but that has not been tested.
1892  It is incompatible with the 
1893 \emph on 
1894 --xstack
1895 \emph default 
1896  option.
1897  It also only makes sense if the processor is in 24 bit contiguous addressing
1898  mode (see the 
1899 \emph on 
1900 --model-flat24 option
1901 \emph default 
1902 ).
1903 \layout Subsubsection
1904
1905 Optimization Options
1906 \layout List
1907 \labelwidthstring 00.00.0000
1908
1909
1910 \series bold 
1911 --nogcse
1912 \series default 
1913  Will not do global subexpression elimination, this option may be used when
1914  the compiler creates undesirably large stack/data spaces to store compiler
1915  temporaries.
1916  A warning message will be generated when this happens and the compiler
1917  will indicate the number of extra bytes it allocated.
1918  It recommended that this option NOT be used, #pragma\SpecialChar ~
1919 NOGCSE can be used
1920  to turn off global subexpression elimination for a given function only.
1921 \layout List
1922 \labelwidthstring 00.00.0000
1923
1924
1925 \series bold 
1926 --noinvariant
1927 \series default 
1928  Will not do loop invariant optimizations, this may be turned off for reasons
1929  explained for the previous option.
1930  For more details of loop optimizations performed see section Loop Invariants.It
1931  recommended that this option NOT be used, #pragma\SpecialChar ~
1932 NOINVARIANT can be used
1933  to turn off invariant optimizations for a given function only.
1934 \layout List
1935 \labelwidthstring 00.00.0000
1936
1937
1938 \series bold 
1939 --noinduction
1940 \series default 
1941  Will not do loop induction optimizations, see section strength reduction
1942  for more details.It is recommended that this option is NOT used, #pragma\SpecialChar ~
1943 NOINDUCT
1944 ION can be used to turn off induction optimizations for a given function
1945  only.
1946 \layout List
1947 \labelwidthstring 00.00.0000
1948
1949
1950 \series bold 
1951 --nojtbound
1952 \size large 
1953 \bar under 
1954  
1955 \series default 
1956 \size default 
1957 \bar default 
1958  Will not generate boundary condition check when switch statements are implement
1959 ed using jump-tables.
1960  See section Switch Statements for more details.
1961  It is recommended that this option is NOT used, #pragma\SpecialChar ~
1962 NOJTBOUND can be
1963  used to turn off boundary checking for jump tables for a given function
1964  only.
1965 \layout List
1966 \labelwidthstring 00.00.0000
1967
1968
1969 \series bold 
1970 --noloopreverse
1971 \series default 
1972 \size large 
1973  
1974 \size default 
1975 Will not do loop reversal optimization.
1976 \layout List
1977 \labelwidthstring 00.00.0000
1978
1979
1980 \series bold 
1981 --no-xinit-opt
1982 \series default 
1983  This will disable the memcpy of initialized data in far space from code
1984  space
1985 \layout Subsubsection
1986
1987 Other Options
1988 \layout List
1989 \labelwidthstring 00.00.0000
1990
1991
1992 \series bold 
1993 -c\SpecialChar ~
1994 --compile-only
1995 \series default 
1996  will compile and assemble the source, but will not call the linkage editor.
1997 \layout List
1998 \labelwidthstring 00.00.0000
1999
2000
2001 \series bold 
2002 -E
2003 \series default 
2004  Run only the C preprocessor.
2005  Preprocess all the C source files specified and output the results to standard
2006  output.
2007 \layout List
2008 \labelwidthstring 00.00.0000
2009
2010
2011 \series bold 
2012 --stack-auto
2013 \series default 
2014 \size large 
2015 \emph on 
2016  
2017 \size default 
2018 \emph default 
2019 All functions in the source file will be compiled as 
2020 \emph on 
2021 reentrant
2022 \emph default 
2023 , i.e.
2024  the parameters and local variables will be allocated on the stack.
2025  see section Parameters and Local Variables for more details.
2026  If this option is used all source files in the project should be compiled
2027  with this option.
2028  
2029 \layout List
2030 \labelwidthstring 00.00.0000
2031
2032
2033 \series bold 
2034 --xstack
2035 \series default 
2036  Uses a pseudo stack in the first 256 bytes in the external ram for allocating
2037  variables and passing parameters.
2038  See section on external stack for more details.
2039 \layout List
2040 \labelwidthstring 00.00.0000
2041
2042
2043 \series bold 
2044 --callee-saves function1[,function2][,function3]....
2045
2046 \series default 
2047  The compiler by default uses a caller saves convention for register saving
2048  across function calls, however this can cause unneccessary register pushing
2049  & popping when calling small functions from larger functions.
2050  This option can be used to switch the register saving convention for the
2051  function names specified.
2052  The compiler will not save registers when calling these functions, no extra
2053  code will be generated at the entry & exit for these functions to save
2054  & restore the registers used by these functions, this can SUBSTANTIALLY
2055  reduce code & improve run time performance of the generated code.
2056  In the future the compiler (with interprocedural analysis) will be able
2057  to determine the appropriate scheme to use for each function call.
2058  DO NOT use this option for built-in functions such as _muluint..., if this
2059  option is used for a library function the appropriate library function
2060  needs to be recompiled with the same option.
2061  If the project consists of multiple source files then all the source file
2062  should be compiled with the same --callee-saves option string.
2063  Also see #pragma\SpecialChar ~
2064 CALLEE-SAVES.
2065 \layout List
2066 \labelwidthstring 00.00.0000
2067
2068
2069 \series bold 
2070 --debug
2071 \bar under 
2072  
2073 \series default 
2074 \bar default 
2075 When this option is used the compiler will generate debug information, that
2076  can be used with the SDCDB.
2077  The debug information is collected in a file with .cdb extension.
2078  For more information see documentation for SDCDB.
2079 \layout List
2080 \labelwidthstring 00.00.0000
2081
2082
2083 \series bold 
2084 \emph on 
2085 --regextend
2086 \bar under 
2087  
2088 \series default 
2089 \bar default 
2090  This option is obsolete and isn't supported anymore.
2091 \layout List
2092 \labelwidthstring 00.00.0000
2093
2094
2095 \series bold 
2096 \emph on 
2097 --noregparms
2098 \series default 
2099  This option is obsolete and isn't supported anymore.
2100 \layout List
2101 \labelwidthstring 00.00.0000
2102
2103
2104 \series bold 
2105 --peep-file
2106 \series default 
2107 <filename> This option can be used to use additional rules to be used by
2108  the peep hole optimizer.
2109  See section Peep Hole optimizations for details on how to write these rules.
2110 \layout List
2111 \labelwidthstring 00.00.0000
2112
2113
2114 \series bold 
2115 -S
2116 \size large 
2117 \bar under 
2118  
2119 \series default 
2120 \size default 
2121 \bar default 
2122 Stop after the stage of compilation proper; do not assemble.
2123  The output is an assembler code file for the input file specified.
2124 \layout List
2125 \labelwidthstring 00.00.0000
2126
2127
2128 \series bold 
2129 -Wa_asmOption[,asmOption]
2130 \series default 
2131 ...
2132  Pass the asmOption to the assembler.
2133 \layout List
2134 \labelwidthstring 00.00.0000
2135
2136
2137 \series bold 
2138 -Wl_linkOption[,linkOption]
2139 \series default 
2140 ...
2141  Pass the linkOption to the linker.
2142 \layout List
2143 \labelwidthstring 00.00.0000
2144
2145
2146 \series bold 
2147 --int-long-reent
2148 \series default 
2149 \size large 
2150  
2151 \size default 
2152  Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
2153  Note by default these libraries are compiled as non-reentrant.
2154  See section Installation for more details.
2155 \layout List
2156 \labelwidthstring 00.00.0000
2157
2158
2159 \series bold 
2160 --cyclomatic
2161 \bar under 
2162  
2163 \series default 
2164 \bar default 
2165 This option will cause the compiler to generate an information message for
2166  each function in the source file.
2167  The message contains some 
2168 \emph on 
2169 important
2170 \emph default 
2171  information about the function.
2172  The number of edges and nodes the compiler detected in the control flow
2173  graph of the function, and most importantly the 
2174 \emph on 
2175 cyclomatic complexity
2176 \emph default 
2177  see section on Cyclomatic Complexity for more details.
2178 \layout List
2179 \labelwidthstring 00.00.0000
2180
2181
2182 \series bold 
2183 --float-reent
2184 \bar under 
2185  
2186 \series default 
2187 \bar default 
2188  Floating point library is compiled as reentrant.See section Installation
2189  for more details.
2190 \layout List
2191 \labelwidthstring 00.00.0000
2192
2193
2194 \series bold 
2195 --nooverlay
2196 \series default 
2197   The compiler will not overlay parameters and local variables of any function,
2198  see section Parameters and local variables for more details.
2199 \layout List
2200 \labelwidthstring 00.00.0000
2201
2202
2203 \series bold 
2204 --main-return
2205 \series default 
2206  This option can be used when the code generated is called by a monitor
2207  program.
2208  The compiler will generate a 'ret' upon return from the 'main' function.
2209  The default option is to lock up i.e.
2210  generate a 'ljmp '.
2211 \layout List
2212 \labelwidthstring 00.00.0000
2213
2214
2215 \series bold 
2216 --no-peep
2217 \series default 
2218   Disable peep-hole optimization.
2219 \layout List
2220 \labelwidthstring 00.00.0000
2221
2222
2223 \series bold 
2224 --peep-asm
2225 \series default 
2226   Pass the inline assembler code through the peep hole optimizer.
2227  This can cause unexpected changes to inline assembler code, please go through
2228  the peephole optimizer rules defined in the source file tree '<target>/peeph.def
2229 ' before using this option.
2230 \layout List
2231 \labelwidthstring 00.00.0000
2232
2233
2234 \series bold 
2235 --iram-size
2236 \series default 
2237 <Value> Causes the linker to check if the interal ram usage is within limits
2238  of the given value.
2239 \layout List
2240 \labelwidthstring 00.00.0000
2241
2242
2243 \series bold 
2244 --nostdincl
2245 \series default 
2246  This will prevent the compiler from passing on the default include path
2247  to the preprocessor.
2248 \layout List
2249 \labelwidthstring 00.00.0000
2250
2251
2252 \series bold 
2253 --nostdlib
2254 \series default 
2255  This will prevent the compiler from passing on the default library path
2256  to the linker.
2257 \layout List
2258 \labelwidthstring 00.00.0000
2259
2260
2261 \series bold 
2262 --verbose
2263 \series default 
2264  Shows the various actions the compiler is performing.
2265 \layout List
2266 \labelwidthstring 00.00.0000
2267
2268
2269 \series bold 
2270 -V
2271 \series default 
2272  Shows the actual commands the compiler is executing.
2273 \layout Subsubsection
2274
2275 Intermediate Dump Options
2276 \layout Standard
2277
2278 The following options are provided for the purpose of retargetting and debugging
2279  the compiler.
2280  These provided a means to dump the intermediate code (iCode) generated
2281  by the compiler in human readable form at various stages of the compilation
2282  process.
2283  
2284 \layout List
2285 \labelwidthstring 00.00.0000
2286
2287
2288 \series bold 
2289 --dumpraw
2290 \series default 
2291  This option will cause the compiler to dump the intermediate code into
2292  a file of named 
2293 \emph on 
2294 <source filename>.dumpraw
2295 \emph default 
2296  just after the intermediate code has been generated for a function, i.e.
2297  before any optimizations are done.
2298  The basic blocks at this stage ordered in the depth first number, so they
2299  may not be in sequence of execution.
2300 \layout List
2301 \labelwidthstring 00.00.0000
2302
2303
2304 \series bold 
2305 --dumpgcse
2306 \series default 
2307  Will create a dump of iCode's, after global subexpression elimination,
2308  into a file named 
2309 \emph on 
2310 <source filename>.dumpgcse.
2311 \layout List
2312 \labelwidthstring 00.00.0000
2313
2314
2315 \series bold 
2316 --dumpdeadcode
2317 \series default 
2318  Will create a dump of iCode's, after deadcode elimination, into a file
2319  named 
2320 \emph on 
2321 <source filename>.dumpdeadcode.
2322 \layout List
2323 \labelwidthstring 00.00.0000
2324
2325
2326 \series bold 
2327 --dumploop
2328 \series default 
2329 \size large 
2330  
2331 \size default 
2332 Will create a dump of iCode's, after loop optimizations, into a file named
2333  
2334 \emph on 
2335 <source filename>.dumploop.
2336 \layout List
2337 \labelwidthstring 00.00.0000
2338
2339
2340 \series bold 
2341 --dumprange
2342 \series default 
2343 \size large 
2344  
2345 \size default 
2346 Will create a dump of iCode's, after live range analysis, into a file named
2347  
2348 \emph on 
2349 <source filename>.dumprange.
2350 \layout List
2351 \labelwidthstring 00.00.0000
2352
2353
2354 \series bold 
2355 --dumlrange
2356 \series default 
2357  Will dump the life ranges for all symbols.
2358 \layout List
2359 \labelwidthstring 00.00.0000
2360
2361
2362 \series bold 
2363 --dumpregassign
2364 \bar under 
2365  
2366 \series default 
2367 \bar default 
2368 Will create a dump of iCode's, after register assignment, into a file named
2369  
2370 \emph on 
2371 <source filename>.dumprassgn.
2372 \layout List
2373 \labelwidthstring 00.00.0000
2374
2375
2376 \series bold 
2377 --dumplrange
2378 \series default 
2379  Will create a dump of the live ranges of iTemp's
2380 \layout List
2381 \labelwidthstring 00.00.0000
2382
2383
2384 \series bold 
2385 --dumpall
2386 \size large 
2387 \bar under 
2388  
2389 \series default 
2390 \size default 
2391 \bar default 
2392 Will cause all the above mentioned dumps to be created.
2393 \layout Subsection
2394
2395 MCS51/DS390 Storage Class Language Extensions
2396 \layout Standard
2397
2398 In addition to the ANSI storage classes SDCC allows the following MCS51
2399  specific storage classes.
2400 \layout Subsubsection
2401
2402 xdata
2403 \layout Standard
2404
2405 Variables declared with this storage class will be placed in the extern
2406  RAM.
2407  This is the 
2408 \series bold 
2409 default
2410 \series default 
2411  storage class for Large Memory model, e.g.:
2412 \newline 
2413
2414 \newline 
2415
2416 \family typewriter 
2417 xdata unsigned char xduc;
2418 \layout Subsubsection
2419
2420 data
2421 \layout Standard
2422
2423 This is the 
2424 \series bold 
2425 default
2426 \series default 
2427  storage class for Small Memory model.
2428  Variables declared with this storage class will be allocated in the internal
2429  RAM, e.g.:
2430 \newline 
2431
2432 \newline 
2433
2434 \family typewriter 
2435 data int iramdata;
2436 \layout Subsubsection
2437
2438 idata
2439 \layout Standard
2440
2441 Variables declared with this storage class will be allocated into the indirectly
2442  addressable portion of the internal ram of a 8051, e.g.:
2443 \newline 
2444
2445 \newline 
2446
2447 \family typewriter 
2448 idata int idi;
2449 \layout Subsubsection
2450
2451 bit
2452 \layout Standard
2453
2454 This is a data-type and a storage class specifier.
2455  When a variable is declared as a bit, it is allocated into the bit addressable
2456  memory of 8051, e.g.:
2457 \newline 
2458
2459 \newline 
2460
2461 \family typewriter 
2462 bit iFlag;
2463 \layout Subsubsection
2464
2465 sfr / sbit
2466 \layout Standard
2467
2468 Like the bit keyword, 
2469 \emph on 
2470 sfr / sbit 
2471 \emph default 
2472 signifies both a data-type and storage class, they are used to describe
2473  the special function registers and special bit variables of a 8051, eg:
2474 \newline 
2475
2476 \newline 
2477
2478 \family typewriter 
2479 sfr at 0x80 P0; /* special function register P0 at location 0x80 */
2480 \newline 
2481 sbit at 0xd7 CY; /* CY (Carry Flag) */
2482 \layout Subsection
2483
2484 Pointers
2485 \layout Standard
2486
2487 SDCC allows (via language extensions) pointers to explicitly point to any
2488  of the memory spaces of the 8051.
2489  In addition to the explicit pointers, the compiler uses (by default) generic
2490  pointers which can be used to point to any of the memory spaces.
2491 \newline 
2492
2493 \newline 
2494 Pointer declaration examples:
2495 \newline 
2496
2497 \size small 
2498
2499 \newline 
2500
2501 \family typewriter 
2502 \size default 
2503 /* pointer physically in xternal ram pointing to object in internal ram
2504  */ 
2505 \newline 
2506 data unsigned char * xdata p;
2507 \newline 
2508
2509 \newline 
2510 /* pointer physically in code rom pointing to data in xdata space */ 
2511 \newline 
2512 xdata unsigned char * code p;
2513 \newline 
2514
2515 \newline 
2516 /* pointer physically in code space pointing to data in code space */ 
2517 \newline 
2518 code unsigned char * code p;
2519 \newline 
2520
2521 \newline 
2522 /* the folowing is a generic pointer physically located in xdata space */
2523 \newline 
2524 char * xdata p;
2525 \family default 
2526 \size small 
2527
2528 \newline 
2529
2530 \newline 
2531
2532 \size default 
2533 Well you get the idea.
2534  
2535 \newline 
2536
2537 \newline 
2538 All unqualified pointers are treated as 3-byte (4-byte for the ds390) 
2539 \emph on 
2540 generic
2541 \emph default 
2542  pointers.
2543  
2544 \size small 
2545
2546 \newline 
2547
2548 \newline 
2549
2550 \size default 
2551 The highest order byte of the 
2552 \emph on 
2553 generic
2554 \emph default 
2555  pointers contains the data space information.
2556  Assembler support routines are called whenever data is stored or retrieved
2557  using 
2558 \emph on 
2559 generic
2560 \emph default 
2561  pointers.
2562  These are useful for developing reusable library routines.
2563  Explicitly specifying the pointer type will generate the most efficient
2564  code.
2565 \layout Subsection
2566
2567 Parameters & Local Variables
2568 \layout Standard
2569
2570 Automatic (local) variables and parameters to functions can either be placed
2571  on the stack or in data-space.
2572  The default action of the compiler is to place these variables in the internal
2573  RAM (for small model) or external RAM (for large model).
2574  This in fact makes them 
2575 \emph on 
2576 static
2577 \emph default 
2578  so by default functions are non-reentrant.
2579 \newline 
2580
2581 \newline 
2582 They can be placed on the stack either by using the
2583 \emph on 
2584  --stack-auto
2585 \emph default 
2586  option or by using the 
2587 \emph on 
2588 reentrant
2589 \emph default 
2590  keyword in the function declaration, e.g.:
2591 \newline 
2592
2593 \size small 
2594
2595 \newline 
2596
2597 \family typewriter 
2598 \size default 
2599 unsigned char foo(char i) reentrant 
2600 \newline 
2601
2602 \newline 
2603 ...
2604  
2605 \newline 
2606 }
2607 \newline 
2608
2609 \family default 
2610
2611 \newline 
2612 Since stack space on 8051 is limited, the 
2613 \emph on 
2614 reentrant 
2615 \emph default 
2616 keyword or the
2617 \emph on 
2618  --stack-auto
2619 \emph default 
2620  option should be used sparingly.
2621  Note that the reentrant keyword just means that the parameters & local
2622  variables will be allocated to the stack, it 
2623 \emph on 
2624 does not
2625 \emph default 
2626  mean that the function is register bank independent.
2627 \newline 
2628
2629 \newline 
2630 Local variables can be assigned storage classes and absolute addresses,
2631  e.g.: 
2632 \newline 
2633
2634 \newline 
2635
2636 \family typewriter 
2637 unsigned char foo() {
2638 \newline 
2639 \SpecialChar ~
2640 \SpecialChar ~
2641 \SpecialChar ~
2642 \SpecialChar ~
2643 xdata unsigned char i;
2644 \newline 
2645 \SpecialChar ~
2646 \SpecialChar ~
2647 \SpecialChar ~
2648 \SpecialChar ~
2649 bit bvar;
2650 \newline 
2651 \SpecialChar ~
2652 \SpecialChar ~
2653 \SpecialChar ~
2654 \SpecialChar ~
2655 data at 0x31 unsiged char j;
2656 \newline 
2657 \SpecialChar ~
2658 \SpecialChar ~
2659 \SpecialChar ~
2660 \SpecialChar ~
2661 ...
2662  
2663 \newline 
2664 }
2665 \newline 
2666
2667 \newline 
2668
2669 \family default 
2670 In the above example the variable 
2671 \emph on 
2672 i
2673 \emph default 
2674  will be allocated in the external ram, 
2675 \emph on 
2676 bvar
2677 \emph default 
2678  in bit addressable space and
2679 \emph on 
2680  j
2681 \emph default 
2682  in internal ram.
2683  When compiled with 
2684 \emph on 
2685 --stack-auto
2686 \emph default 
2687  or when a function is declared as 
2688 \emph on 
2689 reentrant
2690 \emph default 
2691  this should only be done for static variables.
2692 \layout Standard
2693
2694 Parameters however are not allowed any storage class, (storage classes for
2695  parameters will be ignored), their allocation is governed by the memory
2696  model in use, and the reentrancy options.
2697 \layout Subsection
2698
2699 Overlaying
2700 \layout Standard
2701
2702 For non-reentrant functions SDCC will try to reduce internal ram space usage
2703  by overlaying parameters and local variables of a function (if possible).
2704  Parameters and local variables of a function will be allocated to an overlayabl
2705 e segment if the function has 
2706 \emph on 
2707 no other function calls and the function is non-reentrant and the memory
2708  model is small.
2709
2710 \emph default 
2711  If an explicit storage class is specified for a local variable, it will
2712  NOT be overlayed.
2713 \layout Standard
2714
2715 Note that the compiler (not the linkage editor) makes the decision for overlayin
2716 g the data items.
2717  Functions that are called from an interrupt service routine should be preceded
2718  by a #pragma\SpecialChar ~
2719 NOOVERLAY if they are not reentrant.
2720 \layout Standard
2721
2722 Also note that the compiler does not do any processing of inline assembler
2723  code, so the compiler might incorrectly assign local variables and parameters
2724  of a function into the overlay segment if the inline assembler code calls
2725  other c-functions that might use the overlay.
2726  In that case the #pragma\SpecialChar ~
2727 NOOVERLAY should be used.
2728 \layout Standard
2729
2730 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
2731 tion or division will NOT be overlayed since these are implemented using
2732  external functions, e.g.:
2733 \newline 
2734
2735 \newline 
2736
2737 \family typewriter 
2738 #pragma SAVE 
2739 \newline 
2740 #pragma NOOVERLAY 
2741 \newline 
2742 void set_error(unsigned char errcd) 
2743 \newline 
2744 {
2745 \newline 
2746 \SpecialChar ~
2747 \SpecialChar ~
2748 \SpecialChar ~
2749 \SpecialChar ~
2750 P3 = errcd;
2751 \newline 
2752
2753 \newline 
2754 #pragma RESTORE 
2755 \newline 
2756
2757 \newline 
2758 void some_isr () interrupt 2 using 1 
2759 \newline 
2760 {
2761 \newline 
2762 \SpecialChar ~
2763 \SpecialChar ~
2764 \SpecialChar ~
2765 \SpecialChar ~
2766 ...
2767 \newline 
2768 \SpecialChar ~
2769 \SpecialChar ~
2770 \SpecialChar ~
2771 \SpecialChar ~
2772 set_error(10);
2773 \newline 
2774 \SpecialChar ~
2775 \SpecialChar ~
2776 \SpecialChar ~
2777 \SpecialChar ~
2778 ...
2779  
2780 \newline 
2781 }
2782 \newline 
2783
2784 \newline 
2785
2786 \family default 
2787 In the above example the parameter 
2788 \emph on 
2789 errcd
2790 \emph default 
2791  for the function 
2792 \emph on 
2793 set_error
2794 \emph default 
2795  would be assigned to the overlayable segment if the #pragma\SpecialChar ~
2796 NOOVERLAY was
2797  not present, this could cause unpredictable runtime behavior when called
2798  from an ISR.
2799  The #pragma\SpecialChar ~
2800 NOOVERLAY ensures that the parameters and local variables for
2801  the function are NOT overlayed.
2802 \layout Subsection
2803
2804 Interrupt Service Routines
2805 \layout Standard
2806
2807 SDCC allows interrupt service routines to be coded in C, with some extended
2808  keywords.
2809 \newline 
2810
2811 \newline 
2812
2813 \family typewriter 
2814 void timer_isr (void) interrupt 2 using 1 
2815 \newline 
2816
2817 \newline 
2818 ..
2819  
2820 \newline 
2821 }
2822 \newline 
2823
2824 \newline 
2825
2826 \family default 
2827 The number following the 
2828 \emph on 
2829 interrupt
2830 \emph default 
2831  keyword is the interrupt number this routine will service.
2832  The compiler will insert a call to this routine in the interrupt vector
2833  table for the interrupt number specified.
2834  The 
2835 \emph on 
2836 using
2837 \emph default 
2838  keyword is used to tell the compiler to use the specified register bank
2839  (8051 specific) when generating code for this function.
2840  Note that when some function is called from an interrupt service routine
2841  it should be preceded by a #pragma\SpecialChar ~
2842 NOOVERLAY if it is not reentrant.
2843  A special note here, int (16 bit) and long (32 bit) integer division, multiplic
2844 ation & modulus operations are implemented using external support routines
2845  developed in ANSI-C, if an interrupt service routine needs to do any of
2846  these operations then the support routines (as mentioned in a following
2847  section) will have to be recompiled using the
2848 \emph on 
2849  --stack-auto
2850 \emph default 
2851  option and the source file will need to be compiled using the 
2852 \emph on 
2853 --int-long-ren
2854 \emph default 
2855 t compiler option.
2856 \layout Standard
2857
2858 If you have multiple source files in your project, interrupt service routines
2859  can be present in any of them, but a prototype of the isr MUST be present
2860  or included in the file that contains the function 
2861 \emph on 
2862 main
2863 \emph default 
2864 .
2865 \layout Standard
2866
2867 Interrupt Numbers and the corresponding address & descriptions for the Standard
2868  8051 are listed below.
2869  SDCC will automatically adjust the interrupt vector table to the maximum
2870  interrupt number specified.
2871 \newline 
2872
2873 \layout Standard
2874
2875
2876 \begin_inset  Tabular
2877 <lyxtabular version="3" rows="6" columns="3">
2878 <features>
2879 <column alignment="center" valignment="top" leftline="true" width="0(null)">
2880 <column alignment="center" valignment="top" leftline="true" width="0(null)">
2881 <column alignment="center" valignment="top" leftline="true" rightline="true" width="0(null)">
2882 <row topline="true" bottomline="true">
2883 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2884 \begin_inset Text
2885
2886 \layout Standard
2887
2888 Interrupt #
2889 \end_inset 
2890 </cell>
2891 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2892 \begin_inset Text
2893
2894 \layout Standard
2895
2896 Description
2897 \end_inset 
2898 </cell>
2899 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2900 \begin_inset Text
2901
2902 \layout Standard
2903
2904 Vector Address
2905 \end_inset 
2906 </cell>
2907 </row>
2908 <row topline="true">
2909 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2910 \begin_inset Text
2911
2912 \layout Standard
2913
2914 0
2915 \end_inset 
2916 </cell>
2917 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2918 \begin_inset Text
2919
2920 \layout Standard
2921
2922 External 0
2923 \end_inset 
2924 </cell>
2925 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2926 \begin_inset Text
2927
2928 \layout Standard
2929
2930 0x0003
2931 \end_inset 
2932 </cell>
2933 </row>
2934 <row topline="true">
2935 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2936 \begin_inset Text
2937
2938 \layout Standard
2939
2940 1
2941 \end_inset 
2942 </cell>
2943 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2944 \begin_inset Text
2945
2946 \layout Standard
2947
2948 Timer 0
2949 \end_inset 
2950 </cell>
2951 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2952 \begin_inset Text
2953
2954 \layout Standard
2955
2956 0x000B
2957 \end_inset 
2958 </cell>
2959 </row>
2960 <row topline="true">
2961 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2962 \begin_inset Text
2963
2964 \layout Standard
2965
2966 2
2967 \end_inset 
2968 </cell>
2969 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2970 \begin_inset Text
2971
2972 \layout Standard
2973
2974 External 1
2975 \end_inset 
2976 </cell>
2977 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
2978 \begin_inset Text
2979
2980 \layout Standard
2981
2982 0x0013
2983 \end_inset 
2984 </cell>
2985 </row>
2986 <row topline="true">
2987 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2988 \begin_inset Text
2989
2990 \layout Standard
2991
2992 3
2993 \end_inset 
2994 </cell>
2995 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
2996 \begin_inset Text
2997
2998 \layout Standard
2999
3000 Timer 1
3001 \end_inset 
3002 </cell>
3003 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3004 \begin_inset Text
3005
3006 \layout Standard
3007
3008 0x001B
3009 \end_inset 
3010 </cell>
3011 </row>
3012 <row topline="true" bottomline="true">
3013 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3014 \begin_inset Text
3015
3016 \layout Standard
3017
3018 4
3019 \end_inset 
3020 </cell>
3021 <cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3022 \begin_inset Text
3023
3024 \layout Standard
3025
3026 Serial
3027 \end_inset 
3028 </cell>
3029 <cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
3030 \begin_inset Text
3031
3032 \layout Standard
3033
3034 0x0023
3035 \end_inset 
3036 </cell>
3037 </row>
3038 </lyxtabular>
3039
3040 \end_inset 
3041
3042
3043 \newline 
3044
3045 \newline 
3046 If the interrupt service routine is defined without 
3047 \emph on 
3048 using
3049 \emph default 
3050  a register bank or with register bank 0 (using 0), the compiler will save
3051  the registers used by itself on the stack upon entry and restore them at
3052  exit, however if such an interrupt service routine calls another function
3053  then the entire register bank will be saved on the stack.
3054  This scheme may be advantageous for small interrupt service routines which
3055  have low register usage.
3056 \layout Standard
3057
3058 If the interrupt service routine is defined to be using a specific register
3059  bank then only 
3060 \emph on 
3061 a, b & dptr
3062 \emph default 
3063  are save and restored, if such an interrupt service routine calls another
3064  function (using another register bank) then the entire register bank of
3065  the called function will be saved on the stack.
3066  This scheme is recommended for larger interrupt service routines.
3067 \layout Standard
3068
3069 Calling other functions from an interrupt service routine is not recommended,
3070  avoid it if possible.
3071 \newline 
3072
3073 \newline 
3074 Also see the _naked modifier.
3075 \layout Subsection
3076
3077 Critical Functions
3078 \layout Standard
3079
3080
3081 \shape italic 
3082 <TODO: this isn't implemented at all!>
3083 \shape default 
3084
3085 \newline 
3086
3087 \newline 
3088 A special keyword may be associated with a function declaring it as 
3089 \emph on 
3090 critical
3091 \emph default 
3092 .
3093  SDCC will generate code to disable all interrupts upon entry to a critical
3094  function and enable them back before returning.
3095  Note that nesting critical functions may cause unpredictable results.
3096 \newline 
3097
3098 \size small 
3099
3100 \newline 
3101
3102 \family typewriter 
3103 \size default 
3104 int foo () critical 
3105 \newline 
3106
3107 \newline 
3108 ...
3109  
3110 \newline 
3111 ...
3112  
3113 \newline 
3114 }
3115 \newline 
3116
3117 \family default 
3118
3119 \newline 
3120 The critical attribute maybe used with other attributes like 
3121 \emph on 
3122 reentrant.
3123 \layout Subsection
3124
3125 Naked Functions
3126 \layout Standard
3127
3128 A special keyword may be associated with a function declaring it as 
3129 \emph on 
3130 _naked.
3131  
3132 \emph default 
3133 The 
3134 \emph on 
3135 _naked
3136 \emph default 
3137  function modifier attribute prevents the compiler from generating prologue
3138  and epilogue code for that function.
3139  This means that the user is entirely responsible for such things as saving
3140  any registers that may need to be preserved, selecting the proper register
3141  bank, generating the 
3142 \emph on 
3143 return
3144 \emph default 
3145  instruction at the end, etc.
3146  Practically, this means that the contents of the function must be written
3147  in inline assembler.
3148  This is particularly useful for interrupt functions, which can have a large
3149  (and often unnecessary) prologue/epilogue.
3150  For example, compare the code generated by these two functions:
3151 \newline 
3152
3153 \newline 
3154
3155 \family typewriter 
3156 data unsigned char counter;
3157 \newline 
3158 void simpleInterrupt(void) interrupt 1
3159 \newline 
3160 {
3161 \newline 
3162 \SpecialChar ~
3163 \SpecialChar ~
3164 \SpecialChar ~
3165 \SpecialChar ~
3166 counter++;
3167 \newline 
3168 }
3169 \newline 
3170
3171 \newline 
3172 void nakedInterrupt(void) interrupt 2 _naked
3173 \newline 
3174 {
3175 \newline 
3176 \SpecialChar ~
3177 \SpecialChar ~
3178 \SpecialChar ~
3179 \SpecialChar ~
3180 _asm
3181 \newline 
3182 \SpecialChar ~
3183 \SpecialChar ~
3184 \SpecialChar ~
3185 \SpecialChar ~
3186 \SpecialChar ~
3187 \SpecialChar ~
3188 inc\SpecialChar ~
3189 \SpecialChar ~
3190 \SpecialChar ~
3191 \SpecialChar ~
3192 \SpecialChar ~
3193 _counter
3194 \newline 
3195 \SpecialChar ~
3196 \SpecialChar ~
3197 \SpecialChar ~
3198 \SpecialChar ~
3199 \SpecialChar ~
3200 \SpecialChar ~
3201 reti\SpecialChar ~
3202 \SpecialChar ~
3203 \SpecialChar ~
3204 \SpecialChar ~
3205 ; MUST explicitly include ret in _naked function.
3206 \newline 
3207 \SpecialChar ~
3208 \SpecialChar ~
3209 \SpecialChar ~
3210 \SpecialChar ~
3211 _endasm;
3212 \newline 
3213 }
3214 \family default 
3215
3216 \newline 
3217
3218 \newline 
3219 For an 8051 target, the generated simpleInterrupt looks like:
3220 \newline 
3221
3222 \newline 
3223
3224 \family typewriter 
3225 _simpleIterrupt:
3226 \newline 
3227 \SpecialChar ~
3228 \SpecialChar ~
3229 \SpecialChar ~
3230 \SpecialChar ~
3231 push\SpecialChar ~
3232 \SpecialChar ~
3233 \SpecialChar ~
3234 \SpecialChar ~
3235 acc
3236 \newline 
3237 \SpecialChar ~
3238 \SpecialChar ~
3239 \SpecialChar ~
3240 \SpecialChar ~
3241 push\SpecialChar ~
3242 \SpecialChar ~
3243 \SpecialChar ~
3244 \SpecialChar ~
3245 b
3246 \newline 
3247 \SpecialChar ~
3248 \SpecialChar ~
3249 \SpecialChar ~
3250 \SpecialChar ~
3251 push\SpecialChar ~
3252 \SpecialChar ~
3253 \SpecialChar ~
3254 \SpecialChar ~
3255 dpl
3256 \newline 
3257 \SpecialChar ~
3258 \SpecialChar ~
3259 \SpecialChar ~
3260 \SpecialChar ~
3261 push\SpecialChar ~
3262 \SpecialChar ~
3263 \SpecialChar ~
3264 \SpecialChar ~
3265 dph
3266 \newline 
3267 \SpecialChar ~
3268 \SpecialChar ~
3269 \SpecialChar ~
3270 \SpecialChar ~
3271 push\SpecialChar ~
3272 \SpecialChar ~
3273 \SpecialChar ~
3274 \SpecialChar ~
3275 psw
3276 \newline 
3277 \SpecialChar ~
3278 \SpecialChar ~
3279 \SpecialChar ~
3280 \SpecialChar ~
3281 mov\SpecialChar ~
3282 \SpecialChar ~
3283 \SpecialChar ~
3284 \SpecialChar ~
3285 \SpecialChar ~
3286 psw,#0x00
3287 \newline 
3288 \SpecialChar ~
3289 \SpecialChar ~
3290 \SpecialChar ~
3291 \SpecialChar ~
3292 inc\SpecialChar ~
3293 \SpecialChar ~
3294 \SpecialChar ~
3295 \SpecialChar ~
3296 \SpecialChar ~
3297 _counter
3298 \newline 
3299 \SpecialChar ~
3300 \SpecialChar ~
3301 \SpecialChar ~
3302 \SpecialChar ~
3303 pop\SpecialChar ~
3304 \SpecialChar ~
3305 \SpecialChar ~
3306 \SpecialChar ~
3307 \SpecialChar ~
3308 psw
3309 \newline 
3310 \SpecialChar ~
3311 \SpecialChar ~
3312 \SpecialChar ~
3313 \SpecialChar ~
3314 pop\SpecialChar ~
3315 \SpecialChar ~
3316 \SpecialChar ~
3317 \SpecialChar ~
3318 \SpecialChar ~
3319 dph
3320 \newline 
3321 \SpecialChar ~
3322 \SpecialChar ~
3323 \SpecialChar ~
3324 \SpecialChar ~
3325 pop\SpecialChar ~
3326 \SpecialChar ~
3327 \SpecialChar ~
3328 \SpecialChar ~
3329 \SpecialChar ~
3330 dpl
3331 \newline 
3332 \SpecialChar ~
3333 \SpecialChar ~
3334 \SpecialChar ~
3335 \SpecialChar ~
3336 pop\SpecialChar ~
3337 \SpecialChar ~
3338 \SpecialChar ~
3339 \SpecialChar ~
3340 \SpecialChar ~
3341 b
3342 \newline 
3343 \SpecialChar ~
3344 \SpecialChar ~
3345 \SpecialChar ~
3346 \SpecialChar ~
3347 pop\SpecialChar ~
3348 \SpecialChar ~
3349 \SpecialChar ~
3350 \SpecialChar ~
3351 \SpecialChar ~
3352 acc
3353 \newline 
3354 \SpecialChar ~
3355 \SpecialChar ~
3356 \SpecialChar ~
3357 \SpecialChar ~
3358 reti
3359 \family default 
3360
3361 \newline 
3362
3363 \newline 
3364 whereas nakedInterrupt looks like:
3365 \newline 
3366
3367 \newline 
3368
3369 \family typewriter 
3370 _nakedInterrupt:
3371 \newline 
3372 \SpecialChar ~
3373 \SpecialChar ~
3374 \SpecialChar ~
3375 \SpecialChar ~
3376 inc\SpecialChar ~
3377 \SpecialChar ~
3378 \SpecialChar ~
3379 \SpecialChar ~
3380 _counter
3381 \newline 
3382 \SpecialChar ~
3383 \SpecialChar ~
3384 \SpecialChar ~
3385 \SpecialChar ~
3386 reti\SpecialChar ~
3387 \SpecialChar ~
3388 \SpecialChar ~
3389 ; MUST explicitly include ret(i) in _naked function.
3390 \family default 
3391
3392 \newline 
3393
3394 \newline 
3395 While there is nothing preventing you from writing C code inside a _naked
3396  function, there are many ways to shoot yourself in the foot doing this,
3397  and is is recommended that you stick to inline assembler.
3398 \layout Subsection
3399
3400 Functions using private banks
3401 \layout Standard
3402
3403 The 
3404 \emph on 
3405 using
3406 \emph default 
3407  attribute (which tells the compiler to use a register bank other than the
3408  default bank zero) should only be applied to 
3409 \emph on 
3410 interrupt
3411 \emph default 
3412  functions (see note 1 below).
3413  This will in most circumstances make the generated ISR code more efficient
3414  since it will not have to save registers on the stack.
3415 \layout Standard
3416
3417 The 
3418 \emph on 
3419 using
3420 \emph default 
3421  attribute will have no effect on the generated code for a 
3422 \emph on 
3423 non-interrupt
3424 \emph default 
3425  function (but may occasionally be useful anyway
3426 \begin_inset Foot
3427 collapsed true
3428
3429 \layout Standard
3430
3431 possible exception: if a function is called ONLY from 'interrupt' functions
3432  using a particular bank, it can be declared with the same 'using' attribute
3433  as the calling 'interrupt' functions.
3434  For instance, if you have several ISRs using bank one, and all of them
3435  call memcpy(), it might make sense to create a specialized version of memcpy()
3436  'using 1', since this would prevent the ISR from having to save bank zero
3437  to the stack on entry and switch to bank zero before calling the function
3438 \end_inset 
3439
3440 ).
3441 \newline 
3442
3443 \emph on 
3444 (pending: I don't think this has been done yet)
3445 \layout Standard
3446
3447 An 
3448 \emph on 
3449 interrupt
3450 \emph default 
3451  function using a non-zero bank will assume that it can trash that register
3452  bank, and will not save it.
3453  Since high-priority interrupts can interrupt low-priority ones on the 8051
3454  and friends, this means that if a high-priority ISR 
3455 \emph on 
3456 using
3457 \emph default 
3458  a particular bank occurs while processing a low-priority ISR 
3459 \emph on 
3460 using
3461 \emph default 
3462  the same bank, terrible and bad things can happen.
3463  To prevent this, no single register bank should be 
3464 \emph on 
3465 used
3466 \emph default 
3467  by both a high priority and a low priority ISR.
3468  This is probably most easily done by having all high priority ISRs use
3469  one bank and all low priority ISRs use another.
3470  If you have an ISR which can change priority at runtime, you're on your
3471  own: I suggest using the default bank zero and taking the small performance
3472  hit.
3473 \layout Standard
3474
3475 It is most efficient if your ISR calls no other functions.
3476  If your ISR must call other functions, it is most efficient if those functions
3477  use the same bank as the ISR (see note 1 below); the next best is if the
3478  called functions use bank zero.
3479  It is very inefficient to call a function using a different, non-zero bank
3480  from an ISR.
3481  
3482 \layout Subsection
3483
3484 Absolute Addressing
3485 \layout Standard
3486
3487 Data items can be assigned an absolute address with the 
3488 \emph on 
3489 at <address>
3490 \emph default 
3491  keyword, in addition to a storage class, e.g.:
3492 \newline 
3493
3494 \newline 
3495
3496 \family typewriter 
3497 xdata at 0x8000 unsigned char PORTA_8255 ;
3498 \newline 
3499
3500 \family default 
3501
3502 \newline 
3503 In the above example the PORTA_8255 will be allocated to the location 0x8000
3504  of the external ram.
3505  Note that this feature is provided to give the programmer access to 
3506 \emph on 
3507 memory mapped
3508 \emph default 
3509  devices attached to the controller.
3510  The compiler does not actually reserve any space for variables declared
3511  in this way (they are implemented with an equate in the assembler).
3512  Thus it is left to the programmer to make sure there are no overlaps with
3513  other variables that are declared without the absolute address.
3514  The assembler listing file (.lst) and the linker output files (.rst) and
3515  (.map) are a good places to look for such overlaps.
3516 \newline 
3517
3518 \newline 
3519 Absolute address can be specified for variables in all storage classes,
3520  e.g.:
3521 \newline 
3522
3523 \newline 
3524
3525 \family typewriter 
3526 bit at 0x02 bvar;
3527 \newline 
3528
3529 \newline 
3530
3531 \family default 
3532 The above example will allocate the variable at offset 0x02 in the bit-addressab
3533 le space.
3534  There is no real advantage to assigning absolute addresses to variables
3535  in this manner, unless you want strict control over all the variables allocated.
3536 \layout Subsection
3537
3538 Startup Code
3539 \layout Standard
3540
3541 The compiler inserts a call to the C routine 
3542 \emph on 
3543 _sdcc__external__startup()
3544 \series bold 
3545 \emph default 
3546  
3547 \series default 
3548 at the start of the CODE area.
3549  This routine is in the runtime library.
3550  By default this routine returns 0, if this routine returns a non-zero value,
3551  the static & global variable initialization will be skipped and the function
3552  main will be invoked Other wise static & global variables will be initialized
3553  before the function main is invoked.
3554  You could add a 
3555 \emph on 
3556 _sdcc__external__startup()
3557 \emph default 
3558  routine to your program to override the default if you need to setup hardware
3559  or perform some other critical operation prior to static & global variable
3560  initialization.
3561 \layout Subsection
3562
3563 Inline Assembler Code
3564 \layout Standard
3565
3566 SDCC allows the use of in-line assembler with a few restriction as regards
3567  labels.
3568  All labels defined within inline assembler code 
3569 \emph on 
3570 has to be
3571 \emph default 
3572  of the form 
3573 \emph on 
3574 nnnnn$
3575 \emph default 
3576  where nnnn is a number less than 100 (which implies a limit of utmost 100
3577  inline assembler labels 
3578 \emph on 
3579 per function
3580 \emph default 
3581 \noun on 
3582 )
3583 \noun default 
3584 .
3585  It is strongly recommended that each assembly instruction (including labels)
3586  be placed in a separate line (as the example shows).
3587  When the 
3588 \emph on 
3589 --peep-asm
3590 \emph default 
3591  command line option is used, the inline assembler code will be passed through
3592  the peephole optimizer.
3593  This might cause some unexpected changes in the inline assembler code.
3594  Please go throught the peephole optimizer rules defined in file 
3595 \emph on 
3596 SDCCpeeph.def
3597 \emph default 
3598  carefully before using this option.
3599 \newline 
3600
3601 \newline 
3602
3603 \family typewriter 
3604 _asm 
3605 \newline 
3606 \SpecialChar ~
3607 \SpecialChar ~
3608 \SpecialChar ~
3609 \SpecialChar ~
3610 mov\SpecialChar ~
3611 \SpecialChar ~
3612 \SpecialChar ~
3613 \SpecialChar ~
3614 \SpecialChar ~
3615 b,#10 
3616 \newline 
3617 00001$: 
3618 \newline 
3619 \SpecialChar ~
3620 \SpecialChar ~
3621 \SpecialChar ~
3622 \SpecialChar ~
3623 djnz\SpecialChar ~
3624 \SpecialChar ~
3625 \SpecialChar ~
3626 \SpecialChar ~
3627 b,00001$ 
3628 \newline 
3629 _endasm ;
3630 \family default 
3631 \size small 
3632
3633 \newline 
3634
3635 \newline 
3636
3637 \size default 
3638 The inline assembler code can contain any valid code understood by the assembler
3639 , this includes any assembler directives and comment lines.
3640  The compiler does not do any validation of the code within the 
3641 \family typewriter 
3642 _asm ...
3643  _endasm;
3644 \family default 
3645  keyword pair.
3646  
3647 \newline 
3648
3649 \newline 
3650 Inline assembler code cannot reference any C-Labels, however it can reference
3651  labels defined by the inline assembler, e.g.:
3652 \newline 
3653
3654 \newline 
3655
3656 \family typewriter 
3657 foo() { 
3658 \newline 
3659 \SpecialChar ~
3660 \SpecialChar ~
3661 \SpecialChar ~
3662 \SpecialChar ~
3663 /* some c code */ 
3664 \newline 
3665 \SpecialChar ~
3666 \SpecialChar ~
3667 \SpecialChar ~
3668 \SpecialChar ~
3669 _asm 
3670 \newline 
3671 \SpecialChar ~
3672 \SpecialChar ~
3673 \SpecialChar ~
3674 \SpecialChar ~
3675 \SpecialChar ~
3676 \SpecialChar ~
3677 ; some assembler code 
3678 \newline 
3679 \SpecialChar ~
3680 \SpecialChar ~
3681 \SpecialChar ~
3682 \SpecialChar ~
3683 \SpecialChar ~
3684 \SpecialChar ~
3685 ljmp $0003 
3686 \newline 
3687 \SpecialChar ~
3688 \SpecialChar ~
3689 \SpecialChar ~
3690 \SpecialChar ~
3691 _endasm; 
3692 \newline 
3693 \SpecialChar ~
3694 \SpecialChar ~
3695 \SpecialChar ~
3696 \SpecialChar ~
3697 /* some more c code */ 
3698 \newline 
3699 clabel:\SpecialChar ~
3700 \SpecialChar ~
3701 /* inline assembler cannot reference this label */ 
3702 \newline 
3703 \SpecialChar ~
3704 \SpecialChar ~
3705 \SpecialChar ~
3706 \SpecialChar ~
3707 _asm
3708 \newline 
3709 \SpecialChar ~
3710 \SpecialChar ~
3711 \SpecialChar ~
3712 \SpecialChar ~
3713 $0003: ;label (can be reference by inline assembler only) 
3714 \newline 
3715 \SpecialChar ~
3716 \SpecialChar ~
3717 \SpecialChar ~
3718 \SpecialChar ~
3719 _endasm ; 
3720 \newline 
3721 \SpecialChar ~
3722 \SpecialChar ~
3723 \SpecialChar ~
3724 \SpecialChar ~
3725 /* some more c code */
3726 \newline 
3727 }
3728 \newline 
3729
3730 \newline 
3731
3732 \family default 
3733 In other words inline assembly code can access labels defined in inline
3734  assembly within the scope of the funtion.
3735  
3736 \layout Standard
3737
3738 The same goes the other way, ie.
3739  labels defines in inline assembly CANNOT be accessed by C statements.
3740 \layout Subsection
3741
3742 int(16 bit) and long (32 bit) Support
3743 \layout Standard
3744
3745 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
3746  multiplication and modulus operations are implemented by support routines.
3747  These support routines are all developed in ANSI-C to facilitate porting
3748  to other MCUs, although some model specific assembler optimations are used.
3749  The following files contain the described routine, all of them can be found
3750  in <installdir>/share/sdcc/lib.
3751 \newline 
3752
3753 \newline 
3754
3755 \emph on 
3756 <pending: tabularise this>
3757 \emph default 
3758
3759 \newline 
3760
3761 \newline 
3762 _mulsint.c - signed 16 bit multiplication (calls _muluint)
3763 \newline 
3764 _muluint.c - unsigned 16 bit multiplication
3765 \newline 
3766 _divsint.c - signed 16 bit division (calls _divuint)
3767 \newline 
3768 _divuint.c - unsigned 16 bit division
3769 \newline 
3770 _modsint.c - signed 16 bit modulus (call _moduint)
3771 \newline 
3772 _moduint.c - unsigned 16 bit modulus
3773 \newline 
3774 _mulslong.c - signed 32 bit multiplication (calls _mululong)
3775 \newline 
3776 _mululong.c - unsigned32 bit multiplication
3777 \newline 
3778 _divslong.c - signed 32 division (calls _divulong)
3779 \newline 
3780 _divulong.c - unsigned 32 division
3781 \newline 
3782 _modslong.c - signed 32 bit modulus (calls _modulong)
3783 \newline 
3784 _modulong.c - unsigned 32 bit modulus 
3785 \size footnotesize 
3786
3787 \newline 
3788
3789 \newline 
3790
3791 \size default 
3792 Since they are compiled as 
3793 \emph on 
3794 non-reentrant
3795 \emph default 
3796 , interrupt service routines should not do any of the above operations.
3797  If this is unavoidable then the above routines will need to be compiled
3798  with the 
3799 \emph on 
3800 --stack-auto
3801 \emph default 
3802  option, after which the source program will have to be compiled with 
3803 \emph on 
3804 --int-long-rent
3805 \emph default 
3806  option.
3807 \layout Subsection
3808
3809 Floating Point Support
3810 \layout Standard
3811
3812 SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
3813  point support routines are derived from gcc's floatlib.c and consists of
3814  the following routines:
3815 \newline 
3816
3817 \newline 
3818
3819 \emph on 
3820 <pending: tabularise this>
3821 \emph default 
3822
3823 \newline 
3824
3825 \newline 
3826 _fsadd.c - add floating point numbers
3827 \newline 
3828 _fssub.c - subtract floating point numbers
3829 \newline 
3830 _fsdiv.c - divide floating point numbers
3831 \newline 
3832 _fsmul.c - multiply floating point numbers
3833 \newline 
3834 _fs2uchar.c - convert floating point to unsigned char
3835 \newline 
3836 _fs2char.c - convert floating point to signed char
3837 \newline 
3838 _fs2uint.c - convert floating point to unsigned int
3839 \newline 
3840 _fs2int.c - convert floating point to signed int
3841 \newline 
3842 _fs2ulong.c - convert floating point to unsigned long
3843 \newline 
3844 _fs2long.c - convert floating point to signed long
3845 \newline 
3846 _uchar2fs.c - convert unsigned char to floating point
3847 \newline 
3848 _char2fs.c - convert char to floating point number
3849 \newline 
3850 _uint2fs.c - convert unsigned int to floating point
3851 \newline 
3852 _int2fs.c - convert int to floating point numbers
3853 \newline 
3854 _ulong2fs.c - convert unsigned long to floating point number
3855 \newline 
3856 _long2fs.c - convert long to floating point number
3857 \size footnotesize 
3858
3859 \newline 
3860
3861 \newline 
3862
3863 \size default 
3864 Note if all these routines are used simultaneously the data space might
3865  overflow.
3866  For serious floating point usage it is strongly recommended that the large
3867  model be used.
3868 \layout Subsection
3869
3870 MCS51 Memory Models
3871 \layout Standard
3872
3873 SDCC allows two memory models for MCS51 code, small and large.
3874  Modules compiled with different memory models should 
3875 \emph on 
3876 never
3877 \emph default 
3878  be combined together or the results would be unpredictable.
3879  The library routines supplied with the compiler are compiled as both small
3880  and large.
3881  The compiled library modules are contained in seperate directories as small
3882  and large so that you can link to either set.
3883  
3884 \layout Standard
3885
3886 When the large model is used all variables declared without a storage class
3887  will be allocated into the external ram, this includes all parameters and
3888  local variables (for non-reentrant functions).
3889  When the small model is used variables without storage class are allocated
3890  in the internal ram.
3891 \layout Standard
3892
3893 Judicious usage of the processor specific storage classes and the 'reentrant'
3894  function type will yield much more efficient code, than using the large
3895  model.
3896  Several optimizations are disabled when the program is compiled using the
3897  large model, it is therefore strongly recommdended that the small model
3898  be used unless absolutely required.
3899 \layout Subsection
3900
3901 DS390 Memory Models
3902 \layout Standard
3903
3904 The only model supported is Flat 24.
3905  This generates code for the 24 bit contiguous addressing mode of the Dallas
3906  DS80C390 part.
3907  In this mode, up to four meg of external RAM or code space can be directly
3908  addressed.
3909  See the data sheets at www.dalsemi.com for further information on this part.
3910 \newline 
3911
3912 \newline 
3913 In older versions of the compiler, this option was used with the MCS51 code
3914  generator (
3915 \emph on 
3916 -mmcs51
3917 \emph default 
3918 ).
3919  Now, however, the '390 has it's own code generator, selected by the 
3920 \emph on 
3921 -mds390
3922 \emph default 
3923  switch.
3924  
3925 \newline 
3926
3927 \newline 
3928 Note that the compiler does not generate any code to place the processor
3929  into 24 bitmode (although 
3930 \emph on 
3931 tinibios
3932 \emph default 
3933  in the ds390 libraries will do that for you).
3934  If you don't use 
3935 \emph on 
3936 tinibios
3937 \emph default 
3938 , the boot loader or similar code must ensure that the processor is in 24
3939  bit contiguous addressing mode before calling the SDCC startup code.
3940 \newline 
3941
3942 \newline 
3943 Like the 
3944 \emph on 
3945 --model-large
3946 \emph default 
3947  option, variables will by default be placed into the XDATA segment.
3948  
3949 \newline 
3950
3951 \newline 
3952 Segments may be placed anywhere in the 4 meg address space using the usual
3953  --*-loc options.
3954  Note that if any segments are located above 64K, the -r flag must be passed
3955  to the linker to generate the proper segment relocations, and the Intel
3956  HEX output format must be used.
3957  The -r flag can be passed to the linker by using the option 
3958 \emph on 
3959 -Wl-r
3960 \emph default 
3961  on the sdcc command line.
3962  However, currently the linker can not handle code segments > 64k.
3963 \layout Subsection
3964
3965 Defines Created by the Compiler
3966 \layout Standard
3967
3968 The compiler creates the following #defines.
3969 \layout Itemize
3970
3971 SDCC - this Symbol is always defined.
3972 \layout Itemize
3973
3974 SDCC_mcs51 or SDCC_ds390 or SDCC_z80, etc - depending on the model used
3975  (e.g.: -mds390)
3976 \layout Itemize
3977
3978 __mcs51 or __ds390 or __z80, etc - depending on the model used (e.g.
3979  -mz80)
3980 \layout Itemize
3981
3982 SDCC_STACK_AUTO - this symbol is defined when 
3983 \emph on 
3984 --stack-auto
3985 \emph default 
3986  option is used.
3987 \layout Itemize
3988
3989 SDCC_MODEL_SMALL - when 
3990 \emph on 
3991 --model-small
3992 \emph default 
3993  is used.
3994 \layout Itemize
3995
3996 SDCC_MODEL_LARGE - when 
3997 \emph on 
3998 --model-large
3999 \emph default 
4000  is used.
4001 \layout Itemize
4002
4003 SDCC_USE_XSTACK - when 
4004 \emph on 
4005 --xstack
4006 \emph default 
4007  option is used.
4008 \layout Itemize
4009
4010 SDCC_STACK_TENBIT - when 
4011 \emph on 
4012 -mds390
4013 \emph default 
4014  is used
4015 \layout Itemize
4016
4017 SDCC_MODEL_FLAT24 - when 
4018 \emph on 
4019 -mds390
4020 \emph default 
4021  is used
4022 \layout Section
4023
4024 SDCC Technical Data
4025 \layout Subsection
4026
4027 Optimizations
4028 \layout Standard
4029
4030 SDCC performs a host of standard optimizations in addition to some MCU specific
4031  optimizations.
4032  
4033 \layout Subsubsection
4034
4035 Sub-expression Elimination
4036 \layout Standard
4037
4038 The compiler does local and global common subexpression elimination, e.g.:
4039  
4040 \newline 
4041
4042 \newline 
4043
4044 \family typewriter 
4045 i = x + y + 1; 
4046 \newline 
4047 j = x + y;
4048 \family default 
4049
4050 \newline 
4051
4052 \newline 
4053 will be translated to
4054 \newline 
4055
4056 \newline 
4057
4058 \family typewriter 
4059 iTemp = x + y 
4060 \newline 
4061 i = iTemp + 1 
4062 \newline 
4063 j = iTemp
4064 \newline 
4065
4066 \family default 
4067
4068 \newline 
4069 Some subexpressions are not as obvious as the above example, e.g.:
4070 \newline 
4071
4072 \newline 
4073
4074 \family typewriter 
4075 a->b[i].c = 10; 
4076 \newline 
4077 a->b[i].d = 11;
4078 \family default 
4079
4080 \newline 
4081
4082 \newline 
4083 In this case the address arithmetic a->b[i] will be computed only once;
4084  the equivalent code in C would be.
4085 \newline 
4086
4087 \newline 
4088
4089 \family typewriter 
4090 iTemp = a->b[i]; 
4091 \newline 
4092 iTemp.c = 10; 
4093 \newline 
4094 iTemp.d = 11;
4095 \family default 
4096
4097 \newline 
4098
4099 \newline 
4100 The compiler will try to keep these temporary variables in registers.
4101 \layout Subsubsection
4102
4103 Dead-Code Elimination
4104 \layout Standard
4105
4106
4107 \family typewriter 
4108 int global; 
4109 \newline 
4110 void f () { 
4111 \newline 
4112 \SpecialChar ~
4113 \SpecialChar ~
4114 int i; 
4115 \newline 
4116 \SpecialChar ~
4117 \SpecialChar ~
4118 i = 1; \SpecialChar ~
4119 /* dead store */ 
4120 \newline 
4121 \SpecialChar ~
4122 \SpecialChar ~
4123 global = 1;\SpecialChar ~
4124 /* dead store */ 
4125 \newline 
4126 \SpecialChar ~
4127 \SpecialChar ~
4128 global = 2; 
4129 \newline 
4130 \SpecialChar ~
4131 \SpecialChar ~
4132 return; 
4133 \newline 
4134 \SpecialChar ~
4135 \SpecialChar ~
4136 global = 3;\SpecialChar ~
4137 /* unreachable */ 
4138 \newline 
4139 }
4140 \family default 
4141
4142 \newline 
4143
4144 \newline 
4145 will be changed to
4146 \newline 
4147
4148 \newline 
4149
4150 \family typewriter 
4151 int global; void f () 
4152 \newline 
4153 {
4154 \newline 
4155 \SpecialChar ~
4156 \SpecialChar ~
4157 global = 2; 
4158 \newline 
4159 \SpecialChar ~
4160 \SpecialChar ~
4161 return; 
4162 \newline 
4163 }
4164 \layout Subsubsection
4165
4166 Copy-Propagation
4167 \layout Standard
4168
4169
4170 \family typewriter 
4171 int f() { 
4172 \newline 
4173 \SpecialChar ~
4174 \SpecialChar ~
4175 int i, j; 
4176 \newline 
4177 \SpecialChar ~
4178 \SpecialChar ~
4179 i = 10; 
4180 \newline 
4181 \SpecialChar ~
4182 \SpecialChar ~
4183 j = i; 
4184 \newline 
4185 \SpecialChar ~
4186 \SpecialChar ~
4187 return j; 
4188 \newline 
4189 }
4190 \family default 
4191
4192 \newline 
4193
4194 \newline 
4195 will be changed to 
4196 \newline 
4197
4198 \newline 
4199
4200 \family typewriter 
4201 int f() { 
4202 \newline 
4203 \SpecialChar ~
4204  \SpecialChar ~
4205  int i,j; 
4206 \newline 
4207 \SpecialChar ~
4208  \SpecialChar ~
4209  i = 10; 
4210 \newline 
4211 \SpecialChar ~
4212  \SpecialChar ~
4213  j = 10; 
4214 \newline 
4215 \SpecialChar ~
4216  \SpecialChar ~
4217  return 10; 
4218 \newline 
4219 }
4220 \newline 
4221
4222 \newline 
4223
4224 \family default 
4225 Note: the dead stores created by this copy propagation will be eliminated
4226  by dead-code elimination.
4227 \layout Subsubsection
4228
4229 Loop Optimizations
4230 \layout Standard
4231
4232 Two types of loop optimizations are done by SDCC loop invariant lifting
4233  and strength reduction of loop induction variables.
4234  In addition to the strength reduction the optimizer marks the induction
4235  variables and the register allocator tries to keep the induction variables
4236  in registers for the duration of the loop.
4237  Because of this preference of the register allocator, loop induction optimizati
4238 on causes an increase in register pressure, which may cause unwanted spilling
4239  of other temporary variables into the stack / data space.
4240  The compiler will generate a warning message when it is forced to allocate
4241  extra space either on the stack or data space.
4242  If this extra space allocation is undesirable then induction optimization
4243  can be eliminated either for the entire source file (with --noinduction
4244  option) or for a given function only using #pragma\SpecialChar ~
4245 NOINDUCTION.
4246 \newline 
4247
4248 \newline 
4249 Loop Invariant:
4250 \newline 
4251
4252 \newline 
4253
4254 \family typewriter 
4255 for (i = 0 ; i < 100 ; i ++) 
4256 \newline 
4257  \SpecialChar ~
4258  \SpecialChar ~
4259 f += k + l;
4260 \family default 
4261
4262 \newline 
4263
4264 \newline 
4265 changed to
4266 \newline 
4267
4268 \newline 
4269
4270 \family typewriter 
4271 itemp = k + l; 
4272 \newline 
4273 for (i = 0; i < 100; i++) 
4274 \newline 
4275 \SpecialChar ~
4276 \SpecialChar ~
4277 f += itemp;
4278 \family default 
4279
4280 \newline 
4281
4282 \newline 
4283 As mentioned previously some loop invariants are not as apparent, all static
4284  address computations are also moved out of the loop.
4285 \newline 
4286
4287 \newline 
4288 Strength Reduction, this optimization substitutes an expression by a cheaper
4289  expression:
4290 \newline 
4291
4292 \newline 
4293
4294 \family typewriter 
4295 for (i=0;i < 100; i++)
4296 \newline 
4297 \SpecialChar ~
4298 \SpecialChar ~
4299 ar[i*5] = i*3;
4300 \family default 
4301
4302 \newline 
4303
4304 \newline 
4305 changed to
4306 \newline 
4307
4308 \newline 
4309
4310 \family typewriter 
4311 itemp1 = 0; 
4312 \newline 
4313 itemp2 = 0; 
4314 \newline 
4315 for (i=0;i< 100;i++) { 
4316 \newline 
4317  \SpecialChar ~
4318  \SpecialChar ~
4319 ar[itemp1] = itemp2; 
4320 \newline 
4321  \SpecialChar ~
4322  \SpecialChar ~
4323 itemp1 += 5; 
4324 \newline 
4325  \SpecialChar ~
4326  \SpecialChar ~
4327 itemp2 += 3; 
4328 \newline 
4329 }
4330 \family default 
4331
4332 \newline 
4333
4334 \newline 
4335 The more expensive multiplication is changed to a less expensive addition.
4336 \layout Subsubsection
4337
4338 Loop Reversing
4339 \layout Standard
4340
4341 This optimization is done to reduce the overhead of checking loop boundaries
4342  for every iteration.
4343  Some simple loops can be reversed and implemented using a 
4344 \begin_inset Quotes eld
4345 \end_inset 
4346
4347 decrement and jump if not zero
4348 \begin_inset Quotes erd
4349 \end_inset 
4350
4351  instruction.
4352  SDCC checks for the following criterion to determine if a loop is reversible
4353  (note: more sophisticated compilers use data-dependency analysis to make
4354  this determination, SDCC uses a more simple minded analysis).
4355 \layout Itemize
4356
4357 The 'for' loop is of the form 
4358 \newline 
4359
4360 \newline 
4361
4362 \family typewriter 
4363 for (<symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ |
4364  <sym> += 1])
4365 \newline 
4366 \SpecialChar ~
4367 \SpecialChar ~
4368 \SpecialChar ~
4369 \SpecialChar ~
4370 <for body>
4371 \layout Itemize
4372
4373 The <for body> does not contain 
4374 \begin_inset Quotes eld
4375 \end_inset 
4376
4377 continue
4378 \begin_inset Quotes erd
4379 \end_inset 
4380
4381  or 'break
4382 \begin_inset Quotes erd
4383 \end_inset 
4384
4385 .
4386 \layout Itemize
4387
4388 All goto's are contained within the loop.
4389 \layout Itemize
4390
4391 No function calls within the loop.
4392 \layout Itemize
4393
4394 The loop control variable <sym> is not assigned any value within the loop
4395 \layout Itemize
4396
4397 The loop control variable does NOT participate in any arithmetic operation
4398  within the loop.
4399 \layout Itemize
4400
4401 There are NO switch statements in the loop.
4402 \layout Subsubsection
4403
4404 Algebraic Simplifications
4405 \layout Standard
4406
4407 SDCC does numerous algebraic simplifications, the following is a small sub-set
4408  of these optimizations.
4409 \newline 
4410
4411 \newline 
4412
4413 \family typewriter 
4414 i = j + 0 ; /* changed to */ i = j; 
4415 \newline 
4416 i /= 2; /* changed to */ i >>= 1; 
4417 \newline 
4418 i = j - j ; /* changed to */ i = 0; 
4419 \newline 
4420 i = j / 1 ; /* changed to */ i = j;
4421 \family default 
4422
4423 \newline 
4424
4425 \newline 
4426 Note the subexpressions given above are generally introduced by macro expansions
4427  or as a result of copy/constant propagation.
4428 \layout Subsubsection
4429
4430 'switch' Statements
4431 \layout Standard
4432
4433 SDCC changes switch statements to jump tables when the following conditions
4434  are true.
4435  
4436 \layout Itemize
4437
4438 The case labels are in numerical sequence, the labels need not be in order,
4439  and the starting number need not be one or zero.
4440 \newline 
4441
4442 \newline 
4443
4444 \family typewriter 
4445 switch(i) {\SpecialChar ~
4446  \SpecialChar ~
4447  \SpecialChar ~
4448  \SpecialChar ~
4449  \SpecialChar ~
4450  \SpecialChar ~
4451  \SpecialChar ~
4452  \SpecialChar ~
4453  \SpecialChar ~
4454  \SpecialChar ~
4455  \SpecialChar ~
4456  \SpecialChar ~
4457  \SpecialChar ~
4458 switch (i) { 
4459 \newline 
4460 case 4:...
4461  \SpecialChar ~
4462  \SpecialChar ~
4463  \SpecialChar ~
4464  \SpecialChar ~
4465  \SpecialChar ~
4466  \SpecialChar ~
4467  \SpecialChar ~
4468  \SpecialChar ~
4469  \SpecialChar ~
4470  \SpecialChar ~
4471  \SpecialChar ~
4472  \SpecialChar ~
4473  \SpecialChar ~
4474 case 1: ...
4475  
4476 \newline 
4477 case 5:...
4478  \SpecialChar ~
4479  \SpecialChar ~
4480  \SpecialChar ~
4481  \SpecialChar ~
4482  \SpecialChar ~
4483  \SpecialChar ~
4484  \SpecialChar ~
4485  \SpecialChar ~
4486  \SpecialChar ~
4487  \SpecialChar ~
4488  \SpecialChar ~
4489  \SpecialChar ~
4490  \SpecialChar ~
4491 case 2: ...
4492  
4493 \newline 
4494 case 3:...
4495  \SpecialChar ~
4496  \SpecialChar ~
4497  \SpecialChar ~
4498  \SpecialChar ~
4499  \SpecialChar ~
4500  \SpecialChar ~
4501  \SpecialChar ~
4502  \SpecialChar ~
4503  \SpecialChar ~
4504  \SpecialChar ~
4505  \SpecialChar ~
4506  \SpecialChar ~
4507  \SpecialChar ~
4508 case 3: ...
4509  
4510 \newline 
4511 case 6:...
4512  \SpecialChar ~
4513  \SpecialChar ~
4514  \SpecialChar ~
4515  \SpecialChar ~
4516  \SpecialChar ~
4517  \SpecialChar ~
4518  \SpecialChar ~
4519  \SpecialChar ~
4520  \SpecialChar ~
4521  \SpecialChar ~
4522  \SpecialChar ~
4523  \SpecialChar ~
4524  \SpecialChar ~
4525 case 4: ...
4526  
4527 \newline 
4528 }\SpecialChar ~
4529  \SpecialChar ~
4530  \SpecialChar ~
4531  \SpecialChar ~
4532  \SpecialChar ~
4533  \SpecialChar ~
4534  \SpecialChar ~
4535  \SpecialChar ~
4536  \SpecialChar ~
4537  \SpecialChar ~
4538  \SpecialChar ~
4539  \SpecialChar ~
4540  \SpecialChar ~
4541  \SpecialChar ~
4542  \SpecialChar ~
4543  \SpecialChar ~
4544  \SpecialChar ~
4545  \SpecialChar ~
4546 }
4547 \newline 
4548
4549 \newline 
4550
4551 \family default 
4552 Both the above switch statements will be implemented using a jump-table.
4553 \layout Itemize
4554
4555 The number of case labels is at least three, since it takes two conditional
4556  statements to handle the boundary conditions.
4557 \layout Itemize
4558
4559 The number of case labels is less than 84, since each label takes 3 bytes
4560  and a jump-table can be utmost 256 bytes long.
4561  
4562 \layout Standard
4563
4564 Switch statements which have gaps in the numeric sequence or those that
4565  have more that 84 case labels can be split into more than one switch statement
4566  for efficient code generation, e.g.:
4567 \newline 
4568
4569 \newline 
4570
4571 \family typewriter 
4572 switch (i) { 
4573 \newline 
4574 case 1: ...
4575  
4576 \newline 
4577 case 2: ...
4578  
4579 \newline 
4580 case 3: ...
4581  
4582 \newline 
4583 case 4: ...
4584  
4585 \newline 
4586 case 9: ...
4587  
4588 \newline 
4589 case 10: ...
4590  
4591 \newline 
4592 case 11: ...
4593  
4594 \newline 
4595 case 12: ...
4596  
4597 \newline 
4598 }
4599 \family default 
4600
4601 \newline 
4602
4603 \newline 
4604 If the above switch statement is broken down into two switch statements
4605 \newline 
4606
4607 \newline 
4608
4609 \family typewriter 
4610 switch (i) { 
4611 \newline 
4612 case 1: ...
4613  
4614 \newline 
4615 case 2: ...
4616  
4617 \newline 
4618 case 3: ...
4619  
4620 \newline 
4621 case 4: ...
4622  
4623 \newline 
4624 }
4625 \newline 
4626
4627 \newline 
4628
4629 \family default 
4630 and
4631 \family typewriter 
4632
4633 \newline 
4634
4635 \newline 
4636 switch (i) { 
4637 \newline 
4638 case 9: \SpecialChar ~
4639 ...
4640  
4641 \newline 
4642 case 10: ...
4643  
4644 \newline 
4645 case 11: ...
4646  
4647 \newline 
4648 case 12:\SpecialChar ~
4649 ...
4650  
4651 \newline 
4652 }
4653 \newline 
4654
4655 \newline 
4656
4657 \family default 
4658 then both the switch statements will be implemented using jump-tables whereas
4659  the unmodified switch statement will not be.
4660 \layout Subsubsection
4661
4662 Bit-shifting Operations.
4663 \layout Standard
4664
4665 Bit shifting is one of the most frequently used operation in embedded programmin
4666 g.
4667  SDCC tries to implement bit-shift operations in the most efficient way
4668  possible, e.g.:
4669 \newline 
4670
4671 \family typewriter 
4672
4673 \newline 
4674 unsigned char i;
4675 \newline 
4676 ...
4677  
4678 \newline 
4679 i>>= 4; 
4680 \newline 
4681 ...
4682 \newline 
4683
4684 \family default 
4685
4686 \newline 
4687 generates the following code:
4688 \newline 
4689
4690 \family typewriter 
4691
4692 \newline 
4693 mov a,_i 
4694 \newline 
4695 swap a 
4696 \newline 
4697 anl a,#0x0f 
4698 \newline 
4699 mov _i,a
4700 \family default 
4701
4702 \newline 
4703
4704 \newline 
4705 In general SDCC will never setup a loop if the shift count is known.
4706  Another example:
4707 \newline 
4708
4709 \newline 
4710
4711 \family typewriter 
4712 unsigned int i; 
4713 \newline 
4714 ...
4715  
4716 \newline 
4717 i >>= 9; 
4718 \newline 
4719 ...
4720 \family default 
4721
4722 \newline 
4723
4724 \newline 
4725 will generate:
4726 \newline 
4727
4728 \newline 
4729
4730 \family typewriter 
4731 mov a,(_i + 1) 
4732 \newline 
4733 mov (_i + 1),#0x00 
4734 \newline 
4735 clr c 
4736 \newline 
4737 rrc a 
4738 \newline 
4739 mov _i,a
4740 \family default 
4741
4742 \newline 
4743
4744 \newline 
4745 Note that SDCC stores numbers in little-endian format (i.e.
4746  lowest order first).
4747 \layout Subsubsection
4748
4749 Bit-rotation
4750 \layout Standard
4751
4752 A special case of the bit-shift operation is bit rotation, SDCC recognizes
4753  the following expression to be a left bit-rotation:
4754 \newline 
4755
4756 \newline 
4757
4758 \family typewriter 
4759 unsigned char i; 
4760 \newline 
4761 ...
4762  
4763 \newline 
4764 i = ((i << 1) | (i >> 7)); 
4765 \family default 
4766
4767 \newline 
4768 ...
4769 \newline 
4770
4771 \newline 
4772 will generate the following code:
4773 \newline 
4774
4775 \newline 
4776
4777 \family typewriter 
4778 mov a,_i 
4779 \newline 
4780 rl a 
4781 \newline 
4782 mov _i,a
4783 \family default 
4784
4785 \newline 
4786
4787 \newline 
4788 SDCC uses pattern matching on the parse tree to determine this operation.Variatio
4789 ns of this case will also be recognized as bit-rotation, i.e.: 
4790 \newline 
4791
4792 \newline 
4793
4794 \family typewriter 
4795 i = ((i >> 7) | (i << 1)); /* left-bit rotation */
4796 \layout Subsubsection
4797
4798 Highest Order Bit
4799 \layout Standard
4800
4801 It is frequently required to obtain the highest order bit of an integral
4802  type (long, int, short or char types).
4803  SDCC recognizes the following expression to yield the highest order bit
4804  and generates optimized code for it, e.g.:
4805 \newline 
4806
4807 \newline 
4808  
4809 \family typewriter 
4810 unsigned int gint; 
4811 \newline 
4812
4813 \newline 
4814 foo () { 
4815 \newline 
4816 unsigned char hob; 
4817 \newline 
4818 \SpecialChar ~
4819 \SpecialChar ~
4820 ...
4821  
4822 \newline 
4823 \SpecialChar ~
4824 \SpecialChar ~
4825 hob = (gint >> 15) & 1; 
4826 \newline 
4827 \SpecialChar ~
4828 \SpecialChar ~
4829 ..
4830  
4831 \newline 
4832 }
4833 \family default 
4834
4835 \newline 
4836
4837 \newline 
4838 will generate the following code:
4839 \newline 
4840
4841 \family typewriter 
4842
4843 \newline 
4844 \SpecialChar ~
4845 \SpecialChar ~
4846 \SpecialChar ~
4847 \SpecialChar ~
4848 \SpecialChar ~
4849 \SpecialChar ~
4850 \SpecialChar ~
4851 \SpecialChar ~
4852 \SpecialChar ~
4853 \SpecialChar ~
4854 \SpecialChar ~
4855 \SpecialChar ~
4856 \SpecialChar ~
4857 \SpecialChar ~
4858 \SpecialChar ~
4859 \SpecialChar ~
4860 \SpecialChar ~
4861 \SpecialChar ~
4862 \SpecialChar ~
4863 \SpecialChar ~
4864 \SpecialChar ~
4865 \SpecialChar ~
4866 \SpecialChar ~
4867 \SpecialChar ~
4868 \SpecialChar ~
4869 \SpecialChar ~
4870 \SpecialChar ~
4871 \SpecialChar ~
4872  61 ;\SpecialChar ~
4873  hob.c 7 
4874 \newline 
4875 \SpecialChar ~
4876 \SpecialChar ~
4877  000A E5*01\SpecialChar ~
4878 \SpecialChar ~
4879 \SpecialChar ~
4880 \SpecialChar ~
4881 \SpecialChar ~
4882 \SpecialChar ~
4883 \SpecialChar ~
4884 \SpecialChar ~
4885 \SpecialChar ~
4886 \SpecialChar ~
4887 \SpecialChar ~
4888 \SpecialChar ~
4889 \SpecialChar ~
4890 \SpecialChar ~
4891 \SpecialChar ~
4892  62\SpecialChar ~
4893 \SpecialChar ~
4894 \SpecialChar ~
4895 \SpecialChar ~
4896 \SpecialChar ~
4897 \SpecialChar ~
4898 \SpecialChar ~
4899 \SpecialChar ~
4900  mov\SpecialChar ~
4901  a,(_gint + 1) 
4902 \newline 
4903 \SpecialChar ~
4904 \SpecialChar ~
4905  000C 33\SpecialChar ~
4906 \SpecialChar ~
4907 \SpecialChar ~
4908 \SpecialChar ~
4909 \SpecialChar ~
4910 \SpecialChar ~
4911 \SpecialChar ~
4912 \SpecialChar ~
4913 \SpecialChar ~
4914 \SpecialChar ~
4915 \SpecialChar ~
4916 \SpecialChar ~
4917 \SpecialChar ~
4918 \SpecialChar ~
4919 \SpecialChar ~
4920 \SpecialChar ~
4921 \SpecialChar ~
4922 \SpecialChar ~
4923  63\SpecialChar ~
4924 \SpecialChar ~
4925 \SpecialChar ~
4926 \SpecialChar ~
4927 \SpecialChar ~
4928 \SpecialChar ~
4929 \SpecialChar ~
4930 \SpecialChar ~
4931  rlc\SpecialChar ~
4932  a 
4933 \newline 
4934 \SpecialChar ~
4935 \SpecialChar ~
4936  000D E4\SpecialChar ~
4937 \SpecialChar ~
4938 \SpecialChar ~
4939 \SpecialChar ~
4940 \SpecialChar ~
4941 \SpecialChar ~
4942 \SpecialChar ~
4943 \SpecialChar ~
4944 \SpecialChar ~
4945 \SpecialChar ~
4946 \SpecialChar ~
4947 \SpecialChar ~
4948 \SpecialChar ~
4949 \SpecialChar ~
4950 \SpecialChar ~
4951 \SpecialChar ~
4952 \SpecialChar ~
4953 \SpecialChar ~
4954  64\SpecialChar ~
4955 \SpecialChar ~
4956 \SpecialChar ~
4957 \SpecialChar ~
4958 \SpecialChar ~
4959 \SpecialChar ~
4960 \SpecialChar ~
4961 \SpecialChar ~
4962  clr\SpecialChar ~
4963  a 
4964 \newline 
4965 \SpecialChar ~
4966 \SpecialChar ~
4967  000E 13\SpecialChar ~
4968 \SpecialChar ~
4969 \SpecialChar ~
4970 \SpecialChar ~
4971 \SpecialChar ~
4972 \SpecialChar ~
4973 \SpecialChar ~
4974 \SpecialChar ~
4975 \SpecialChar ~
4976 \SpecialChar ~
4977 \SpecialChar ~
4978 \SpecialChar ~
4979 \SpecialChar ~
4980 \SpecialChar ~
4981 \SpecialChar ~
4982 \SpecialChar ~
4983 \SpecialChar ~
4984 \SpecialChar ~
4985  65\SpecialChar ~
4986 \SpecialChar ~
4987 \SpecialChar ~
4988 \SpecialChar ~
4989 \SpecialChar ~
4990 \SpecialChar ~
4991 \SpecialChar ~
4992 \SpecialChar ~
4993  rrc\SpecialChar ~
4994  a 
4995 \newline 
4996 \SpecialChar ~
4997 \SpecialChar ~
4998  000F F5*02\SpecialChar ~
4999 \SpecialChar ~
5000 \SpecialChar ~
5001 \SpecialChar ~
5002 \SpecialChar ~
5003 \SpecialChar ~
5004 \SpecialChar ~
5005 \SpecialChar ~
5006 \SpecialChar ~
5007 \SpecialChar ~
5008 \SpecialChar ~
5009 \SpecialChar ~
5010 \SpecialChar ~
5011 \SpecialChar ~
5012 \SpecialChar ~
5013  66\SpecialChar ~
5014 \SpecialChar ~
5015 \SpecialChar ~
5016 \SpecialChar ~
5017 \SpecialChar ~
5018 \SpecialChar ~
5019 \SpecialChar ~
5020 \SpecialChar ~
5021  mov\SpecialChar ~
5022  _foo_hob_1_1,a
5023 \newline 
5024
5025 \newline 
5026
5027 \family default 
5028 Variations of this case however will 
5029 \emph on 
5030 not
5031 \emph default 
5032  be recognized.
5033  It is a standard C expression, so I heartily recommend this be the only
5034  way to get the highest order bit, (it is portable).
5035  Of course it will be recognized even if it is embedded in other expressions,
5036  e.g.:
5037 \newline 
5038
5039 \newline 
5040
5041 \family typewriter 
5042 xyz = gint + ((gint >> 15) & 1);
5043 \family default 
5044
5045 \newline 
5046
5047 \newline 
5048 will still be recognized.
5049 \layout Subsubsection
5050
5051 Peep-hole Optimizer
5052 \layout Standard
5053
5054 The compiler uses a rule based, pattern matching and re-writing mechanism
5055  for peep-hole optimization.
5056  It is inspired by 
5057 \emph on 
5058 copt
5059 \emph default 
5060  a peep-hole optimizer by Christopher W.
5061  Fraser (cwfraser@microsoft.com).
5062  A default set of rules are compiled into the compiler, additional rules
5063  may be added with the 
5064 \emph on 
5065 --peep-file <filename>
5066 \emph default 
5067  option.
5068  The rule language is best illustrated with examples.
5069 \newline 
5070
5071 \newline 
5072
5073 \family typewriter 
5074 replace { 
5075 \newline 
5076 \SpecialChar ~
5077 \SpecialChar ~
5078 mov %1,a 
5079 \newline 
5080 \SpecialChar ~
5081 \SpecialChar ~
5082 mov a,%1
5083 \newline 
5084 } by {
5085 \newline 
5086 \SpecialChar ~
5087 \SpecialChar ~
5088 mov %1,a
5089 \newline 
5090 }
5091 \family default 
5092
5093 \newline 
5094
5095 \newline 
5096 The above rule will change the following assembly sequence:
5097 \newline 
5098
5099 \newline 
5100
5101 \family typewriter 
5102 \SpecialChar ~
5103 \SpecialChar ~
5104 mov r1,a 
5105 \newline 
5106 \SpecialChar ~
5107 \SpecialChar ~
5108 mov a,r1
5109 \family default 
5110
5111 \newline 
5112
5113 \newline 
5114 to
5115 \newline 
5116
5117 \newline 
5118
5119 \family typewriter 
5120 mov r1,a
5121 \family default 
5122
5123 \newline 
5124
5125 \newline 
5126 Note: All occurrences of a 
5127 \emph on 
5128 %n
5129 \emph default 
5130  (pattern variable) must denote the same string.
5131  With the above rule, the assembly sequence:
5132 \newline 
5133
5134 \newline 
5135
5136 \family typewriter 
5137 \SpecialChar ~
5138 \SpecialChar ~
5139 mov r1,a 
5140 \newline 
5141 \SpecialChar ~
5142 \SpecialChar ~
5143 mov a,r2
5144 \family default 
5145
5146 \newline 
5147
5148 \newline 
5149 will remain unmodified.
5150 \newline 
5151
5152 \newline 
5153 Other special case optimizations may be added by the user (via 
5154 \emph on 
5155 --peep-file option
5156 \emph default 
5157 ).
5158  E.g.
5159  some variants of the 8051 MCU allow only 
5160 \family typewriter 
5161 ajmp
5162 \family default 
5163  and 
5164 \family typewriter 
5165 acall
5166 \family default 
5167 .
5168  The following two rules will change all 
5169 \family typewriter 
5170 ljmp
5171 \family default 
5172  and 
5173 \family typewriter 
5174 lcall
5175 \family default 
5176  to 
5177 \family typewriter 
5178 ajmp
5179 \family default 
5180  and 
5181 \family typewriter 
5182 acall
5183 \family default 
5184
5185 \newline 
5186
5187 \newline 
5188
5189 \family typewriter 
5190 replace { lcall %1 } by { acall %1 } 
5191 \newline 
5192 replace { ljmp %1 } by { ajmp %1 }
5193 \family default 
5194
5195 \newline 
5196
5197 \newline 
5198 The 
5199 \emph on 
5200 inline-assembler code
5201 \emph default 
5202  is also passed through the peep hole optimizer, thus the peephole optimizer
5203  can also be used as an assembly level macro expander.
5204  The rules themselves are MCU dependent whereas the rule language infra-structur
5205 e is MCU independent.
5206  Peephole optimization rules for other MCU can be easily programmed using
5207  the rule language.
5208 \newline 
5209
5210 \newline 
5211 The syntax for a rule is as follows:
5212 \newline 
5213
5214 \newline 
5215
5216 \family typewriter 
5217 rule := replace [ restart ] '{' <assembly sequence> '
5218 \backslash 
5219 n' 
5220 \newline 
5221 \SpecialChar ~
5222  \SpecialChar ~
5223  \SpecialChar ~
5224  \SpecialChar ~
5225  \SpecialChar ~
5226  \SpecialChar ~
5227  \SpecialChar ~
5228  \SpecialChar ~
5229  \SpecialChar ~
5230  \SpecialChar ~
5231  \SpecialChar ~
5232  \SpecialChar ~
5233  \SpecialChar ~
5234  \SpecialChar ~
5235  '}' by '{' '
5236 \backslash 
5237 n' 
5238 \newline 
5239 \SpecialChar ~
5240  \SpecialChar ~
5241  \SpecialChar ~
5242  \SpecialChar ~
5243  \SpecialChar ~
5244  \SpecialChar ~
5245  \SpecialChar ~
5246  \SpecialChar ~
5247  \SpecialChar ~
5248  \SpecialChar ~
5249  \SpecialChar ~
5250  \SpecialChar ~
5251  \SpecialChar ~
5252  \SpecialChar ~
5253  \SpecialChar ~
5254  \SpecialChar ~
5255  <assembly sequence> '
5256 \backslash 
5257 n' 
5258 \newline 
5259 \SpecialChar ~
5260  \SpecialChar ~
5261  \SpecialChar ~
5262  \SpecialChar ~
5263  \SpecialChar ~
5264  \SpecialChar ~
5265  \SpecialChar ~
5266  \SpecialChar ~
5267  \SpecialChar ~
5268  \SpecialChar ~
5269  \SpecialChar ~
5270  \SpecialChar ~
5271  \SpecialChar ~
5272  \SpecialChar ~
5273  '}' [if <functionName> ] '
5274 \backslash 
5275 n' 
5276 \newline 
5277
5278 \family default 
5279
5280 \newline 
5281 <assembly sequence> := assembly instruction (each instruction including
5282  labels must be on a separate line).
5283 \newline 
5284
5285 \newline 
5286 The optimizer will apply to the rules one by one from the top in the sequence
5287  of their appearance, it will terminate when all rules are exhausted.
5288  If the 'restart' option is specified, then the optimizer will start matching
5289  the rules again from the top, this option for a rule is expensive (performance)
5290 , it is intended to be used in situations where a transformation will trigger
5291  the same rule again.
5292  An example of this (not a good one, it has side effects) is the following
5293  rule:
5294 \newline 
5295
5296 \newline 
5297
5298 \family typewriter 
5299 replace restart { 
5300 \newline 
5301 \SpecialChar ~
5302 \SpecialChar ~
5303 pop %1 
5304 \newline 
5305 \SpecialChar ~
5306 \SpecialChar ~
5307 push %1 } by { 
5308 \newline 
5309 \SpecialChar ~
5310 \SpecialChar ~
5311 ; nop 
5312 \newline 
5313 }
5314 \family default 
5315
5316 \newline 
5317
5318 \newline 
5319 Note that the replace pattern cannot be a blank, but can be a comment line.
5320  Without the 'restart' option only the inner most 'pop' 'push' pair would
5321  be eliminated, i.e.:
5322 \newline 
5323
5324 \newline 
5325
5326 \family typewriter 
5327 \SpecialChar ~
5328 \SpecialChar ~
5329 pop ar1 
5330 \newline 
5331 \SpecialChar ~
5332 \SpecialChar ~
5333 pop ar2 
5334 \newline 
5335 \SpecialChar ~
5336 \SpecialChar ~
5337 push ar2 
5338 \newline 
5339 \SpecialChar ~
5340 \SpecialChar ~
5341 push ar1
5342 \family default 
5343
5344 \newline 
5345
5346 \newline 
5347 would result in:
5348 \newline 
5349
5350 \newline 
5351
5352 \family typewriter 
5353 \SpecialChar ~
5354 \SpecialChar ~
5355 pop ar1 
5356 \newline 
5357 \SpecialChar ~
5358 \SpecialChar ~
5359 ; nop 
5360 \newline 
5361 \SpecialChar ~
5362 \SpecialChar ~
5363 push ar1
5364 \family default 
5365
5366 \newline 
5367
5368 \newline 
5369
5370 \emph on 
5371 with
5372 \emph default 
5373  the restart option the rule will be applied again to the resulting code
5374  and then all the pop-push pairs will be eliminated to yield:
5375 \newline 
5376
5377 \newline 
5378
5379 \family typewriter 
5380 \SpecialChar ~
5381 \SpecialChar ~
5382 ; nop 
5383 \newline 
5384 \SpecialChar ~
5385 \SpecialChar ~
5386 ; nop
5387 \family default 
5388
5389 \newline 
5390
5391 \newline 
5392 A conditional function can be attached to a rule.
5393  Attaching rules are somewhat more involved, let me illustrate this with
5394  an example.
5395 \newline 
5396
5397 \newline 
5398
5399 \family typewriter 
5400 replace { 
5401 \newline 
5402 \SpecialChar ~
5403  \SpecialChar ~
5404  \SpecialChar ~
5405 ljmp %5 
5406 \newline 
5407 %2:
5408 \newline 
5409 } by { 
5410 \newline 
5411 \SpecialChar ~
5412  \SpecialChar ~
5413  \SpecialChar ~
5414 sjmp %5 
5415 \newline 
5416 %2:
5417 \newline 
5418 } if labelInRange
5419 \family default 
5420
5421 \newline 
5422
5423 \newline 
5424 The optimizer does a look-up of a function name table defined in function
5425  
5426 \emph on 
5427 callFuncByName
5428 \emph default 
5429  in the source file SDCCpeeph.c, with the name 
5430 \emph on 
5431 labelInRange
5432 \emph default 
5433 .
5434  If it finds a corresponding entry the function is called.
5435  Note there can be no parameters specified for these functions, in this
5436  case the use of 
5437 \emph on 
5438 %5
5439 \emph default 
5440  is crucial, since the function 
5441 \emph on 
5442 labelInRange
5443 \emph default 
5444  expects to find the label in that particular variable (the hash table containin
5445 g the variable bindings is passed as a parameter).
5446  If you want to code more such functions, take a close look at the function
5447  labelInRange and the calling mechanism in source file SDCCpeeph.c.
5448  I know this whole thing is a little kludgey, but maybe some day we will
5449  have some better means.
5450  If you are looking at this file, you will also see the default rules that
5451  are compiled into the compiler, you can add your own rules in the default
5452  set there if you get tired of specifying the --peep-file option.
5453 \layout Subsection
5454
5455 Pragmas
5456 \layout Standard
5457
5458 SDCC supports the following #pragma directives.
5459  This directives are applicable only at a function level.
5460 \layout Itemize
5461
5462 SAVE - this will save all the current options.
5463 \layout Itemize
5464
5465 RESTORE - will restore the saved options from the last save.
5466  Note that SAVES & RESTOREs cannot be nested.
5467  SDCC uses the same buffer to save the options each time a SAVE is called.
5468 \layout Itemize
5469
5470 NOGCSE - will stop global subexpression elimination.
5471 \layout Itemize
5472
5473 NOINDUCTION - will stop loop induction optimizations.
5474 \layout Itemize
5475
5476 NOJTBOUND - will not generate code for boundary value checking, when switch
5477  statements are turned into jump-tables.
5478 \layout Itemize
5479
5480 NOOVERLAY - the compiler will not overlay the parameters and local variables
5481  of a function.
5482 \layout Itemize
5483
5484 NOLOOPREVERSE - Will not do loop reversal optimization
5485 \layout Itemize
5486
5487 EXCLUDE NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation
5488  of pair of push/pop instruction in ISR function (using interrupt keyword).
5489  The directive should be placed immediately before the ISR function definition
5490  and it affects ALL ISR functions following it.
5491  To enable the normal register saving for ISR functions use #pragma\SpecialChar ~
5492 EXCLUDE\SpecialChar ~
5493 none.
5494 \layout Itemize
5495
5496 CALLEE-SAVES function1[,function2[,function3...]] - The compiler by default
5497  uses a caller saves convention for register saving across function calls,
5498  however this can cause unneccessary register pushing & popping when calling
5499  small functions from larger functions.
5500  This option can be used to switch the register saving convention for the
5501  function names specified.
5502  The compiler will not save registers when calling these functions, extra
5503  code will be generated at the entry & exit for these functions to save
5504  & restore the registers used by these functions, this can SUBSTANTIALLY
5505  reduce code & improve run time performance of the generated code.
5506  In future the compiler (with interprocedural analysis) will be able to
5507  determine the appropriate scheme to use for each function call.
5508  If --callee-saves command line option is used, the function names specified
5509  in #pragma\SpecialChar ~
5510 CALLEE-SAVES is appended to the list of functions specified inthe
5511  command line.
5512 \layout Standard
5513
5514 The pragma's are intended to be used to turn-off certain optimizations which
5515  might cause the compiler to generate extra stack / data space to store
5516  compiler generated temporary variables.
5517  This usually happens in large functions.
5518  Pragma directives should be used as shown in the following example, they
5519  are used to control options & optimizations for a given function; pragmas
5520  should be placed before and/or after a function, placing pragma's inside
5521  a function body could have unpredictable results.
5522 \newline 
5523
5524 \newline 
5525
5526 \family typewriter 
5527 #pragma SAVE /* save the current settings */ 
5528 \newline 
5529 #pragma NOGCSE /* turnoff global subexpression elimination */ 
5530 \newline 
5531 #pragma NOINDUCTION /* turn off induction optimizations */ 
5532 \newline 
5533 int foo () 
5534 \newline 
5535
5536 \newline 
5537 \SpecialChar ~
5538  \SpecialChar ~
5539  ...
5540  
5541 \newline 
5542 \SpecialChar ~
5543  \SpecialChar ~
5544  /* large code */ 
5545 \newline 
5546 \SpecialChar ~
5547  \SpecialChar ~
5548  ...
5549  
5550 \newline 
5551
5552 \newline 
5553 #pragma RESTORE /* turn the optimizations back on */
5554 \family default 
5555
5556 \newline 
5557
5558 \newline 
5559 The compiler will generate a warning message when extra space is allocated.
5560  It is strongly recommended that the SAVE and RESTORE pragma's be used when
5561  changing options for a function.
5562 \layout Subsection
5563
5564
5565 \emph on 
5566 <pending: this is messy and incomplete>
5567 \emph default 
5568  Library Routines
5569 \layout Enumerate
5570
5571 Compiler support routines (_gptrget, _mulint etc)
5572 \layout Enumerate
5573
5574 Stdclib functions (puts, printf, strcat etc)
5575 \layout Enumerate
5576
5577 Math functions (sin, pow, sqrt etc)
5578 \layout Subsection
5579
5580 Interfacing with Assembly Routines
5581 \layout Subsubsection
5582
5583 Global Registers used for Parameter Passing
5584 \layout Standard
5585
5586 The compiler always uses the global registers 
5587 \emph on 
5588 DPL,DPH,B 
5589 \emph default 
5590 and
5591 \emph on 
5592  ACC
5593 \emph default 
5594  to pass the first parameter to a routine.
5595  The second parameter onwards is either allocated on the stack (for reentrant
5596  routines or if --stack-auto is used) or in the internal / external ram
5597  (depending on the memory model).
5598  
5599 \layout Subsubsection
5600
5601 Assembler Routine(non-reentrant)
5602 \layout Standard
5603
5604 In the following example the function cfunc calls an assembler routine asm_func,
5605  which takes two parameters.
5606 \newline 
5607
5608 \newline 
5609
5610 \family typewriter 
5611 extern int asm_func(unsigned char, unsigned char);
5612 \newline 
5613
5614 \newline 
5615 int c_func (unsigned char i, unsigned char j)
5616 \newline 
5617 {
5618 \newline 
5619 \SpecialChar ~
5620 \SpecialChar ~
5621 \SpecialChar ~
5622 \SpecialChar ~
5623 return asm_func(i,j);
5624 \newline 
5625 }
5626 \newline 
5627
5628 \newline 
5629 int main()
5630 \newline 
5631 {
5632 \newline 
5633 \SpecialChar ~
5634 \SpecialChar ~
5635 \SpecialChar ~
5636 \SpecialChar ~
5637 return c_func(10,9);
5638 \newline 
5639 }
5640 \newline 
5641
5642 \newline 
5643
5644 \family default 
5645 The corresponding assembler function is:
5646 \newline 
5647
5648 \newline 
5649
5650 \family typewriter 
5651 .globl _asm_func_PARM_2 
5652 \newline 
5653 \SpecialChar ~
5654 \SpecialChar ~
5655 \SpecialChar ~
5656 \SpecialChar ~
5657 \SpecialChar ~
5658 \SpecialChar ~
5659 \SpecialChar ~
5660 \SpecialChar ~
5661 .globl _asm_func 
5662 \newline 
5663 \SpecialChar ~
5664 \SpecialChar ~
5665 \SpecialChar ~
5666 \SpecialChar ~
5667 \SpecialChar ~
5668 \SpecialChar ~
5669 \SpecialChar ~
5670 \SpecialChar ~
5671 .area OSEG 
5672 \newline 
5673 _asm_func_PARM_2:
5674 \newline 
5675 \SpecialChar ~
5676 \SpecialChar ~
5677 \SpecialChar ~
5678 \SpecialChar ~
5679 \SpecialChar ~
5680 \SpecialChar ~
5681 \SpecialChar ~
5682 \SpecialChar ~
5683 .ds      1 
5684 \newline 
5685 \SpecialChar ~
5686 \SpecialChar ~
5687 \SpecialChar ~
5688 \SpecialChar ~
5689 \SpecialChar ~
5690 \SpecialChar ~
5691 \SpecialChar ~
5692 \SpecialChar ~
5693 .area CSEG 
5694 \newline 
5695 _asm_func: 
5696 \newline 
5697 \SpecialChar ~
5698 \SpecialChar ~
5699 \SpecialChar ~
5700 \SpecialChar ~
5701 \SpecialChar ~
5702 \SpecialChar ~
5703 \SpecialChar ~
5704 \SpecialChar ~
5705 mov     a,dpl 
5706 \newline 
5707 \SpecialChar ~
5708 \SpecialChar ~
5709 \SpecialChar ~
5710 \SpecialChar ~
5711 \SpecialChar ~
5712 \SpecialChar ~
5713 \SpecialChar ~
5714 \SpecialChar ~
5715 add     a,_asm_func_PARM_2 
5716 \newline 
5717 \SpecialChar ~
5718 \SpecialChar ~
5719 \SpecialChar ~
5720 \SpecialChar ~
5721 \SpecialChar ~
5722 \SpecialChar ~
5723 \SpecialChar ~
5724 \SpecialChar ~
5725 mov     dpl,a 
5726 \newline 
5727 \SpecialChar ~
5728 \SpecialChar ~
5729 \SpecialChar ~
5730 \SpecialChar ~
5731 \SpecialChar ~
5732 \SpecialChar ~
5733 \SpecialChar ~
5734 \SpecialChar ~
5735 mov     dpl,#0x00 
5736 \newline 
5737 \SpecialChar ~
5738 \SpecialChar ~
5739 \SpecialChar ~
5740 \SpecialChar ~
5741 \SpecialChar ~
5742 \SpecialChar ~
5743 \SpecialChar ~
5744 \SpecialChar ~
5745 ret
5746 \newline 
5747
5748 \newline 
5749
5750 \family default 
5751 Note here that the return values are placed in 'dpl' - One byte return value,
5752  'dpl' LSB & 'dph' MSB for two byte values.
5753  'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
5754 b' & 'acc' for four byte values.
5755 \layout Standard
5756
5757 The parameter naming convention is _<function_name>_PARM_<n>, where n is
5758  the parameter number starting from 1, and counting from the left.
5759  The first parameter is passed in 
5760 \begin_inset Quotes eld
5761 \end_inset 
5762
5763 dpl
5764 \begin_inset Quotes erd
5765 \end_inset 
5766
5767  for One bye parameter, 
5768 \begin_inset Quotes eld
5769 \end_inset 
5770
5771 dptr
5772 \begin_inset Quotes erd
5773 \end_inset 
5774
5775  if two bytes, 
5776 \begin_inset Quotes eld
5777 \end_inset 
5778
5779 b,dptr
5780 \begin_inset Quotes erd
5781 \end_inset 
5782
5783  for three bytes and 
5784 \begin_inset Quotes eld
5785 \end_inset 
5786
5787 acc,b,dptr
5788 \begin_inset Quotes erd
5789 \end_inset 
5790
5791  for four bytes, the varible name for the second parameter will be _<function_na
5792 me>_PARM_2.
5793 \newline 
5794
5795 \newline 
5796 Assemble the assembler routine with the following command:
5797 \newline 
5798
5799 \newline 
5800
5801 \family sans 
5802 \series bold 
5803 asx8051 -losg asmfunc.asm
5804 \newline 
5805
5806 \newline 
5807
5808 \family default 
5809 \series default 
5810 Then compile and link the assembler routine to the C source file with the
5811  following command:
5812 \newline 
5813
5814 \newline 
5815
5816 \family sans 
5817 \series bold 
5818 sdcc cfunc.c asmfunc.rel
5819 \layout Subsubsection
5820
5821 Assembler Routine(reentrant)
5822 \layout Standard
5823
5824 In this case the second parameter onwards will be passed on the stack, the
5825  parameters are pushed from right to left i.e.
5826  after the call the left most parameter will be on the top of the stack.
5827  Here is an example:
5828 \newline 
5829
5830 \newline 
5831
5832 \family typewriter 
5833 extern int asm_func(unsigned char, unsigned char);
5834 \newline 
5835
5836 \newline 
5837 int c_func (unsigned char i, unsigned char j) reentrant 
5838 \newline 
5839
5840 \newline 
5841 \SpecialChar ~
5842 \SpecialChar ~
5843 \SpecialChar ~
5844 \SpecialChar ~
5845 return asm_func(i,j); 
5846 \newline 
5847
5848 \newline 
5849
5850 \newline 
5851 int main() 
5852 \newline 
5853
5854 \newline 
5855 \SpecialChar ~
5856 \SpecialChar ~
5857 \SpecialChar ~
5858 \SpecialChar ~
5859 return c_func(10,9); 
5860 \newline 
5861 }
5862 \newline 
5863
5864 \family default 
5865
5866 \newline 
5867 The corresponding assembler routine is:
5868 \newline 
5869
5870 \newline 
5871
5872 \family typewriter 
5873 .globl _asm_func 
5874 \newline 
5875 _asm_func: 
5876 \newline 
5877 \SpecialChar ~
5878 \SpecialChar ~
5879 \SpecialChar ~
5880 \SpecialChar ~
5881 push  _bp 
5882 \newline 
5883 \SpecialChar ~
5884 \SpecialChar ~
5885 \SpecialChar ~
5886 \SpecialChar ~
5887 mov  _bp,sp 
5888 \newline 
5889 \SpecialChar ~
5890 \SpecialChar ~
5891 \SpecialChar ~
5892 \SpecialChar ~
5893 mov  r2,dpl
5894 \newline 
5895 \SpecialChar ~
5896 \SpecialChar ~
5897 \SpecialChar ~
5898 \SpecialChar ~
5899 mov  a,_bp 
5900 \newline 
5901 \SpecialChar ~
5902 \SpecialChar ~
5903 \SpecialChar ~
5904 \SpecialChar ~
5905 clr  c 
5906 \newline 
5907 \SpecialChar ~
5908 \SpecialChar ~
5909 \SpecialChar ~
5910 \SpecialChar ~
5911 add  a,#0xfd 
5912 \newline 
5913 \SpecialChar ~
5914 \SpecialChar ~
5915 \SpecialChar ~
5916 \SpecialChar ~
5917 mov  r0,a 
5918 \newline 
5919 \SpecialChar ~
5920 \SpecialChar ~
5921 \SpecialChar ~
5922 \SpecialChar ~
5923 add  a,#0xfc
5924 \newline 
5925 \SpecialChar ~
5926 \SpecialChar ~
5927 \SpecialChar ~
5928 \SpecialChar ~
5929 mov  r1,a 
5930 \newline 
5931 \SpecialChar ~
5932 \SpecialChar ~
5933 \SpecialChar ~
5934 \SpecialChar ~
5935 mov  a,@r0 
5936 \newline 
5937 \SpecialChar ~
5938 \SpecialChar ~
5939 \SpecialChar ~
5940 \SpecialChar ~
5941 add  a,r2
5942 \newline 
5943 \SpecialChar ~
5944 \SpecialChar ~
5945 \SpecialChar ~
5946 \SpecialChar ~
5947 mov  dpl,a 
5948 \newline 
5949 \SpecialChar ~
5950 \SpecialChar ~
5951 \SpecialChar ~
5952 \SpecialChar ~
5953 mov  dph,#0x00 
5954 \newline 
5955 \SpecialChar ~
5956 \SpecialChar ~
5957 \SpecialChar ~
5958 \SpecialChar ~
5959 mov  sp,_bp 
5960 \newline 
5961 \SpecialChar ~
5962 \SpecialChar ~
5963 \SpecialChar ~
5964 \SpecialChar ~
5965 pop  _bp 
5966 \newline 
5967 \SpecialChar ~
5968 \SpecialChar ~
5969 \SpecialChar ~
5970 \SpecialChar ~
5971 ret
5972 \newline 
5973
5974 \newline 
5975
5976 \family default 
5977 The compiling and linking procedure remains the same, however note the extra
5978  entry & exit linkage required for the assembler code, _bp is the stack
5979  frame pointer and is used to compute the offset into the stack for parameters
5980  and local variables.
5981 \layout Subsection
5982
5983 External Stack
5984 \layout Standard
5985
5986 The external stack is located at the start of the external ram segment,
5987  and is 256 bytes in size.
5988  When --xstack option is used to compile the program, the parameters and
5989  local variables of all reentrant functions are allocated in this area.
5990  This option is provided for programs with large stack space requirements.
5991  When used with the --stack-auto option, all parameters and local variables
5992  are allocated on the external stack (note support libraries will need to
5993  be recompiled with the same options).
5994 \layout Standard
5995
5996 The compiler outputs the higher order address byte of the external ram segment
5997  into PORT P2, therefore when using the External Stack option, this port
5998  MAY NOT be used by the application program.
5999 \layout Subsection
6000
6001 ANSI-Compliance
6002 \layout Standard
6003
6004 Deviations from the compliancy.
6005 \layout Itemize
6006
6007 functions are not always reentrant.
6008 \layout Itemize
6009
6010 structures cannot be assigned values directly, cannot be passed as function
6011  parameters or assigned to each other and cannot be a return value from
6012  a function, e.g.:
6013 \family typewriter 
6014
6015 \newline 
6016
6017 \newline 
6018 struct s { ...
6019  }; 
6020 \newline 
6021 struct s s1, s2; 
6022 \newline 
6023 foo() 
6024 \newline 
6025
6026 \newline 
6027 \SpecialChar ~
6028 \SpecialChar ~
6029 \SpecialChar ~
6030 \SpecialChar ~
6031 ...
6032  
6033 \newline 
6034 \SpecialChar ~
6035 \SpecialChar ~
6036 \SpecialChar ~
6037 \SpecialChar ~
6038 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ 
6039 \newline 
6040 \SpecialChar ~
6041 \SpecialChar ~
6042 \SpecialChar ~
6043 \SpecialChar ~
6044 ...
6045  
6046 \newline 
6047 }
6048 \newline 
6049 struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in
6050  ANSI */ 
6051 \newline 
6052
6053 \newline 
6054 \SpecialChar ~
6055 \SpecialChar ~
6056 \SpecialChar ~
6057 \SpecialChar ~
6058 struct s rets; 
6059 \newline 
6060 \SpecialChar ~
6061 \SpecialChar ~
6062 \SpecialChar ~
6063 \SpecialChar ~
6064 ...
6065  
6066 \newline 
6067 \SpecialChar ~
6068 \SpecialChar ~
6069 \SpecialChar ~
6070 \SpecialChar ~
6071 return rets;/* is invalid in SDCC although allowed in ANSI */ 
6072 \newline 
6073 }
6074 \layout Itemize
6075
6076 'long long' (64 bit integers) not supported.
6077 \layout Itemize
6078
6079 'double' precision floating point not supported.
6080 \layout Itemize
6081
6082 No support for setjmp and longjmp (for now).
6083 \layout Itemize
6084
6085 Old K&R style function declarations are NOT allowed.
6086 \newline 
6087
6088 \family typewriter 
6089
6090 \newline 
6091 foo(i,j) /* this old style of function declarations */ 
6092 \newline 
6093 int i,j; /* are valid in ANSI but not valid in SDCC */ 
6094 \newline 
6095
6096 \newline 
6097 \SpecialChar ~
6098 \SpecialChar ~
6099 \SpecialChar ~
6100 \SpecialChar ~
6101 ...
6102  
6103 \newline 
6104 }
6105 \layout Itemize
6106
6107 functions declared as pointers must be dereferenced during the call.
6108 \newline 
6109
6110 \family typewriter 
6111
6112 \newline 
6113 int (*foo)();
6114 \newline 
6115 ...
6116  
6117 \newline 
6118 /* has to be called like this */ 
6119 \newline 
6120 (*foo)(); /* ansi standard allows calls to be made like 'foo()' */
6121 \layout Subsection
6122
6123 Cyclomatic Complexity
6124 \layout Standard
6125
6126 Cyclomatic complexity of a function is defined as the number of independent
6127  paths the program can take during execution of the function.
6128  This is an important number since it defines the number test cases you
6129  have to generate to validate the function.
6130  The accepted industry standard for complexity number is 10, if the cyclomatic
6131  complexity reported by SDCC exceeds 10 you should think about simplification
6132  of the function logic.
6133  Note that the complexity level is not related to the number of lines of
6134  code in a function.
6135  Large functions can have low complexity, and small functions can have large
6136  complexity levels.
6137  
6138 \newline 
6139
6140 \newline 
6141 SDCC uses the following formula to compute the complexity:
6142 \newline 
6143
6144 \layout Standard
6145
6146 complexity = (number of edges in control flow graph) - (number of nodes
6147  in control flow graph) + 2;
6148 \newline 
6149
6150 \newline 
6151 Having said that the industry standard is 10, you should be aware that in
6152  some cases it be may unavoidable to have a complexity level of less than
6153  10.
6154  For example if you have switch statement with more than 10 case labels,
6155  each case label adds one to the complexity level.
6156  The complexity level is by no means an absolute measure of the algorithmic
6157  complexity of the function, it does however provide a good starting point
6158  for which functions you might look at for further optimization.
6159 \layout Section
6160
6161 TIPS
6162 \layout Standard
6163
6164 Here are a few guidelines that will help the compiler generate more efficient
6165  code, some of the tips are specific to this compiler others are generally
6166  good programming practice.
6167 \layout Itemize
6168
6169 Use the smallest data type to represent your data-value.
6170  If it is known in advance that the value is going to be less than 256 then
6171  use a 'char' instead of a 'short' or 'int'.
6172 \layout Itemize
6173
6174 Use unsigned when it is known in advance that the value is not going to
6175  be negative.
6176  This helps especially if you are doing division or multiplication.
6177 \layout Itemize
6178
6179 NEVER jump into a LOOP.
6180 \layout Itemize
6181
6182 Declare the variables to be local whenever possible, especially loop control
6183  variables (induction).
6184 \layout Itemize
6185
6186 Since the compiler does not do implicit integral promotion, the programmer
6187  should do an explicit cast when integral promotion is required.
6188 \layout Itemize
6189
6190 Reducing the size of division, multiplication & modulus operations can reduce
6191  code size substantially.
6192  Take the following code for example.
6193 \family typewriter 
6194
6195 \newline 
6196
6197 \newline 
6198 foobar(unsigned int p1, unsigned char ch)
6199 \newline 
6200 {
6201 \newline 
6202     unsigned char ch1 = p1 % ch ;
6203 \newline 
6204     ....
6205     
6206 \newline 
6207 }
6208 \newline 
6209
6210 \family default 
6211
6212 \newline 
6213 For the modulus operation the variable ch will be promoted to unsigned int
6214  first then the modulus operation will be performed (this will lead to a
6215  call to support routine _moduint()), and the result will be casted to a
6216  char.
6217  If the code is changed to 
6218 \newline 
6219
6220 \family typewriter 
6221
6222 \newline 
6223 foobar(unsigned int p1, unsigned char ch)
6224 \newline 
6225 {
6226 \newline 
6227     unsigned char ch1 = (unsigned char)p1 % ch ;
6228 \newline 
6229     ....
6230     
6231 \newline 
6232 }
6233 \newline 
6234
6235 \family default 
6236
6237 \newline 
6238 It would substantially reduce the code generated (future versions of the
6239  compiler will be smart enough to detect such optimization oppurtunities).
6240 \layout Subsection
6241
6242 Notes on MCS51 memory layout
6243 \layout Standard
6244
6245 The 8051 family of micro controller have a minimum of 128 bytes of internal
6246  memory which is structured as follows
6247 \newline 
6248
6249 \newline 
6250 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7
6251  
6252 \newline 
6253 - Bytes 20-2F - 16 bytes to hold 128 bit variables and 
6254 \newline 
6255 - Bytes 30-7F - 60 bytes for general purpose use.
6256 \newline 
6257
6258 \newline 
6259 Normally the SDCC compiler will only utilise the first bank of registers,
6260  but it is possible to specify that other banks of registers should be used
6261  in interrupt routines.
6262  By default, the compiler will place the stack after the last bank of used
6263  registers, i.e.
6264  if the first 2 banks of registers are used, it will position the base of
6265  the internal stack at address 16 (0X10).
6266  This implies that as the stack grows, it will use up the remaining register
6267  banks, and the 16 bytes used by the 128 bit variables, and 60 bytes for
6268  general purpose use.
6269 \layout Standard
6270
6271 By default, the compiler uses the 60 general purpose bytes to hold "near
6272  data".
6273  The compiler/optimiser may also declare some Local Variables in this area
6274  to hold local data.
6275  
6276 \layout Standard
6277
6278 If any of the 128 bit variables are used, or near data is being used then
6279  care needs to be taken to ensure that the stack does not grow so much that
6280  it starts to over write either your bit variables or "near data".
6281  There is no runtime checking to prevent this from happening.
6282 \layout Standard
6283
6284 The amount of stack being used is affected by the use of the "internal stack"
6285  to save registers before a subroutine call is made (--stack-auto will declare
6286  parameters and local variables on the stack) and the number of nested subroutin
6287 es.
6288 \layout Standard
6289
6290 If you detect that the stack is over writing you data, then the following
6291  can be done.
6292  --xstack will cause an external stack to be used for saving registers and
6293  (if --stack-auto is being used) storing parameters and local variables.
6294  However this will produce more code which will be slower to execute.
6295  
6296 \layout Standard
6297
6298 --stack-loc will allow you specify the start of the stack, i.e.
6299  you could start it after any data in the general purpose area.
6300  However this may waste the memory not used by the register banks and if
6301  the size of the "near data" increases, it may creep into the bottom of
6302  the stack.
6303 \layout Standard
6304
6305 --stack-after-data, similar to the --stack-loc, but it automatically places
6306  the stack after the end of the "near data".
6307  Again this could waste any spare register space.
6308 \layout Standard
6309
6310 --data-loc allows you to specify the start address of the near data.
6311  This could be used to move the "near data" further away from the stack
6312  giving it more room to grow.
6313  This will only work if no bit variables are being used and the stack can
6314  grow to use the bit variable space.
6315 \newline 
6316
6317 \newline 
6318 Conclusion.
6319 \newline 
6320
6321 \newline 
6322 If you find that the stack is over writing your bit variables or "near data"
6323  then the approach which best utilised the internal memory is to position
6324  the "near data" after the last bank of used registers or, if you use bit
6325  variables, after the last bit variable by using the --data-loc, e.g.
6326  if two register banks are being used and no bit variables, --data-loc 16,
6327  and use the --stack-after-data option.
6328 \layout Standard
6329
6330 If bit variables are being used, another method would be to try and squeeze
6331  the data area in the unused register banks if it will fit, and start the
6332  stack after the last bit variable.
6333 \layout Section
6334
6335 Retargetting for other MCUs.
6336 \layout Standard
6337
6338 The issues for retargetting the compiler are far too numerous to be covered
6339  by this document.
6340  What follows is a brief description of each of the seven phases of the
6341  compiler and its MCU dependency.
6342 \layout Itemize
6343
6344 Parsing the source and building the annotated parse tree.
6345  This phase is largely MCU independent (except for the language extensions).
6346  Syntax & semantic checks are also done in this phase, along with some initial
6347  optimizations like back patching labels and the pattern matching optimizations
6348  like bit-rotation etc.
6349 \layout Itemize
6350
6351 The second phase involves generating an intermediate code which can be easy
6352  manipulated during the later phases.
6353  This phase is entirely MCU independent.
6354  The intermediate code generation assumes the target machine has unlimited
6355  number of registers, and designates them with the name iTemp.
6356  The compiler can be made to dump a human readable form of the code generated
6357  by using the --dumpraw option.
6358 \layout Itemize
6359
6360 This phase does the bulk of the standard optimizations and is also MCU independe
6361 nt.
6362  This phase can be broken down into several sub-phases:
6363 \newline 
6364
6365 \newline 
6366 Break down intermediate code (iCode) into basic blocks.
6367 \newline 
6368 Do control flow & data flow analysis on the basic blocks.
6369 \newline 
6370 Do local common subexpression elimination, then global subexpression elimination
6371 \newline 
6372 Dead code elimination
6373 \newline 
6374 Loop optimizations
6375 \newline 
6376 If loop optimizations caused any changes then do 'global subexpression eliminati
6377 on' and 'dead code elimination' again.
6378 \layout Itemize
6379
6380 This phase determines the live-ranges; by live range I mean those iTemp
6381  variables defined by the compiler that still survive after all the optimization
6382 s.
6383  Live range analysis is essential for register allocation, since these computati
6384 on determines which of these iTemps will be assigned to registers, and for
6385  how long.
6386 \layout Itemize
6387
6388 Phase five is register allocation.
6389  There are two parts to this process.
6390 \newline 
6391
6392 \newline 
6393 The first part I call 'register packing' (for lack of a better term).
6394  In this case several MCU specific expression folding is done to reduce
6395  register pressure.
6396 \newline 
6397
6398 \newline 
6399 The second part is more MCU independent and deals with allocating registers
6400  to the remaining live ranges.
6401  A lot of MCU specific code does creep into this phase because of the limited
6402  number of index registers available in the 8051.
6403 \layout Itemize
6404
6405 The Code generation phase is (unhappily), entirely MCU dependent and very
6406  little (if any at all) of this code can be reused for other MCU.
6407  However the scheme for allocating a homogenized assembler operand for each
6408  iCode operand may be reused.
6409 \layout Itemize
6410
6411 As mentioned in the optimization section the peep-hole optimizer is rule
6412  based system, which can reprogrammed for other MCUs.
6413 \layout Section
6414
6415 SDCDB - Source Level Debugger
6416 \layout Standard
6417
6418 SDCC is distributed with a source level debugger.
6419  The debugger uses a command line interface, the command repertoire of the
6420  debugger has been kept as close to gdb (the GNU debugger) as possible.
6421  The configuration and build process is part of the standard compiler installati
6422 on, which also builds and installs the debugger in the target directory
6423  specified during configuration.
6424  The debugger allows you debug BOTH at the C source and at the ASM source
6425  level.
6426 \layout Subsection
6427
6428 Compiling for Debugging
6429 \layout Standard
6430
6431 The \SpecialChar \-
6432 \SpecialChar \-
6433 debug option must be specified for all files for which debug information
6434  is to be generated.
6435  The complier generates a .cdb file for each of these files.
6436  The linker updates the .cdb file with the address information.
6437  This .cdb is used by the debugger.
6438 \layout Subsection
6439
6440 How the Debugger Works
6441 \layout Standard
6442
6443 When the --debug option is specified the compiler generates extra symbol
6444  information some of which are put into the the assembler source and some
6445  are put into the .cdb file, the linker updates the .cdb file with the address
6446  information for the symbols.
6447  The debugger reads the symbolic information generated by the compiler &
6448  the address information generated by the linker.
6449  It uses the SIMULATOR (Daniel's S51) to execute the program, the program
6450  execution is controlled by the debugger.
6451  When a command is issued for the debugger, it translates it into appropriate
6452  commands for the simulator.
6453 \layout Subsection
6454
6455 Starting the Debugger
6456 \layout Standard
6457
6458 The debugger can be started using the following command line.
6459  (Assume the file you are debugging has the file name foo).
6460 \newline 
6461
6462 \newline 
6463
6464 \family sans 
6465 \series bold 
6466 sdcdb foo
6467 \newline 
6468
6469 \family default 
6470 \series default 
6471
6472 \newline 
6473 The debugger will look for the following files.
6474 \layout Itemize
6475
6476 foo.c - the source file.
6477 \layout Itemize
6478
6479 foo.cdb - the debugger symbol information file.
6480 \layout Itemize
6481
6482 foo.ihx - the intel hex format object file.
6483 \layout Subsection
6484
6485 Command Line Options.
6486 \layout Itemize
6487
6488 --directory=<source file directory> this option can used to specify the
6489  directory search list.
6490  The debugger will look into the directory list specified for source, cdb
6491  & ihx files.
6492  The items in the directory list must be separated by ':', e.g.
6493  if the source files can be in the directories /home/src1 and /home/src2,
6494  the --directory option should be --directory=/home/src1:/home/src2.
6495  Note there can be no spaces in the option.
6496  
6497 \layout Itemize
6498
6499 -cd <directory> - change to the <directory>.
6500 \layout Itemize
6501
6502 -fullname - used by GUI front ends.
6503 \layout Itemize
6504
6505 -cpu <cpu-type> - this argument is passed to the simulator please see the
6506  simulator docs for details.
6507 \layout Itemize
6508
6509 -X <Clock frequency > this options is passed to the simulator please see
6510  the simulator docs for details.
6511 \layout Itemize
6512
6513 -s <serial port file> passed to simulator see the simulator docs for details.
6514 \layout Itemize
6515
6516 -S <serial in,out> passed to simulator see the simulator docs for details.
6517 \layout Subsection
6518
6519 Debugger Commands.
6520 \layout Standard
6521
6522 As mention earlier the command interface for the debugger has been deliberately
6523  kept as close the GNU debugger gdb, as possible.
6524  This will help the integration with existing graphical user interfaces
6525  (like ddd, xxgdb or xemacs) existing for the GNU debugger.
6526 \layout Subsubsection
6527
6528 break [line | file:line | function | file:function]
6529 \layout Standard
6530
6531 Set breakpoint at specified line or function:
6532 \newline 
6533
6534 \newline 
6535
6536 \family sans 
6537 \series bold 
6538 sdcdb>break 100 
6539 \newline 
6540 sdcdb>break foo.c:100
6541 \newline 
6542 sdcdb>break funcfoo
6543 \newline 
6544 sdcdb>break foo.c:funcfoo
6545 \layout Subsubsection
6546
6547 clear [line | file:line | function | file:function ]
6548 \layout Standard
6549
6550 Clear breakpoint at specified line or function:
6551 \newline 
6552
6553 \newline 
6554
6555 \family sans 
6556 \series bold 
6557 sdcdb>clear 100
6558 \newline 
6559 sdcdb>clear foo.c:100
6560 \newline 
6561 sdcdb>clear funcfoo
6562 \newline 
6563 sdcdb>clear foo.c:funcfoo
6564 \layout Subsubsection
6565
6566 continue
6567 \layout Standard
6568
6569 Continue program being debugged, after breakpoint.
6570 \layout Subsubsection
6571
6572 finish
6573 \layout Standard
6574
6575 Execute till the end of the current function.
6576 \layout Subsubsection
6577
6578 delete [n]
6579 \layout Standard
6580
6581 Delete breakpoint number 'n'.
6582  If used without any option clear ALL user defined break points.
6583 \layout Subsubsection
6584
6585 info [break | stack | frame | registers ]
6586 \layout Itemize
6587
6588 info break - list all breakpoints
6589 \layout Itemize
6590
6591 info stack - show the function call stack.
6592 \layout Itemize
6593
6594 info frame - show information about the current execution frame.
6595 \layout Itemize
6596
6597 info registers - show content of all registers.
6598 \layout Subsubsection
6599
6600 step
6601 \layout Standard
6602
6603 Step program until it reaches a different source line.
6604 \layout Subsubsection
6605
6606 next
6607 \layout Standard
6608
6609 Step program, proceeding through subroutine calls.
6610 \layout Subsubsection
6611
6612 run
6613 \layout Standard
6614
6615 Start debugged program.
6616 \layout Subsubsection
6617
6618 ptype variable 
6619 \layout Standard
6620
6621 Print type information of the variable.
6622 \layout Subsubsection
6623
6624 print variable
6625 \layout Standard
6626
6627 print value of variable.
6628 \layout Subsubsection
6629
6630 file filename
6631 \layout Standard
6632
6633 load the given file name.
6634  Note this is an alternate method of loading file for debugging.
6635 \layout Subsubsection
6636
6637 frame
6638 \layout Standard
6639
6640 print information about current frame.
6641 \layout Subsubsection
6642
6643 set srcmode
6644 \layout Standard
6645
6646 Toggle between C source & assembly source.
6647 \layout Subsubsection
6648
6649 ! simulator command
6650 \layout Standard
6651
6652 Send the string following '!' to the simulator, the simulator response is
6653  displayed.
6654  Note the debugger does not interpret the command being sent to the simulator,
6655  so if a command like 'go' is sent the debugger can loose its execution
6656  context and may display incorrect values.
6657 \layout Subsubsection
6658
6659 quit.
6660 \layout Standard
6661
6662 "Watch me now.
6663  Iam going Down.
6664  My name is Bobby Brown"
6665 \layout Subsection
6666
6667 Interfacing with XEmacs.
6668 \layout Standard
6669
6670 Two files (in emacs lisp) are provided for the interfacing with XEmacs,
6671  sdcdb.el and sdcdbsrc.el.
6672  These two files can be found in the $(prefix)/bin directory after the installat
6673 ion is complete.
6674  These files need to be loaded into XEmacs for the interface to work.
6675  This can be done at XEmacs startup time by inserting the following into
6676  your '.xemacs' file (which can be found in your HOME directory): 
6677 \newline 
6678
6679 \newline 
6680
6681 \family typewriter 
6682 (load-file sdcdbsrc.el) 
6683 \family default 
6684
6685 \newline 
6686
6687 \newline 
6688 .xemacs is a lisp file so the () around the command is REQUIRED.
6689  The files can also be loaded dynamically while XEmacs is running, set the
6690  environment variable 'EMACSLOADPATH' to the installation bin directory
6691  (<installdir>/bin), then enter the following command ESC-x load-file sdcdbsrc.
6692  To start the interface enter the following command: 
6693 \newline 
6694
6695 \newline 
6696
6697 \family sans 
6698 \series bold 
6699 ESC-x sdcdbsrc
6700 \family default 
6701 \series default 
6702
6703 \newline 
6704
6705 \newline 
6706 You will prompted to enter the file name to be debugged.
6707  
6708 \newline 
6709
6710 \newline 
6711 The command line options that are passed to the simulator directly are bound
6712  to default values in the file sdcdbsrc.el.
6713  The variables are listed below, these values maybe changed as required.
6714 \layout Itemize
6715
6716 sdcdbsrc-cpu-type '51
6717 \layout Itemize
6718
6719 sdcdbsrc-frequency '11059200
6720 \layout Itemize
6721
6722 sdcdbsrc-serial nil
6723 \layout Standard
6724
6725 The following is a list of key mapping for the debugger interface.
6726 \layout Standard
6727
6728 \SpecialChar ~
6729
6730 \family typewriter 
6731
6732 \newline 
6733 ;; Current Listing :: 
6734 \newline 
6735 ;;key\SpecialChar ~
6736 \SpecialChar ~
6737 \SpecialChar ~
6738 \SpecialChar ~
6739 \SpecialChar ~
6740 \SpecialChar ~
6741 \SpecialChar ~
6742 \SpecialChar ~
6743 \SpecialChar ~
6744 \SpecialChar ~
6745 \SpecialChar ~
6746 \SpecialChar ~
6747 \SpecialChar ~
6748 \SpecialChar ~
6749 \SpecialChar ~
6750 binding\SpecialChar ~
6751 \SpecialChar ~
6752 \SpecialChar ~
6753 \SpecialChar ~
6754 \SpecialChar ~
6755 \SpecialChar ~
6756 \SpecialChar ~
6757 \SpecialChar ~
6758 \SpecialChar ~
6759 \SpecialChar ~
6760 \SpecialChar ~
6761 \SpecialChar ~
6762 \SpecialChar ~
6763 \SpecialChar ~
6764 \SpecialChar ~
6765 \SpecialChar ~
6766 \SpecialChar ~
6767 \SpecialChar ~
6768 \SpecialChar ~
6769 \SpecialChar ~
6770 \SpecialChar ~
6771 \SpecialChar ~
6772 Comment 
6773 \newline 
6774 ;;---\SpecialChar ~
6775 \SpecialChar ~
6776 \SpecialChar ~
6777 \SpecialChar ~
6778 \SpecialChar ~
6779 \SpecialChar ~
6780 \SpecialChar ~
6781 \SpecialChar ~
6782 \SpecialChar ~
6783 \SpecialChar ~
6784 \SpecialChar ~
6785 \SpecialChar ~
6786 \SpecialChar ~
6787 \SpecialChar ~
6788 \SpecialChar ~
6789 -------\SpecialChar ~
6790 \SpecialChar ~
6791 \SpecialChar ~
6792 \SpecialChar ~
6793 \SpecialChar ~
6794 \SpecialChar ~
6795 \SpecialChar ~
6796 \SpecialChar ~
6797 \SpecialChar ~
6798 \SpecialChar ~
6799 \SpecialChar ~
6800 \SpecialChar ~
6801 \SpecialChar ~
6802 \SpecialChar ~
6803 \SpecialChar ~
6804 \SpecialChar ~
6805 \SpecialChar ~
6806 \SpecialChar ~
6807 \SpecialChar ~
6808 \SpecialChar ~
6809 \SpecialChar ~
6810 \SpecialChar ~
6811 ------- 
6812 \newline 
6813 ;; 
6814 \newline 
6815 ;; n\SpecialChar ~
6816 \SpecialChar ~
6817 \SpecialChar ~
6818 \SpecialChar ~
6819 \SpecialChar ~
6820 \SpecialChar ~
6821 \SpecialChar ~
6822 \SpecialChar ~
6823 \SpecialChar ~
6824 \SpecialChar ~
6825 \SpecialChar ~
6826 \SpecialChar ~
6827 \SpecialChar ~
6828 \SpecialChar ~
6829  sdcdb-next-from-src\SpecialChar ~
6830 \SpecialChar ~
6831 \SpecialChar ~
6832 \SpecialChar ~
6833 \SpecialChar ~
6834 \SpecialChar ~
6835 \SpecialChar ~
6836 \SpecialChar ~
6837 \SpecialChar ~
6838 \SpecialChar ~
6839 SDCDB next command 
6840 \newline 
6841 ;; b\SpecialChar ~
6842 \SpecialChar ~
6843 \SpecialChar ~
6844 \SpecialChar ~
6845 \SpecialChar ~
6846 \SpecialChar ~
6847 \SpecialChar ~
6848 \SpecialChar ~
6849 \SpecialChar ~
6850 \SpecialChar ~
6851 \SpecialChar ~
6852 \SpecialChar ~
6853 \SpecialChar ~
6854 \SpecialChar ~
6855  sdcdb-back-from-src\SpecialChar ~
6856 \SpecialChar ~
6857 \SpecialChar ~
6858 \SpecialChar ~
6859 \SpecialChar ~
6860 \SpecialChar ~
6861 \SpecialChar ~
6862 \SpecialChar ~
6863 \SpecialChar ~
6864 \SpecialChar ~
6865 SDCDB back command 
6866 \newline 
6867 ;; c\SpecialChar ~
6868 \SpecialChar ~
6869 \SpecialChar ~
6870 \SpecialChar ~
6871 \SpecialChar ~
6872 \SpecialChar ~
6873 \SpecialChar ~
6874 \SpecialChar ~
6875 \SpecialChar ~
6876 \SpecialChar ~
6877 \SpecialChar ~
6878 \SpecialChar ~
6879 \SpecialChar ~
6880 \SpecialChar ~
6881  sdcdb-cont-from-src\SpecialChar ~
6882 \SpecialChar ~
6883 \SpecialChar ~
6884 \SpecialChar ~
6885 \SpecialChar ~
6886 \SpecialChar ~
6887 \SpecialChar ~
6888 \SpecialChar ~
6889 \SpecialChar ~
6890 \SpecialChar ~
6891 SDCDB continue command
6892 \newline 
6893 ;; s\SpecialChar ~
6894 \SpecialChar ~
6895 \SpecialChar ~
6896 \SpecialChar ~
6897 \SpecialChar ~
6898 \SpecialChar ~
6899 \SpecialChar ~
6900 \SpecialChar ~
6901 \SpecialChar ~
6902 \SpecialChar ~
6903 \SpecialChar ~
6904 \SpecialChar ~
6905 \SpecialChar ~
6906 \SpecialChar ~
6907  sdcdb-step-from-src\SpecialChar ~
6908 \SpecialChar ~
6909 \SpecialChar ~
6910 \SpecialChar ~
6911 \SpecialChar ~
6912 \SpecialChar ~
6913 \SpecialChar ~
6914 \SpecialChar ~
6915 \SpecialChar ~
6916 \SpecialChar ~
6917 SDCDB step command 
6918 \newline 
6919 ;; ?\SpecialChar ~
6920 \SpecialChar ~
6921 \SpecialChar ~
6922 \SpecialChar ~
6923 \SpecialChar ~
6924 \SpecialChar ~
6925 \SpecialChar ~
6926 \SpecialChar ~
6927 \SpecialChar ~
6928 \SpecialChar ~
6929 \SpecialChar ~
6930 \SpecialChar ~
6931 \SpecialChar ~
6932 \SpecialChar ~
6933  sdcdb-whatis-c-sexp\SpecialChar ~
6934 \SpecialChar ~
6935 \SpecialChar ~
6936 \SpecialChar ~
6937 \SpecialChar ~
6938 \SpecialChar ~
6939 \SpecialChar ~
6940 \SpecialChar ~
6941 \SpecialChar ~
6942 \SpecialChar ~
6943 SDCDB ptypecommand for data at 
6944 \newline 
6945 ;;\SpecialChar ~
6946 \SpecialChar ~
6947 \SpecialChar ~
6948 \SpecialChar ~
6949 \SpecialChar ~
6950 \SpecialChar ~
6951 \SpecialChar ~
6952 \SpecialChar ~
6953 \SpecialChar ~
6954 \SpecialChar ~
6955 \SpecialChar ~
6956 \SpecialChar ~
6957 \SpecialChar ~
6958 \SpecialChar ~
6959 \SpecialChar ~
6960 \SpecialChar ~
6961 \SpecialChar ~
6962 \SpecialChar ~
6963 \SpecialChar ~
6964 \SpecialChar ~
6965 \SpecialChar ~
6966 \SpecialChar ~
6967 \SpecialChar ~
6968 \SpecialChar ~
6969 \SpecialChar ~
6970 \SpecialChar ~
6971 \SpecialChar ~
6972 \SpecialChar ~
6973 \SpecialChar ~
6974 \SpecialChar ~
6975 \SpecialChar ~
6976 \SpecialChar ~
6977 \SpecialChar ~
6978 \SpecialChar ~
6979 \SpecialChar ~
6980 \SpecialChar ~
6981 \SpecialChar ~
6982 \SpecialChar ~
6983 \SpecialChar ~
6984 \SpecialChar ~
6985 \SpecialChar ~
6986 \SpecialChar ~
6987 \SpecialChar ~
6988 \SpecialChar ~
6989 \SpecialChar ~
6990 \SpecialChar ~
6991  buffer point 
6992 \newline 
6993 ;; x\SpecialChar ~
6994 \SpecialChar ~
6995 \SpecialChar ~
6996 \SpecialChar ~
6997 \SpecialChar ~
6998 \SpecialChar ~
6999 \SpecialChar ~
7000 \SpecialChar ~
7001 \SpecialChar ~
7002 \SpecialChar ~
7003 \SpecialChar ~
7004 \SpecialChar ~
7005 \SpecialChar ~
7006 \SpecialChar ~
7007  sdcdbsrc-delete\SpecialChar ~
7008 \SpecialChar ~
7009 \SpecialChar ~
7010 \SpecialChar ~
7011 \SpecialChar ~
7012 \SpecialChar ~
7013 \SpecialChar ~
7014 \SpecialChar ~
7015 \SpecialChar ~
7016 \SpecialChar ~
7017 \SpecialChar ~
7018 \SpecialChar ~
7019 \SpecialChar ~
7020 \SpecialChar ~
7021 SDCDB Delete all breakpoints if no arg 
7022 \newline 
7023 ;;\SpecialChar ~
7024 \SpecialChar ~
7025 \SpecialChar ~
7026 \SpecialChar ~
7027 \SpecialChar ~
7028 \SpecialChar ~
7029 \SpecialChar ~
7030 \SpecialChar ~
7031 \SpecialChar ~
7032 \SpecialChar ~
7033 \SpecialChar ~
7034 \SpecialChar ~
7035 \SpecialChar ~
7036 \SpecialChar ~
7037 \SpecialChar ~
7038 \SpecialChar ~
7039 \SpecialChar ~
7040 \SpecialChar ~
7041 \SpecialChar ~
7042 \SpecialChar ~
7043 \SpecialChar ~
7044 \SpecialChar ~
7045 \SpecialChar ~
7046 \SpecialChar ~
7047 \SpecialChar ~
7048 \SpecialChar ~
7049 \SpecialChar ~
7050 \SpecialChar ~
7051 \SpecialChar ~
7052 \SpecialChar ~
7053 \SpecialChar ~
7054 \SpecialChar ~
7055 \SpecialChar ~
7056 \SpecialChar ~
7057 \SpecialChar ~
7058 \SpecialChar ~
7059 \SpecialChar ~
7060 \SpecialChar ~
7061 \SpecialChar ~
7062 \SpecialChar ~
7063 \SpecialChar ~
7064 \SpecialChar ~
7065 \SpecialChar ~
7066 \SpecialChar ~
7067 \SpecialChar ~
7068 \SpecialChar ~
7069 given or delete arg (C-u arg x) 
7070 \newline 
7071 ;; m\SpecialChar ~
7072 \SpecialChar ~
7073 \SpecialChar ~
7074 \SpecialChar ~
7075 \SpecialChar ~
7076 \SpecialChar ~
7077 \SpecialChar ~
7078 \SpecialChar ~
7079 \SpecialChar ~
7080 \SpecialChar ~
7081 \SpecialChar ~
7082 \SpecialChar ~
7083 \SpecialChar ~
7084 \SpecialChar ~
7085  sdcdbsrc-frame\SpecialChar ~
7086 \SpecialChar ~
7087 \SpecialChar ~
7088 \SpecialChar ~
7089 \SpecialChar ~
7090 \SpecialChar ~
7091 \SpecialChar ~
7092 \SpecialChar ~
7093 \SpecialChar ~
7094 \SpecialChar ~
7095 \SpecialChar ~
7096 \SpecialChar ~
7097 \SpecialChar ~
7098 \SpecialChar ~
7099 \SpecialChar ~
7100 SDCDB Display current frame if no arg, 
7101 \newline 
7102 ;;\SpecialChar ~
7103 \SpecialChar ~
7104 \SpecialChar ~
7105 \SpecialChar ~
7106 \SpecialChar ~
7107 \SpecialChar ~
7108 \SpecialChar ~
7109 \SpecialChar ~
7110 \SpecialChar ~
7111 \SpecialChar ~
7112 \SpecialChar ~
7113 \SpecialChar ~
7114 \SpecialChar ~
7115 \SpecialChar ~
7116 \SpecialChar ~
7117 \SpecialChar ~
7118 \SpecialChar ~
7119 \SpecialChar ~
7120 \SpecialChar ~
7121 \SpecialChar ~
7122 \SpecialChar ~
7123 \SpecialChar ~
7124 \SpecialChar ~
7125 \SpecialChar ~
7126 \SpecialChar ~
7127 \SpecialChar ~
7128 \SpecialChar ~
7129 \SpecialChar ~
7130 \SpecialChar ~
7131 \SpecialChar ~
7132 \SpecialChar ~
7133 \SpecialChar ~
7134 \SpecialChar ~
7135 \SpecialChar ~
7136 \SpecialChar ~
7137 \SpecialChar ~
7138 \SpecialChar ~
7139 \SpecialChar ~
7140 \SpecialChar ~
7141 \SpecialChar ~
7142 \SpecialChar ~
7143 \SpecialChar ~
7144 \SpecialChar ~
7145 \SpecialChar ~
7146 \SpecialChar ~
7147 \SpecialChar ~
7148 \SpecialChar ~
7149 given or display frame arg 
7150 \newline 
7151 ;;\SpecialChar ~
7152 \SpecialChar ~
7153 \SpecialChar ~
7154 \SpecialChar ~
7155 \SpecialChar ~
7156 \SpecialChar ~
7157 \SpecialChar ~
7158 \SpecialChar ~
7159 \SpecialChar ~
7160 \SpecialChar ~
7161 \SpecialChar ~
7162 \SpecialChar ~
7163 \SpecialChar ~
7164 \SpecialChar ~
7165 \SpecialChar ~
7166 \SpecialChar ~
7167 \SpecialChar ~
7168 \SpecialChar ~
7169 \SpecialChar ~
7170 \SpecialChar ~
7171 \SpecialChar ~
7172 \SpecialChar ~
7173 \SpecialChar ~
7174 \SpecialChar ~
7175 \SpecialChar ~
7176 \SpecialChar ~
7177 \SpecialChar ~
7178 \SpecialChar ~
7179 \SpecialChar ~
7180 \SpecialChar ~
7181 \SpecialChar ~
7182 \SpecialChar ~
7183 \SpecialChar ~
7184 \SpecialChar ~
7185 \SpecialChar ~
7186 \SpecialChar ~
7187 \SpecialChar ~
7188 \SpecialChar ~
7189 \SpecialChar ~
7190 \SpecialChar ~
7191 \SpecialChar ~
7192 \SpecialChar ~
7193 \SpecialChar ~
7194 \SpecialChar ~
7195 \SpecialChar ~
7196 \SpecialChar ~
7197 \SpecialChar ~
7198 buffer point 
7199 \newline 
7200 ;; !\SpecialChar ~
7201 \SpecialChar ~
7202 \SpecialChar ~
7203 \SpecialChar ~
7204 \SpecialChar ~
7205 \SpecialChar ~
7206 \SpecialChar ~
7207 \SpecialChar ~
7208 \SpecialChar ~
7209 \SpecialChar ~
7210 \SpecialChar ~
7211 \SpecialChar ~
7212 \SpecialChar ~
7213 \SpecialChar ~
7214  sdcdbsrc-goto-sdcdb\SpecialChar ~
7215 \SpecialChar ~
7216 \SpecialChar ~
7217 \SpecialChar ~
7218 \SpecialChar ~
7219 \SpecialChar ~
7220 \SpecialChar ~
7221 \SpecialChar ~
7222 \SpecialChar ~
7223 \SpecialChar ~
7224 Goto the SDCDB output buffer 
7225 \newline 
7226 ;; p\SpecialChar ~
7227 \SpecialChar ~
7228 \SpecialChar ~
7229 \SpecialChar ~
7230 \SpecialChar ~
7231 \SpecialChar ~
7232 \SpecialChar ~
7233 \SpecialChar ~
7234 \SpecialChar ~
7235 \SpecialChar ~
7236 \SpecialChar ~
7237 \SpecialChar ~
7238 \SpecialChar ~
7239 \SpecialChar ~
7240  sdcdb-print-c-sexp\SpecialChar ~
7241 \SpecialChar ~
7242 \SpecialChar ~
7243 \SpecialChar ~
7244 \SpecialChar ~
7245 \SpecialChar ~
7246 \SpecialChar ~
7247 \SpecialChar ~
7248 \SpecialChar ~
7249 \SpecialChar ~
7250 \SpecialChar ~
7251 SDCDB print command for data at 
7252 \newline 
7253 ;;\SpecialChar ~
7254 \SpecialChar ~
7255 \SpecialChar ~
7256 \SpecialChar ~
7257 \SpecialChar ~
7258 \SpecialChar ~
7259 \SpecialChar ~
7260 \SpecialChar ~
7261 \SpecialChar ~
7262 \SpecialChar ~
7263 \SpecialChar ~
7264 \SpecialChar ~
7265 \SpecialChar ~
7266 \SpecialChar ~
7267 \SpecialChar ~
7268 \SpecialChar ~
7269 \SpecialChar ~
7270 \SpecialChar ~
7271 \SpecialChar ~
7272 \SpecialChar ~
7273 \SpecialChar ~
7274 \SpecialChar ~
7275 \SpecialChar ~
7276 \SpecialChar ~
7277 \SpecialChar ~
7278 \SpecialChar ~
7279 \SpecialChar ~
7280 \SpecialChar ~
7281 \SpecialChar ~
7282 \SpecialChar ~
7283 \SpecialChar ~
7284 \SpecialChar ~
7285 \SpecialChar ~
7286 \SpecialChar ~
7287 \SpecialChar ~
7288 \SpecialChar ~
7289 \SpecialChar ~
7290 \SpecialChar ~
7291 \SpecialChar ~
7292 \SpecialChar ~
7293 \SpecialChar ~
7294 \SpecialChar ~
7295 \SpecialChar ~
7296 \SpecialChar ~
7297 \SpecialChar ~
7298 \SpecialChar ~
7299  buffer point 
7300 \newline 
7301 ;; g\SpecialChar ~
7302 \SpecialChar ~
7303 \SpecialChar ~
7304 \SpecialChar ~
7305 \SpecialChar ~
7306 \SpecialChar ~
7307 \SpecialChar ~
7308 \SpecialChar ~
7309 \SpecialChar ~
7310 \SpecialChar ~
7311 \SpecialChar ~
7312 \SpecialChar ~
7313 \SpecialChar ~
7314 \SpecialChar ~
7315  sdcdbsrc-goto-sdcdb\SpecialChar ~
7316 \SpecialChar ~
7317 \SpecialChar ~
7318 \SpecialChar ~
7319 \SpecialChar ~
7320 \SpecialChar ~
7321 \SpecialChar ~
7322 \SpecialChar ~
7323 \SpecialChar ~
7324 \SpecialChar ~
7325 Goto the SDCDB output buffer 
7326 \newline 
7327 ;; t\SpecialChar ~
7328 \SpecialChar ~
7329 \SpecialChar ~
7330 \SpecialChar ~
7331 \SpecialChar ~
7332 \SpecialChar ~
7333 \SpecialChar ~
7334 \SpecialChar ~
7335 \SpecialChar ~
7336 \SpecialChar ~
7337 \SpecialChar ~
7338 \SpecialChar ~
7339 \SpecialChar ~
7340 \SpecialChar ~
7341  sdcdbsrc-mode\SpecialChar ~
7342 \SpecialChar ~
7343 \SpecialChar ~
7344 \SpecialChar ~
7345 \SpecialChar ~
7346 \SpecialChar ~
7347 \SpecialChar ~
7348 \SpecialChar ~
7349 \SpecialChar ~
7350 \SpecialChar ~
7351 \SpecialChar ~
7352 \SpecialChar ~
7353 \SpecialChar ~
7354 \SpecialChar ~
7355 \SpecialChar ~
7356 \SpecialChar ~
7357 Toggles Sdcdbsrc mode (turns it off) 
7358 \newline 
7359 ;; 
7360 \newline 
7361 ;; C-c C-f\SpecialChar ~
7362 \SpecialChar ~
7363 \SpecialChar ~
7364 \SpecialChar ~
7365 \SpecialChar ~
7366 \SpecialChar ~
7367 \SpecialChar ~
7368 \SpecialChar ~
7369  sdcdb-finish-from-src\SpecialChar ~
7370 \SpecialChar ~
7371 \SpecialChar ~
7372 \SpecialChar ~
7373 \SpecialChar ~
7374 \SpecialChar ~
7375 \SpecialChar ~
7376 \SpecialChar ~
7377 SDCDB finish command 
7378 \newline 
7379 ;; 
7380 \newline 
7381 ;; C-x SPC\SpecialChar ~
7382 \SpecialChar ~
7383 \SpecialChar ~
7384 \SpecialChar ~
7385 \SpecialChar ~
7386 \SpecialChar ~
7387 \SpecialChar ~
7388 \SpecialChar ~
7389  sdcdb-break\SpecialChar ~
7390 \SpecialChar ~
7391 \SpecialChar ~
7392 \SpecialChar ~
7393 \SpecialChar ~
7394 \SpecialChar ~
7395 \SpecialChar ~
7396 \SpecialChar ~
7397 \SpecialChar ~
7398 \SpecialChar ~
7399 \SpecialChar ~
7400 \SpecialChar ~
7401 \SpecialChar ~
7402 \SpecialChar ~
7403 \SpecialChar ~
7404 \SpecialChar ~
7405 \SpecialChar ~
7406 \SpecialChar ~
7407 Set break for line with point 
7408 \newline 
7409 ;; ESC t\SpecialChar ~
7410 \SpecialChar ~
7411 \SpecialChar ~
7412 \SpecialChar ~
7413 \SpecialChar ~
7414 \SpecialChar ~
7415 \SpecialChar ~
7416 \SpecialChar ~
7417 \SpecialChar ~
7418 \SpecialChar ~
7419  sdcdbsrc-mode\SpecialChar ~
7420 \SpecialChar ~
7421 \SpecialChar ~
7422 \SpecialChar ~
7423 \SpecialChar ~
7424 \SpecialChar ~
7425 \SpecialChar ~
7426 \SpecialChar ~
7427 \SpecialChar ~
7428 \SpecialChar ~
7429 \SpecialChar ~
7430 \SpecialChar ~
7431 \SpecialChar ~
7432 \SpecialChar ~
7433 \SpecialChar ~
7434 \SpecialChar ~
7435 Toggle Sdcdbsrc mode 
7436 \newline 
7437 ;; ESC m\SpecialChar ~
7438 \SpecialChar ~
7439 \SpecialChar ~
7440 \SpecialChar ~
7441 \SpecialChar ~
7442 \SpecialChar ~
7443 \SpecialChar ~
7444 \SpecialChar ~
7445 \SpecialChar ~
7446 \SpecialChar ~
7447  sdcdbsrc-srcmode\SpecialChar ~
7448 \SpecialChar ~
7449 \SpecialChar ~
7450 \SpecialChar ~
7451 \SpecialChar ~
7452 \SpecialChar ~
7453 \SpecialChar ~
7454 \SpecialChar ~
7455 \SpecialChar ~
7456 \SpecialChar ~
7457 \SpecialChar ~
7458 \SpecialChar ~
7459  Toggle list mode 
7460 \newline 
7461 ;; 
7462 \family default 
7463
7464 \newline 
7465
7466 \layout Section
7467
7468 Other Processors
7469 \layout Subsection
7470
7471 The Z80 and gbz80 port
7472 \layout Standard
7473
7474 SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
7475  The port is incomplete - long support is incomplete (mul, div and mod are
7476  unimplimented), and both float and bitfield support is missing.
7477  Apart from that the code generated is correct.
7478 \layout Standard
7479
7480 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
7481  The stack frame is similar to that generated by the IAR Z80 compiler.
7482  IX is used as the base pointer, HL is used as a temporary register, and
7483  BC and DE are available for holding varibles.
7484  IY is currently unusued.
7485  Return values are stored in HL.
7486  One bad side effect of using IX as the base pointer is that a functions
7487  stack frame is limited to 127 bytes - this will be fixed in a later version.
7488 \layout Section
7489
7490 Support
7491 \layout Standard
7492
7493 SDCC has grown to be a large project.
7494  The compiler alone (without the preprocessor, assembler and linker) is
7495  about 40,000 lines of code (blank stripped).
7496  The open source nature of this project is a key to its continued growth
7497  and support.
7498  You gain the benefit and support of many active software developers and
7499  end users.
7500  Is SDCC perfect? No, that's why we need your help.
7501  The developers take pride in fixing reported bugs.
7502  You can help by reporting the bugs and helping other SDCC users.
7503  There are lots of ways to contribute, and we encourage you to take part
7504  in making SDCC a great software package.
7505 \layout Subsection
7506
7507 Reporting Bugs
7508 \layout Standard
7509
7510 Send an email to the mailing list at 'user-sdcc@sdcc.sourceforge.net' or 'devel-sd
7511 cc@sdcc.sourceforge.net'.
7512  Bugs will be fixed ASAP.
7513  When reporting a bug, it is very useful to include a small test program
7514  which reproduces the problem.
7515  If you can isolate the problem by looking at the generated assembly code,
7516  this can be very helpful.
7517  Compiling your program with the --dumpall option can sometimes be useful
7518  in locating optimization problems.
7519 \layout Section
7520
7521 Acknowledgments
7522 \layout Standard
7523
7524 Sandeep Dutta (sandeep.dutta@usa.net) - SDCC, the compiler, MCS51 code generator,
7525  Debugger, AVR port
7526 \newline 
7527 Alan Baldwin (baldwin@shop-pdp.kent.edu) - Initial version of ASXXXX & ASLINK.
7528  
7529 \newline 
7530 John Hartman (jhartman@compuserve.com) - Porting ASXXX & ASLINK for 8051
7531 \newline 
7532 Dmitry S.
7533  Obukhov (dso@usa.net) - malloc & serial i/o routines.
7534  
7535 \newline 
7536 Daniel Drotos (drdani@mazsola.iit.uni-miskolc.hu) - for his Freeware simulator
7537 \newline 
7538 Malini Dutta(malini_dutta@hotmail.com) - my wife for her patience and support.
7539 \newline 
7540 Unknown - for the GNU C - preprocessor.
7541 \newline 
7542 Michael Hope - The Z80 and Z80GB port, 186 development
7543 \newline 
7544 Kevin Vigor - The DS390 port.
7545 \newline 
7546 Johan Knol - Lots of fixes and enhancements, DS390/TINI libs.
7547 \newline 
7548 Scott Datallo - The PIC port.
7549 \newline 
7550
7551 \newline 
7552
7553 \emph on 
7554 Thanks to all the other volunteer developers who have helped with coding,
7555  testing, web-page creation, distribution sets, etc.
7556  You know who you are :-)
7557 \emph default 
7558
7559 \newline 
7560
7561 \layout Standard
7562
7563 This document was initially written by Sandeep Dutta
7564 \layout Standard
7565
7566 All product names mentioned herein may be trademarks of their respective
7567  companies.
7568  
7569 \layout Standard
7570
7571
7572 \begin_inset LatexCommand \printindex{}
7573
7574 \end_inset 
7575
7576
7577 \the_end