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