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