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