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