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