From: johanknol Date: Sat, 7 Jul 2001 14:50:27 +0000 (+0000) Subject: Updated documentation X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=174be3f2a74835628619ec5ee88fb5a6fef741eb;p=fw%2Fsdcc Updated documentation git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1040 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/doc/SDCCUdoc.html b/doc/SDCCUdoc.html index 408a772c..86a06743 100644 --- a/doc/SDCCUdoc.html +++ b/doc/SDCCUdoc.html @@ -1,20 +1,20 @@ - -lSDCC Compiler User Guide - +SDCC Compiler User Guide + - + @@ -23,12 +23,12 @@ original version by: Nikos Drakos, CBLU, University of Leeds -next_inactive +next_group up + SRC="/home/johan/latex2html/icons.gif/up_motif_gr.gif"> previous + SRC="/home/johan/latex2html/icons.gif/previous_motif_gr.gif">


@@ -37,7 +37,8 @@ original version by: Nikos Drakos, CBLU, University of Leeds

-

lSDCC Compiler User Guide

+ +

SDCC Compiler User Guide


@@ -46,152 +47,151 @@ Contents

-<pending: tabularise these features, this is unreadeble> -
-
SDCC is a Free ware, retargettable, optimizing ANSI-C compiler + +SDCC is a Freeware, retargettable, optimizing ANSI-C compiler by Sandeep Dutta designed for 8 bit Microprocessors. The current version targets Intel MCS51 based Microprocessors(8051,8052, -etc), Zilog Z80 based MCUs, and the Dallas 80C390 MCS51 variant. It -can be retargetted for other microprocessors, support for PIC, AVR -and 186 is under development. The entire source code for the compiler +etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant. It can +be retargetted for other microprocessors, support for PIC, AVR and +186 is under development. The entire source code for the compiler is distributed under GPL. SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker. SDCC has extensive language extensions -suitable for utilizing various microcontrollers underlying hardware -effectively. In addition to the MCU specific optimizations SDCC also -does a host of standard optimizations like global sub expression -elimination, loop optimizations (loop invariant, strength reduction -of induction variables and loop reversing), constant folding & propagation, -copy propagation, dead code elimination and jumptables for 'switch' -statements. For the back-end SDCC uses a global register allocation -scheme which should be well suited for other 8 bit MCUs. The peep -hole optimizer uses a rule based substitution mechanism which is MCU -dependent. Supported data-types are char (8 bits, 1 byte), short -and int (16 bits, 2 bytes), long (32 bit, 4 bytes) and float -(4 byte IEEE). The compiler also allows inline assembler code -to be embedded anywhere in a function. In addition routines developed -in assembly can also be called. SDCC also provides an option to report -the relative complexity of a function, these functions can then be -further optimized, or hand coded in assembly if needed. SDCC also -comes with a companion source level debugger SDCDB, the debugger currently -uses ucSim a freeware simulator for 8051 and other micro-controllers. -The latest version can be downloaded from http://sdcc.sourceforge.net/ -. +suitable for utilizing various microcontrollers and underlying hardware +effectively. +
+ +
+In addition to the MCU specific optimizations SDCC also does a host +of standard optimizations like: + +

+ +

+For the back-end SDCC uses a global register allocation scheme which +should be well suited for other 8 bit MCUs. +
+ +
+The peep hole optimizer uses a rule based substitution mechanism which +is MCU independent. +
+ +
+Supported data-types are: + +

+ +

+The compiler also allows inline assembler code to be embedded +anywhere in a function. In addition, routines developed in assembly +can also be called. +
+ +
+SDCC also provides an option (-cyclomatic) to report the relative +complexity of a function. These functions can then be further optimized, +or hand coded in assembly if needed. +
+ +
+SDCC also comes with a companion source level debugger SDCDB, the +debugger currently uses ucSim a freeware simulator for 8051 and other +micro-controllers. +
+ +
+The latest version can be downloaded from http://sdcc.sourceforge.net/.

@@ -258,8 +295,6 @@ if not, write to the Free Software Foundation, 59 Temple Place - Suite use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! -
-
<pending: add a link to gnu>

@@ -277,28 +312,36 @@ type.

-1.4 Pending: compatibilaty with previous versions +1.4 Compatibility with previous versions

-This version has numerous bug fixes comperated with the previous version. -But we also introduced some incompatibilaties with older versions. +This version has numerous bug fixes compared with the previous version. +But we also introduced some incompatibilities with older versions. Not just for the fun of it, but to make the compiler more stable, efficient and ANSI compliant.
+ +

+ +

+<pending: more incompatibilities?>

@@ -309,7 +352,7 @@ more?

What do you need before you start installation of SDCC? A computer, and a desire to compute. The preferred method of installation is to -compile SDCC from source using GNU GCC and make. For Windows some +compile SDCC from source using GNU gcc and make. For Windows some pre-compiled binary distributions are available for your convenience. You should have some experience with command line tools and compiler use. @@ -321,7 +364,7 @@ use.

-The SDCC home page at http://sdcc.sourceforge.net/ is a great +The SDCC home page at http://sdcc.sourceforge.net/ is a great place to find distribution sets. You can also find links to the user mailing lists that offer help or discuss SDCC with other SDCC users. Web links to other SDCC related sites can also be found here. This @@ -334,8 +377,36 @@ on cvs.sdcc.sourceforge.net.

+

+1.7 Wishes for the future +

+ +

+There are (and always will be) some things that could be done. Here +are some I can think of: +
+ +

+ +sdcc -c -model-large -o large _atoi.c (where large +could be a different basename or a directory) +
+ +

+ +char KernelFunction3(char p) at 0x340;  +
  +
+If you can think of some more, please send them to the list. +
+ +
+<pending: And then of course a proper index-table> + +

+

-2 Installation +2. Installation

@@ -347,26 +418,20 @@ on cvs.sdcc.sourceforge.net.

    -
  1. Download the source package, it will be named something like sdcc-2.x.x.tgz. -
  2. -
  3. Bring up a command line terminal, such as xterm. -
  4. +
  5. Download the source package, it will be named something like sdcc-2.x.x.tgz.
  6. +
  7. Bring up a command line terminal, such as xterm.
  8. Unpack the file using a command like: "tar --xzf sdcc-2.x.x.tgz", this will create a sub-directory -called sdcc with all of the sources. -
  9. +-xzf sdcc-2.x.x.tgz", this will create a sub-directory +called sdcc with all of the sources.
  10. Change directory into the main SDCC directory, for example type: "cd -sdcc". -
  11. -
  12. Type "./configure". This configures -the package for compilation on your system. -
  13. -
  14. Type "make". All of the source -packages will compile, this can take a while. -
  15. +sdcc". +
  16. Type "./configure". This configures +the package for compilation on your system.
  17. +
  18. Type "make". All of the source +packages will compile, this can take a while.
  19. Type "make install" as root. This -copies the binary executables to the install directories. -
  20. +copies the binary executables, the include files, the libraries and +the documentation to the install directories.

@@ -376,6 +441,7 @@ copies the binary executables to the install directories.

+ <pending: is this complete? where is borland, mingw>

@@ -402,16 +468,13 @@ tool (gunzip, WinZip, etc). This should unpack to a group of sub-directories. An example directory structure after unpacking is: c:\usr\local\bin for the executables, c:\usr\local\share\sdcc\include and c:\usr\local\share\sdcc\lib -for the include and libraries. - +for the include and libraries.

  • Adjust your environment PATH to include the location of the bin directory. -For example, make a setsdcc.bat file with the following: set PATH=c:\usr\local\bin;%PATH% -
  • +For example, make a setsdcc.bat file with the following: set PATH=c:\usr\local\bin;%PATH%
  • When you compile with sdcc, you may need to specify the location of the lib and include folders. For example, sdcc -I c:\usr\local\share\sdcc\include -L c:\usr\local\share\sdcc\lib\small -test.c -
  • +test.c

    @@ -423,15 +486,12 @@ test.c

      -
    1. Download and install the cygwin package from the redhat sitehttp://sources.redhat.com/cygwin/. +
    2. Download and install the cygwin package from the redhat site http://sources.redhat.com/cygwin/. Currently, this involved downloading a small install program which then automates downloading and installing selected parts of the package -(a large 80M byte sized dowload for the whole thing). -
    3. -
    4. Bring up a Unix/Bash command line terminal from the Cygwin menu. -
    5. -
    6. Follow the instructions in the preceding Linux/Unix installation section. -
    7. +(a large 80M byte sized dowload for the whole thing). +
    8. Bring up a Unix/Bash command line terminal from the Cygwin menu.
    9. +
    10. Follow the instructions in the preceding Linux/Unix installation section.

    @@ -451,11 +511,13 @@ PATH environment setting (see the Trouble-shooting section for suggestions). Make sure that the sdcc program is in the bin folder, if not perhaps something did not install correctly.
    +
    SDCC binaries are commonly installed in a directory arrangement like this:
    -

    + +
    @@ -468,35 +530,50 @@ this:
    /usr/local/bin Holds executables(sdcc, s51, aslink, ...)

    +
    Make sure the compiler works on a very simple example. Type in the following test.c program using your favorite editor:

    +int test(int t) {  +
    +    return t+3;  +
    +} +
    +
    Compile this using the following command: "sdcc --c test.c" If all goes well, the compiler will generate +-c test.c". If all goes well, the compiler will generate a test.asm and test.rel file. Congratulations, you've just compiled your first program with SDCC. We used the -c option to tell SDCC not to link the generated code, just to keep things simple for this step.
    +
    The next step is to try it with the linker. Type in "sdcc -test.c". If all goes well the compiler will link with the +test.c". If all goes well the compiler will link with the libraries and produce a test.ihx output file. If this step fails (no test.ihx, and the linker generates warnings), then the problem is most likely that sdcc cannot find the /usr/local/share/sdcc/lib directory (see the Install trouble-shooting section for suggestions).
    +
    The final test is to ensure sdcc can use the standard header files and libraries. Edit test.c and change it to the following:
    -
    #include <string.h> + +
    +#include <string.h>
    main() { -
    char str1[10];  -
        strcpy(str1, "testing");  -
    }  +
    +char str1[10];  +
    +    strcpy(str1, "testing");  +
    +} 
     
    Compile this by typing "sdcc test.c". @@ -533,8 +610,11 @@ this: "sdcc -L /usr/local/sdcc/lib/small -I /usr/l A thing to try is starting from scratch by unpacking the .tgz source package again in an empty directory. Confure it again and build like:
    -
    make 2SPMamp;>1 | tee make.log + +
    +make 2SPMamp;>1 | tee make.log
    +
    After this you can review the make.log file to locate the problem. Or a relevant part of this be attached to an email that could be helpful @@ -581,6 +661,7 @@ executables to /usr/local/bin and the libraries and header files to

    + <pending: is this up to date?>

    @@ -660,12 +741,10 @@ the Borland 32-bit compiler you would run "make

    @@ -682,6 +761,7 @@ location is /usr/local). The installation process will create the following directory structure under the <directory name> specified (if they do not already exist).
    +
    bin/ - binary exectables (add to PATH environment variable)
    @@ -699,9 +779,10 @@ library
    bin/share/sdcc/lib/ds390/ - Object & library files forDS80C390 library
    +
    The command ''./configure -prefix=/usr/local'' -will configure the compiler to be installed in directory /usr/local/bin. +will configure the compiler to be installed in directory /usr/local.

    @@ -718,25 +799,51 @@ you can find in the source package in their respective directories. As SDCC grows to include support for other processors, other packages from various developers are included and may have their own sets of documentation. - -

    -You might want to look at the various executables which are installed -in the bin directory. At the time of this writing, we find the following -programs:
    -
    <pending: tabularize this> +
    -
    sdcc - The compiler. -
    sdcpp - The C preprocessor. -
    asx8051 - The assembler for 8051 type processors. -
    as-z80, as-gbz80 - The Z80 and GameBoy Z80 assemblers. -
    aslink -The linker for 8051 type processors. -
    link-z80, link-gbz80 - The Z80 and GameBoy Z80 linkers. -
    s51 - The ucSim 8051 simulator. -
    sdcdb - The source debugger. -
    packihx - A tool to pack Intel hex files. +You might want to look at the files which are installed in <installdir>. +At the time of this writing, we find the following programs:
    +
    +In <installdir>/bin: + +

    + +

      +
    • sdcc - The compiler.
    • +
    • sdcpp - The C preprocessor.
    • +
    • asx8051 - The assembler for 8051 type processors.
    • +
    • as-z80, as-gbz80 - The Z80 and GameBoy Z80 assemblers.
    • +
    • aslink -The linker for 8051 type processors.
    • +
    • link-z80, link-gbz80 - The Z80 and GameBoy Z80 linkers.
    • +
    • s51 - The ucSim 8051 simulator.
    • +
    • sdcdb - The source debugger.
    • +
    • packihx - A tool to pack Intel hex files.
    • +
    +In <installdir>/share/sdcc/include + +

    + +

      +
    • the include files
    • +
    +In <installdir>/share/sdcc/lib + +

    + +

      +
    • the sources of the runtime library and the subdirs small large and +ds390 with the precompiled relocatables.
    • +
    +In <installdir>/share/sdcc/doc + +

    + +

      +
    • the documentation
    • +
    As development for other processors proceeds, this list will expand to include executables to support processors like AVR, PIC, etc. @@ -782,9 +889,9 @@ properly with the SDCC.

    S51 is a freeware, opensource simulator developed by Daniel Drotos -(mailto:drdani@mazsola.iit.uni-miskolc.hu). The simulator is +( mailto:drdani@mazsola.iit.uni-miskolc.hu). The simulator is built as part of the build process. For more information visit Daniel's -website at: http://mazsola.iit.uni-miskolc.hu/ drdani/embedded/s51 +website at: http://mazsola.iit.uni-miskolc.hu/ drdani/embedded/s51 .

    @@ -801,7 +908,7 @@ to use other simulators.

    -3 Using SDCC +3. Using SDCC

    @@ -822,6 +929,7 @@ your programs with the following command "sdcc sourcefile.c". This will compile, assemble and link your source file. Output files are as follows
    +
    sourcefile.asm - Assembler source file created by the compiler
    @@ -845,6 +953,7 @@ the Motorola S19 format with -out-fmt-s19) sourcefile.cdb - An optional file (with -debug) containing debug information
    +

    @@ -855,6 +964,7 @@ information SDCC can compile only ONE file at a time. Let us for example assume that you have a project containing the following files:
    +
    foo1.c (contains some functions)
    @@ -862,24 +972,34 @@ foo2.c (contains some more functions)
    foomain.c (contains more functions and the function main)
    +
    The first two files will need to be compiled separately with the commands:
    -
    sdcc -c foo1.c -
    sdcc -c foo2.c + +
    +sdcc -c foo1.c +
    +sdcc -c foo2.c
    +
    Then compile the source file containing the main() function and link the files together with the following command:
    -
    sdcc foomain.c foo1.rel foo2.rel + +
    +sdcc foomain.c foo1.rel foo2.rel
    +
    Alternatively, foomain.c can be separately compiled as well:
    -
    sdcc -c foomain.c -
    sdcc foomain.rel foo1.rel foo2.rel +
    +sdcc -c foomain.c +
    +sdcc foomain.rel foo1.rel foo2.rel

    The file containing the main() function MUST @@ -903,11 +1023,14 @@ assuming you have the source file foomain.c and a library foolib.libmylib (if that is not the same as your current project):
    -
    sdcc foomain.c foolib.lib -L mylib + +
    +sdcc foomain.c foolib.lib -L mylib

    Note here that mylib must be an absolute path name.
    +
    The most efficient way to use libraries is to keep seperate modules in seperate source files. The lib file now should name all the modules.rel @@ -930,23 +1053,16 @@ in the directory <installdir>/share/lib/small.
    • [-mmcs51]Generate code for the MCS51 (8051) family of processors. -This is the default processor target. -
    • -
    • [-mds390]Generate code for the DS80C390 processor. -
    • -
    • [-mz80]Generate code for the Z80 family of processors. -
    • -
    • [-mgbz80]Generate code for the GameBoy Z80 processor. -
    • +This is the default processor target. +
    • [-mds390]Generate code for the DS80C390 processor.
    • +
    • [-mz80]Generate code for the Z80 family of processors.
    • +
    • [-mgbz80]Generate code for the GameBoy Z80 processor.
    • [-mavr]Generate code for the Atmel AVR processor(In development, -not complete). -
    • +not complete).
    • [-mpic14]Generate code for the PIC 14-bit processors(In development, -not complete). -
    • +not complete).
    • [-mtlcs900h]Generate code for the Toshiba TLCS-900H processor(In -development, not complete). -
    • +development, not complete).

    @@ -958,11 +1074,9 @@ development, not complete).

    • [-I<path>]The additional location where the pre processor -will look for <..h> or ``..h'' files. -
    • +will look for <..h> or ``..h'' files.
    • [-D<macro[=value]>]Command line definition of macros. -Passed to the pre processor. -
    • +Passed to the pre processor.
    • [-M]Tell the preprocessor to output a rule suitable for make describing the dependencies of each object file. For each source file, the preprocessor outputs one make-rule whose target is the object @@ -970,38 +1084,29 @@ file name for that source file and whose dependencies are all the files `#include'd in it. This rule may be a single line or may be continued with `\'-newline if it is long. The list of rules is printed on standard output instead of the preprocessed -C program. `-M' implies `-E'. -
    • +C program. `-M' implies `-E'.
    • [-C]Tell the preprocessor not to discard comments. Used with -the `-E' option. -
    • +the `-E' option.
    • [-MM]Like `-M' but the output mentions only the user header files included with `#include ``file"'. System header -files included with `#include <file>' are omitted. -
    • +files included with `#include <file>' are omitted.
    • [-Aquestion(answer)]Assert the answer answer for question, in case it is tested with a preprocessor conditional such as `#if #question(answer)'. `-A-' disables the standard assertions that normally -describe the target machine. -
    • +describe the target machine.
    • [-Aquestion](answer) Assert the answer answer for question, in case it is tested with a preprocessor conditional such as `#if #question(answer)'. `-A-' disables the standard assertions that normally -describe the target machine. -
    • +describe the target machine.
    • [-Umacro]Undefine macro macro. `-U' options are evaluated -after all `-D' options, but before any `-include' and `-imacros' options. -
    • +after all `-D' options, but before any `-include' and `-imacros' options.
    • [-dM]Tell the preprocessor to output only a list of the macro definitions that are in effect at the end of preprocessing. Used with -the `-E' option. -
    • +the `-E' option.
    • [-dD]Tell the preprocessor to pass all macro definitions -into the output, in their proper sequence in the rest of the output. -
    • +into the output, in their proper sequence in the rest of the output.
    • [-dN]Like `-dD' except that the macro arguments and contents -are omitted. Only `#define name' is included in the output. -
    • +are omitted. Only `#define name' is included in the output.

    @@ -1016,18 +1121,15 @@ are omitted. Only `#define name' is included in the output. option is passed to the linkage editor's additional libraries search path. The path name must be absolute. Additional library files may be specified in the command line. See section Compiling programs for -more details. - +more details.

  • [-xram-loc<Value>]The start location of the external ram, default value is 0. The value entered can be in Hexadecimal or Decimal -format, e.g.: -xram-loc 0x8000 or -xram-loc 32768. -
  • +format, e.g.: -xram-loc 0x8000 or -xram-loc 32768.
  • [-code-loc<Value>]The start location of the code segment, default value 0. Note when this option is used the interrupt vector table is also relocated to the given address. The value entered can be in Hexadecimal or Decimal format, e.g.: -code-loc 0x8000 or -code-loc -32768. -
  • +32768.
  • [-stack-loc<Value>]The initial value of the stack pointer. The default value of the stack pointer is 0x07 if only register bank 0 is used, if other register banks are used then the stack pointer @@ -1036,26 +1138,20 @@ eg. if register banks 1 & 2 are used the stack pointer will default to location 0x18. The value entered can be in Hexadecimal or Decimal format, eg. -stack-loc 0x20 or -stack-loc 32. If all four register banks are used the stack will be placed after the data segment (equivalent -to -stack-after-data) -
  • +to -stack-after-data)
  • [-stack-after-data]This option will cause the stack to be -located in the internal ram after the data segment. -
  • +located in the internal ram after the data segment.
  • [-data-loc<Value>]The start location of the internal ram data segment, the default value is 0x30.The value entered can be in -Hexadecimal or Decimal format, eg. -data-loc 0x20 or -data-loc 32. -
  • +Hexadecimal or Decimal format, eg. -data-loc 0x20 or -data-loc 32.
  • [-idata-loc<Value>]The start location of the indirectly addressable internal ram, default value is 0x80. The value entered can be in Hexadecimal or Decimal format, eg. -idata-loc 0x88 or -idata-loc -136. -
  • +136.
  • [-out-fmt-ihx]The linker output (final object code) is in -Intel Hex format. (This is the default option). -
  • +Intel Hex format. (This is the default option).
  • [-out-fmt-s19]The linker output (final object code) is in -Motorola S19 format. -
  • +Motorola S19 format.

    @@ -1070,11 +1166,9 @@ Motorola S19 format. section Memory Models for more details. If this option is used all source files in the project should be compiled with this option. In addition the standard library routines are compiled with small model, -they will need to be recompiled. - +they will need to be recompiled.

  • [-model-small]Generate code for Small Model programs see -section Memory Models for more details. This is the default model. -
  • +section Memory Models for more details. This is the default model.

    @@ -1088,8 +1182,7 @@ section Memory Models for more details. This is the default model.

  • [-model-flat24]Generate 24-bit flat mode code. This is the one and only that the ds390 code generator supports right now and is default when using -mds390. See section Memory Models for -more details. -
  • +more details.
  • [-stack-10bit]Generate code for the 10 bit stack mode of the Dallas DS80C390 part. This is the one and only that the ds390 code generator supports right now and is default when using -mds390. @@ -1105,8 +1198,7 @@ mode before calling any re-entrant functions compiled with this option. In principle, this should work with the -stack-auto option, but that has not been tested. It is incompatible with the -xstack option. It also only makes sense if the processor is in 24 bit contiguous -addressing mode (see the -model-flat24 option). -
  • +addressing mode (see the -model-flat24 option).

    @@ -1123,28 +1215,23 @@ spaces to store compiler temporaries. A warning message will be generated when this happens and the compiler will indicate the number of extra bytes it allocated. It recommended that this option NOT be used, #pragma NOGCSE can be used to turn off global subexpression elimination for a given -function only. - +function only.

  • [-noinvariant]Will not do loop invariant optimizations, this may be turned off for reasons explained for the previous option. For more details of loop optimizations performed see section Loop Invariants.It recommended that this option NOT be used, #pragma NOINVARIANT can be used to turn off invariant optimizations for a given function -only. -
  • +only.
  • [-noinduction]Will not do loop induction optimizations, see section strength reduction for more details.It is recommended that this option is NOT used, #pragma NOINDUCTION can be used to -turn off induction optimizations for a given function only. -
  • +turn off induction optimizations for a given function only.
  • [-nojtbound] Will not generate boundary condition check when switch statements are implemented using jump-tables. See section Switch Statements for more details. It is recommended that this option is NOT used, #pragma NOJTBOUND can be used to turn off boundary -checking for jump tables for a given function only. -
  • -
  • [-noloopreverse]Will not do loop reversal optimization. -
  • +checking for jump tables for a given function only. +
  • [-noloopreverse]Will not do loop reversal optimization.
  • @@ -1156,21 +1243,17 @@ checking for jump tables for a given function only.

    • [-c -compile-only]will compile and assemble the source, -but will not call the linkage editor. -
    • +but will not call the linkage editor.
    • [-E]Run only the C preprocessor. Preprocess all the C source -files specified and output the results to standard output. -
    • +files specified and output the results to standard output.
    • [-stack-auto]All functions in the source file will be compiled as reentrant, i.e. the parameters and local variables will be allocated on the stack. see section Parameters and Local Variables for more details. If this option is used all source files in the project -should be compiled with this option. -
    • +should be compiled with this option.
    • [-xstack]Uses a pseudo stack in the first 256 bytes in the external ram for allocating variables and passing parameters. See -section on external stack for more details. -
    • +section on external stack for more details.
    • [-callee-saves]function1[,function2][,function3].... The compiler by default uses a caller saves convention for register saving across function calls, however this can cause unneccessary @@ -1187,75 +1270,55 @@ functions such as _muluint..., if this option is used for a library function the appropriate library function needs to be recompiled with the same option. If the project consists of multiple source files then all the source file should be compiled with the same -callee-saves -option string. Also see #pragma CALLEE-SAVES. -
    • +option string. Also see #pragma CALLEE-SAVES.
    • [-debug]When this option is used the compiler will generate debug information, that can be used with the SDCDB. The debug information is collected in a file with .cdb extension. For more information see -documentation for SDCDB. -
    • +documentation for SDCDB.
    • [-regextend] This option is obsolete and isn't -supported anymore. -
    • +supported anymore.
    • [-noregparms]This option is obsolete and isn't -supported anymore. -
    • +supported anymore.
    • [-peep-file<filename>]This option can be used to use additional rules to be used by the peep hole optimizer. See section Peep Hole -optimizations for details on how to write these rules. -
    • +optimizations for details on how to write these rules.
    • [-S]Stop after the stage of compilation proper; do not assemble. -The output is an assembler code file for the input file specified. -
    • +The output is an assembler code file for the input file specified.
    • [-Wa_asmOption[,asmOption]...]Pass the asmOption to -the assembler. -
    • +the assembler.
    • [-Wl_linkOption[,linkOption]...]Pass the linkOption -to the linker. -
    • +to the linker.
    • [-int-long-reent] Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant. Note by default these libraries are -compiled as non-reentrant. See section Installation for more details. -
    • +compiled as non-reentrant. See section Installation for more details.
    • [-cyclomatic]This option will cause the compiler to generate an information message for each function in the source file. The message contains some important information about the function. The number of edges and nodes the compiler detected in the control flow graph of the function, and most importantly the cyclomatic complexity -see section on Cyclomatic Complexity for more details. -
    • +see section on Cyclomatic Complexity for more details.
    • [-float-reent] Floating point library is compiled as reentrant.See -section Installation for more details. -
    • +section Installation for more details.
    • [-nooverlay] The compiler will not overlay parameters and local variables of any function, see section Parameters and local -variables for more details. -
    • +variables for more details.
    • [-main-return]This option can be used when the code generated is called by a monitor program. The compiler will generate a 'ret' upon return from the 'main' function. The default option is to lock -up i.e. generate a 'ljmp '. -
    • -
    • [-no-peep] Disable peep-hole optimization. -
    • +up i.e. generate a 'ljmp '. +
    • [-no-peep] Disable peep-hole optimization.
    • [-peep-asm] Pass the inline assembler code through the peep hole optimizer. This can cause unexpected changes to inline assembler code, please go through the peephole optimizer rules defined in the -source file tree '<target>/peeph.def' before using this option. -
    • +source file tree '<target>/peeph.def' before using this option.
    • [-iram-size<Value>]Causes the linker to check if the interal -ram usage is within limits of the given value. -
    • +ram usage is within limits of the given value.
    • [-nostdincl]This will prevent the compiler from passing -on the default include path to the preprocessor. -
    • +on the default include path to the preprocessor.
    • [-nostdlib]This will prevent the compiler from passing on -the default library path to the linker. -
    • -
    • [-verbose]Shows the various actions the compiler is performing. -
    • -
    • [-V]Shows the actual commands the compiler is executing. -
    • +the default library path to the linker. +
    • [-verbose]Shows the various actions the compiler is performing.
    • +
    • [-V]Shows the actual commands the compiler is executing.

    @@ -1277,30 +1340,21 @@ intermediate code into a file of named <source filename>.dumpraw just after the intermediate code has been generated for a function, i.e. before any optimizations are done. The basic blocks at this stage ordered in the depth first number, so they may not be in sequence -of execution. - +of execution.

  • [-dumpgcse]Will create a dump of iCode's, after global subexpression -elimination, into a file named <source filename>.dumpgcse. -
  • +elimination, into a file named <source filename>.dumpgcse.
  • [-dumpdeadcode]Will create a dump of iCode's, after deadcode -elimination, into a file named <source filename>.dumpdeadcode. -
  • +elimination, into a file named <source filename>.dumpdeadcode.
  • [-dumploop]Will create a dump of iCode's, after loop optimizations, -into a file named <source filename>.dumploop. -
  • +into a file named <source filename>.dumploop.
  • [-dumprange]Will create a dump of iCode's, after live range -analysis, into a file named <source filename>.dumprange. -
  • -
  • [-dumlrange]Will dump the life ranges for all symbols. -
  • +analysis, into a file named <source filename>.dumprange. +
  • [-dumlrange]Will dump the life ranges for all symbols.
  • [-dumpregassign]Will create a dump of iCode's, after register -assignment, into a file named <source filename>.dumprassgn. -
  • -
  • [-dumplrange]Will create a dump of the live ranges of iTemp's -
  • +assignment, into a file named <source filename>.dumprassgn. +
  • [-dumplrange]Will create a dump of the live ranges of iTemp's
  • [-dumpall]Will cause all the above mentioned dumps to be -created. -
  • +created.

    @@ -1323,7 +1377,9 @@ Variables declared with this storage class will be placed in the extern RAM. This is the default storage class for Large Memory model, e.g.:
    -
    xdata unsigned char xduc; + +
    +xdata unsigned char xduc;

    @@ -1336,7 +1392,9 @@ This is the default storage class for Small Memory model. Variables declared with this storage class will be allocated in the internal RAM, e.g.:
    -
    data int iramdata; + +
    +data int iramdata;

    @@ -1349,7 +1407,9 @@ Variables declared with this storage class will be allocated into the indirectly addressable portion of the internal ram of a 8051, e.g.:
    -
    idata int idi; + +
    +idata int idi;

    @@ -1362,7 +1422,9 @@ This is a data-type and a storage class specifier. When a variable is declared as a bit, it is allocated into the bit addressable memory of 8051, e.g.:
    -
    bit iFlag; + +
    +bit iFlag;

    @@ -1375,9 +1437,12 @@ Like the bit keyword, sfr / sbit signifies both a data-type and storage class, they are used to describe the special function registers and special bit variables of a 8051, eg:
    -
    sfr at 0x80 P0; /* special function register P0 at location + +
    +sfr at 0x80 P0; /* special function register P0 at location 0x80 */  -
    sbit at 0xd7 CY; /* CY (Carry Flag) */ +
    +sbit at 0xd7 CY; /* CY (Carry Flag) */

    @@ -1391,48 +1456,69 @@ to any of the memory spaces of the 8051. In addition to the explicit pointers, the compiler also allows a _generic class of pointers which can be used to point to any of the memory spaces.
    +
    Pointer declaration examples:
    -
    /* pointer physically in xternal ram pointing to object + +
    +/* pointer physically in xternal ram pointing to object in internal ram */   -
    data unsigned char * xdata p;  +
    +data unsigned char * xdata p; 
      -
    /* pointer physically in code rom pointing to data in xdata +
    +/* pointer physically in code rom pointing to data in xdata space */   -
    xdata unsigned char * code p;  +
    +xdata unsigned char * code p; 
      -
    /* pointer physically in code space pointing to data in +
    +/* pointer physically in code space pointing to data in code space */   -
    code unsigned char * code p;  +
    +code unsigned char * code p; 
      -
    /* the folowing is a generic pointer physically located +
    +/* the folowing is a generic pointer physically located in xdata space */  -
    char * xdata p;
    +char * xdata p; +
    +
    Well you get the idea.
    -
    For compatibility with the previous version of the compiler, + +
    +For compatibility with the previous version of the compiler, the following syntax for pointer declaration is still supported but will disappear int the near future.
    -
    unsigned char _xdata *ucxdp; /* pointer to data +
    +unsigned char _xdata *ucxdp; /* pointer to data in external ram */   -
    unsigned char _data  *ucdp ; /* pointer to data +
    +unsigned char _data  *ucdp ; /* pointer to data in internal ram */   -
    unsigned char _code  *uccp ; /* pointer to data +
    +unsigned char _code  *uccp ; /* pointer to data in R/O code space */  -
    unsigned char _idata *uccp;  /* pointer to upper +
    +unsigned char _idata *uccp;  /* pointer to upper 128 bytes of ram */
    +
    All unqualified pointers are treated as 3-byte (4-byte for the ds390) generic pointers. These type of pointers can also to be explicitly declared.
    -
    unsigned char _generic *ucgp; + +
    +unsigned char _generic *ucgp;
    +
    The highest order byte of the generic pointers contains the data space information. Assembler support routines are called whenever @@ -1459,11 +1545,17 @@ They can be placed on the stack either by using the -stack-auto compiler option or by using the reentrant keyword in the function declaration, e.g.:
    -
    unsigned char foo(char i) reentrant   -
    {   -
    ...   -
    }  + +
    +unsigned char foo(char i) reentrant   +
    +{  
    +...   +
    +}  +
    +
    Since stack space on 8051 is limited, the reentrant keyword or the -stack-auto option should be used sparingly. Note that @@ -1471,16 +1563,24 @@ the reentrant keyword just means that the parameters & local variables will be allocated to the stack, it does not mean that the function is register bank independent.
    +
    Local variables can be assigned storage classes and absolute addresses, e.g.:
    -
    unsigned char foo() {  -
        xdata unsigned char i;  -
        bit bvar;  -
        data at 0x31 unsiged char j;  -
        ...   -
    }  + +
    +unsigned char foo() {  +
    +    xdata unsigned char i;  +
    +    bit bvar;  +
    +    data at 0x31 unsiged char j;  +
    +    ...   +
    +} 
     
    In the above example the variable i will be allocated in the @@ -1526,20 +1626,34 @@ Parameters and Local variables of functions that contain 16 or 32 bit multiplication or division will NOT be overlayed since these are implemented using external functions, e.g.:
    -
    #pragma SAVE   -
    #pragma NOOVERLAY   -
    void set_error(unsigned char errcd)   -
    {  -
        P3 = errcd;  -
    }   -
    #pragma RESTORE   + +
    +#pragma SAVE   +
    +#pragma NOOVERLAY   +
    +void set_error(unsigned char errcd)   +
    +{  +
    +    P3 = errcd;  +
    +}   +
    +#pragma RESTORE  
      -
    void some_isr () interrupt 2 using 1   -
    {  -
        ...  -
        set_error(10);  -
        ...   -
    }  +
    +void some_isr () interrupt 2 using 1   +
    +{  +
    +    ...  +
    +    set_error(10);  +
    +    ...   +
    +} 
     
    In the above example the parameter errcd for the function set_error @@ -1558,10 +1672,15 @@ and local variables for the function are NOT overlayed. SDCC allows interrupt service routines to be coded in C, with some extended keywords.
    -
    void timer_isr (void) interrupt 2 using 1   -
    {   -
    ..   -
    }  + +
    +void timer_isr (void) interrupt 2 using 1   +
    +{   +
    +..   +
    +} 
     
    The number following the interrupt keyword is the interrupt @@ -1591,7 +1710,9 @@ Interrupt Numbers and the corresponding address & descriptions for the Standard 8051 are listed below. SDCC will automatically adjust the interrupt vector table to the maximum interrupt number specified.
    +

    + @@ -1619,6 +1740,7 @@ the interrupt vector table to the maximum interrupt number specified.
    Interrupt # Description

    +
    If the interrupt service routine is defined without using a register bank or with register bank 0 (using 0), the compiler will @@ -1640,6 +1762,7 @@ larger interrupt service routines. Calling other functions from an interrupt service routine is not recommended, avoid it if possible.
    +
    Also see the _naked modifier. @@ -1655,12 +1778,19 @@ A special keyword may be associated with a function declaring it as upon entry to a critical function and enable them back before returning. Note that nesting critical functions may cause unpredictable results.
    -
    int foo () critical   -
    {   -
    ...   -
    ...   -
    }  + +
    +int foo () critical   +
    +{  
    +...   +
    +...   +
    +}  +
    +
    The critical attribute maybe used with other attributes like reentrant. @@ -1683,71 +1813,107 @@ interrupt functions, which can have a large (and often unnecessary) prologue/epilogue. For example, compare the code generated by these two functions:
    -
    data unsigned char counter;  -
    void simpleInterrupt(void) interrupt 1  -
    {  -
        counter++;  -
    }  + +
    +data unsigned char counter;  +
    +void simpleInterrupt(void) interrupt 1  +
    +{  +
    +    counter++;  +
    +} 
      -
    void nakedInterrupt(void) interrupt 2 _naked  -
    {  -
        _asm  -
          inc     _counter  -
          reti    ; MUST explicitly include ret in _naked -function.  -
        _endasm;  -
    }
    +void nakedInterrupt(void) interrupt 2 _naked 
    -For an 8051 target, the generated simpleInterrupt looks like: +{ 
    -
    _simpleIterrupt:  -
        push    acc  -
        push    b  -
        push    dpl  -
        push    dph  -
        push    psw  -
        mov     psw,#0x00  -
        inc     _counter  -
        pop     psw  -
        pop     dph  -
        pop     dpl  -
        pop     b  -
        pop     acc  -
        reti +    _asm 
    +      inc     _counter 
    -whereas nakedInterrupt looks like: +      reti    ; MUST explicitly include ret in _naked +function. 
    -
    _nakedInterrupt:  -
        inc    _counter  -
        reti   ; MUST explicitly include ret(i) in _naked -function. +    _endasm; 
    +}
    -While there is nothing preventing you from writing C code inside a -_naked function, there are many ways to shoot yourself in the foot -doing this, and is is recommended that you stick to inline assembler. - -

    -

    -3.10 Functions using private banks -

    +
    +For an 8051 target, the generated simpleInterrupt looks like: +
    -

    -The using attribute (which tells the compiler to use a register -bank other than the default bank zero) should only be applied to interrupt -functions (see note 1 below). This will in most circumstances make -the generated ISR code more efficient since it will not have to save -registers on the stack. +
    +_simpleIterrupt:  +
    +    push    acc  +
    +    push    b  +
    +    push    dpl  +
    +    push    dph  +
    +    push    psw  +
    +    mov     psw,#0x00  +
    +    inc     _counter  +
    +    pop     psw  +
    +    pop     dph  +
    +    pop     dpl  +
    +    pop     b  +
    +    pop     acc  +
    +    reti +
    + +
    +whereas nakedInterrupt looks like: +
    + +
    +_nakedInterrupt:  +
    +    inc    _counter  +
    +    reti   ; MUST explicitly include ret(i) in _naked +function. +
    + +
    +While there is nothing preventing you from writing C code inside a +_naked function, there are many ways to shoot yourself in the foot +doing this, and is is recommended that you stick to inline assembler. + +

    + +

    +3.10 Functions using private banks +

    + +

    +The using attribute (which tells the compiler to use a register +bank other than the default bank zero) should only be applied to interrupt +functions (see note 1 below). This will in most circumstances make +the generated ISR code more efficient since it will not have to save +registers on the stack.

    The using attribute will have no effect on the generated code for a non-interrupt function (but may occasionally be useful anyway1). -
    (pending: I don't think this has been done yet) + HREF="#foot530">1). +
    +(pending: I don't think this has been done yet)

    An interrupt function using a non-zero bank will assume that @@ -1780,8 +1946,11 @@ a function using a different, non-zero bank from an ISR. Data items can be assigned an absolute address with the at <address> keyword, in addition to a storage class, e.g.:
    -
    xdata at 0x8000 unsigned char PORTA_8255 ;  + +
    +xdata at 0x8000 unsigned char PORTA_8255 ; 
    +
    In the above example the PORTA_8255 will be allocated to the location 0x8000 of the external ram. Note that this feature is provided to @@ -1794,11 +1963,14 @@ the absolute address. The assembler listing file (.lst) and the linker output files (.rst) and (.map) are a good places to look for such overlaps.
    +
    Absolute address can be specified for variables in all storage classes, e.g.:
    -
    bit at 0x02 bvar;  + +
    +bit at 0x02 bvar; 
     
    The above example will allocate the variable at offset 0x02 in the @@ -1843,37 +2015,59 @@ optimizer. This might cause some unexpected changes in the inline assembler code. Please go throught the peephole optimizer rules defined in file SDCCpeeph.def carefully before using this option.
    -
    _asm   -
        mov     b,#10   -
    00001$:   -
        djnz    b,00001$   -
    _endasm ; + +
    +_asm   +
    +    mov     b,#10   +
    +00001$:   +
    +    djnz    b,00001$   +
    +_endasm ;
    +
    The inline assembler code can contain any valid code understood by the assembler, this includes any assembler directives and comment lines. The compiler does not do any validation of the code within the _asm ... _endasm; keyword pair.
    +
    Inline assembler code cannot reference any C-Labels, however it can reference labels defined by the inline assembler, e.g.:
    -
    foo() {   -
        /* some c code */   -
        _asm   -
          ; some assembler code   -
          ljmp $0003   -
        _endasm;   -
        /* some more c code */   -
    clabel:  /* inline assembler cannot reference this label + +
    +foo() {   +
    +    /* some c code */   +
    +    _asm   +
    +      ; some assembler code   +
    +      ljmp $0003   +
    +    _endasm;   +
    +    /* some more c code */   +
    +clabel:  /* inline assembler cannot reference this label */   -
        _asm  -
        $0003: ;label (can be reference by inline assembler +
    +    _asm  +
    +    $0003: ;label (can be reference by inline assembler only)   -
        _endasm ;   -
        /* some more c code */  -
    }  +
    +    _endasm ;   +
    +    /* some more c code */  +
    +} 
     
    In other words inline assembly code can access labels defined in inline @@ -1897,8 +2091,11 @@ to other MCUs, although some model specific assembler optimations are used. The following files contain the described routine, all of them can be found in <installdir>/share/sdcc/lib.
    -
    <pending: tabularise this> + +
    +<pending: tabularise this>
    +
    _mulsint.c - signed 16 bit multiplication (calls _muluint)
    @@ -1924,6 +2121,7 @@ _modslong.c - signed 32 bit modulus (calls _modulong)
    _modulong.c - unsigned 32 bit modulus
    +
    Since they are compiled as non-reentrant, interrupt service routines should not do any of the above operations. If this is unavoidable @@ -1942,8 +2140,11 @@ SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating point support routines are derived from gcc's floatlib.c and consists of the following routines:
    -
    <pending: tabularise this> + +
    +<pending: tabularise this>
    +
    _fsadd.c - add floating point numbers
    @@ -1977,6 +2178,7 @@ _ulong2fs.c - convert unsigned long to floating point number
    _long2fs.c - convert long to floating point number
    +
    Note if all these routines are used simultaneously the data space might overflow. For serious floating point usage it is strongly recommended @@ -2023,11 +2225,13 @@ mode, up to four meg of external RAM or code space can be directly addressed. See the data sheets at www.dalsemi.com for further information on this part.
    +
    In older versions of the compiler, this option was used with the MCS51 code generator (-mmcs51). Now, however, the '390 has it's own code generator, selected by the -mds390 switch.
    +
    Note that the compiler does not generate any code to place the processor into 24 bitmode (although tinibios in the ds390 libraries will @@ -2035,10 +2239,12 @@ do that for you). If you don't use tinibios, the boot loader or similar code must ensure that the processor is in 24 bit contiguous addressing mode before calling the SDCC startup code.
    +
    Like the -model-large option, variables will by default be placed into the XDATA segment.
    +
    Segments may be placed anywhere in the 4 meg address space using the usual -*-loc options. Note that if any segments are located above @@ -2060,33 +2266,24 @@ The compiler creates the following #defines.

      -
    • SDCC - this Symbol is always defined. -
    • +
    • SDCC - this Symbol is always defined.
    • SDCC_mcs51 or SDCC_ds390 or SDCC_z80, etc - depending on the model -used (e.g.: -mds390) -
    • +used (e.g.: -mds390)
    • __mcs51 or __ds390 or __z80, etc - depending on the model used -(e.g. -mz80) -
    • +(e.g. -mz80)
    • SDCC_STACK_AUTO - this symbol is defined when -stack-auto -option is used. -
    • -
    • SDCC_MODEL_SMALL - when -model-small is used. -
    • -
    • SDCC_MODEL_LARGE - when -model-large is used. -
    • -
    • SDCC_USE_XSTACK - when -xstack option is used. -
    • -
    • SDCC_STACK_TENBIT - when -mds390 is used -
    • -
    • SDCC_MODEL_FLAT24 - when -mds390 is used -
    • +option is used. +
    • SDCC_MODEL_SMALL - when -model-small is used.
    • +
    • SDCC_MODEL_LARGE - when -model-large is used.
    • +
    • SDCC_USE_XSTACK - when -xstack option is used.
    • +
    • SDCC_STACK_TENBIT - when -mds390 is used
    • +
    • SDCC_MODEL_FLAT24 - when -mds390 is used

    -4 SDCC Technical Data +4. SDCC Technical Data

    @@ -2109,30 +2306,48 @@ MCU specific optimizations. The compiler does local and global common subexpression elimination, e.g.:
    -
    i = x + y + 1;   -
    j = x + y; + +
    +i = x + y + 1;  
    +j = x + y; +
    +
    will be translated to
    -
    iTemp = x + y   -
    i = iTemp + 1   -
    j = iTemp  + +
    +iTemp = x + y   +
    +i = iTemp + 1   +
    +j = iTemp 
    +
    Some subexpressions are not as obvious as the above example, e.g.:
    -
    a->b[i].c = 10;   -
    a->b[i].d = 11; + +
    +a->b[i].c = 10;   +
    +a->b[i].d = 11;
    +
    In this case the address arithmetic a->b[i] will be computed only once; the equivalent code in C would be.
    -
    iTemp = a->b[i];   -
    iTemp.c = 10;   -
    iTemp.d = 11; + +
    +iTemp = a->b[i];   +
    +iTemp.c = 10;  
    +iTemp.d = 11; +
    +
    The compiler will try to keep these temporary variables in registers. @@ -2143,24 +2358,40 @@ The compiler will try to keep these temporary variables in registers.

    + int global;   -
    void f () {   -
      int i;   -
      i = 1;  /* dead store */   -
      global = 1; /* dead store */   -
      global = 2;   -
      return;   -
      global = 3; /* unreachable */   -
    }
    +void f () {   +
    +  int i;   +
    +  i = 1;  /* dead store */   +
    +  global = 1; /* dead store */   +
    +  global = 2;   +
    +  return;   +
    +  global = 3; /* unreachable */   +
    +} +
    +
    will be changed to
    -
    int global; void f ()   -
    {  -
      global = 2;   -
      return;   -
    } + +
    +int global; void f ()   +
    +{  +
    +  global = 2;   +
    +  return;   +
    +}

    @@ -2169,22 +2400,36 @@ will be changed to

    + int f() {   -
      int i, j;   -
      i = 10;   -
      j = i;   -
      return j;   -
    }
    +  int i, j;   +
    +  i = 10;   +
    +  j = i;   +
    +  return j;   +
    +} +
    +
    will be changed to
    -
    int f() {   -
        int i,j;   -
        i = 10;   -
        j = 10;   -
        return 10;   -
    }  + +
    +int f() {   +
    +    int i,j;   +
    +    i = 10;   +
    +    j = 10;   +
    +    return 10;   +
    +} 
     
    Note: the dead stores created by this copy propagation will be eliminated @@ -2211,41 +2456,65 @@ then induction optimization can be eliminated either for the entire source file (with -noinduction option) or for a given function only using #pragma NOINDUCTION.
    +
    Loop Invariant:
    -
    for (i = 0 ; i < 100 ; i ++)   -
       f += k + l; + +
    +for (i = 0 ; i < 100 ; i ++)  
    +    f += k + l; +
    +
    changed to
    -
    itemp = k + l;   -
    for (i = 0; i < 100; i++)   -
      f += itemp; + +
    +itemp = k + l;   +
    +for (i = 0; i < 100; i++)   +
    +  f += itemp;
    +
    As mentioned previously some loop invariants are not as apparent, all static address computations are also moved out of the loop.
    +
    Strength Reduction, this optimization substitutes an expression by a cheaper expression:
    -
    for (i=0;i < 100; i++)  -
      ar[i*5] = i*3; + +
    +for (i=0;i < 100; i++) 
    +  ar[i*5] = i*3; +
    +
    changed to
    -
    itemp1 = 0;   -
    itemp2 = 0;   -
    for (i=0;i< 100;i++) {   -
       ar[itemp1] = itemp2;   -
       itemp1 += 5;   -
       itemp2 += 3;   -
    } + +
    +itemp1 = 0;   +
    +itemp2 = 0;   +
    +for (i=0;i< 100;i++) {   +
    +    ar[itemp1] = itemp2;   +
    +    itemp1 += 5;  
    +    itemp2 += 3;   +
    +} +
    +
    The more expensive multiplication is changed to a less expensive addition. @@ -2269,24 +2538,20 @@ analysis).

    • The 'for' loop is of the form
      -
      for (<symbol> = <expression> ; <sym> [< | <=] <expression> + +
      +for (<symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ | <sym> += 1])  -
          <for body> -
    • -
    • The <for body> does not contain ``continue'' or 'break''. -
    • -
    • All goto's are contained within the loop. -
    • -
    • No function calls within the loop. -
    • +
      +    <for body> +
    • The <for body> does not contain ``continue'' or 'break''.
    • +
    • All goto's are contained within the loop.
    • +
    • No function calls within the loop.
    • The loop control variable <sym> is not assigned any value within the -loop -
    • +loop
    • The loop control variable does NOT participate in any arithmetic operation -within the loop. -
    • -
    • There are NO switch statements in the loop. -
    • +within the loop. +
    • There are NO switch statements in the loop.
    Note djnz instruction can be used for 8-bit values only, therefore it is advantageous to declare loop control symbols as char. @@ -2302,11 +2567,17 @@ Ofcourse this may not be possible on all situations. SDCC does numerous algebraic simplifications, the following is a small sub-set of these optimizations.
    -
    i = j + 0 ; /* changed to */ i = j;   -
    i /= 2; /* changed to */ i >>= 1;   -
    i = j - j ; /* changed to */ i = 0;   -
    i = j / 1 ; /* changed to */ i = j; + +
    +i = j + 0 ; /* changed to */ i = j;  
    +i /= 2; /* changed to */ i >>= 1;   +
    +i = j - j ; /* changed to */ i = 0;   +
    +i = j / 1 ; /* changed to */ i = j; +
    +
    Note the subexpressions given above are generally introduced by macro expansions or as a result of copy/constant propagation. @@ -2326,63 +2597,88 @@ are true.
    • The case labels are in numerical sequence, the labels need not be in order, and the starting number need not be one or zero. -
    • -
    +
    + +
    switch(i) {                         switch (i) {   -
    case 4:...                          case 1: ...   -
    case 5:...                          case 2: ...   -
    case 3:...                          case 3: ...   -
    case 6:...                          case 4: ...   -
    }                                   }  +
    +case 4:...                          case 1: ...   +
    +case 5:...                          case 2: ...   +
    +case 3:...                          case 3: ...   +
    +case 6:...                          case 4: ...   +
    +}                                   } 
     
    -Both the above switch statements will be implemented using a jump-table. - -

    - -

      +Both the above switch statements will be implemented using a jump-table.
    • The number of case labels is at least three, since it takes two conditional -statements to handle the boundary conditions. -
    • +statements to handle the boundary conditions.
    • The number of case labels is less than 84, since each label takes -3 bytes and a jump-table can be utmost 256 bytes long. -
    • +3 bytes and a jump-table can be utmost 256 bytes long.
    Switch statements which have gaps in the numeric sequence or those that have more that 84 case labels can be split into more than one switch statement for efficient code generation, e.g.:
    -
    switch (i) {   -
    case 1: ...   -
    case 2: ...   -
    case 3: ...   -
    case 4: ...   -
    case 9: ...   -
    case 10: ...   -
    case 11: ...   -
    case 12: ...   -
    } + +
    +switch (i) {   +
    +case 1: ...   +
    +case 2: ...   +
    +case 3: ...   +
    +case 4: ...   +
    +case 9: ...  
    +case 10: ...   +
    +case 11: ...   +
    +case 12: ...   +
    +} +
    +
    If the above switch statement is broken down into two switch statements
    -
    switch (i) {   -
    case 1: ...   -
    case 2: ...   -
    case 3: ...   -
    case 4: ...   -
    }  + +
    +switch (i) {   +
    +case 1: ...   +
    +case 2: ...   +
    +case 3: ...   +
    +case 4: ...   +
    +} 
     
    and 
      -
    switch (i) {   -
    case 9:  ...   -
    case 10: ...   -
    case 11: ...   -
    case 12: ...   -
    }  +
    +switch (i) {   +
    +case 9:  ...   +
    +case 10: ...   +
    +case 11: ...   +
    +case 12: ...   +
    +} 
     
    then both the switch statements will be implemented using jump-tables @@ -2398,44 +2694,61 @@ whereas the unmodified switch statement will not be. Bit shifting is one of the most frequently used operation in embedded programming. SDCC tries to implement bit-shift operations in the most efficient way possible, e.g.: +
     
    +unsigned char i; 
    -unsigned char i; -
    ... +...  
    -i>>= 4; -
    ... +i>>= 4;  
    +... 
    -generates the following code: +
    +generates the following code: +
     
    -mov a,_i +mov a,_i  
    -swap a +swap a  
    -anl a,#0x0f +anl a,#0x0f  
    -mov _i,a +mov _i,a
    +
    In general SDCC will never setup a loop if the shift count is known. Another example:
    -
    unsigned int i;   -
    ...   -
    i >>= 9;   -
    ... + +
    +unsigned int i;   +
    +...   +
    +i >>= 9;  
    +... +
    +
    will generate:
    -
    mov a,(_i + 1)   -
    mov (_i + 1),#0x00   -
    clr c   -
    rrc a   -
    mov _i,a + +
    +mov a,(_i + 1)  
    +mov (_i + 1),#0x00   +
    +clr c   +
    +rrc a   +
    +mov _i,a +
    +
    Note that SDCC stores numbers in little-endian format (i.e. lowest order first). @@ -2450,24 +2763,37 @@ order first). A special case of the bit-shift operation is bit rotation, SDCC recognizes the following expression to be a left bit-rotation:
    -
    unsigned char i;   -
    ...   -
    i = ((i << 1) | (i >> + +
    +unsigned char i;   +
    +...   +
    +i = ((i << 1) | (i >> 7)); -
    ...
    +... +
    +
    will generate the following code:
    -
    mov a,_i   -
    rl a   -
    mov _i,a + +
    +mov a,_i   +
    +rl a  
    +mov _i,a +
    +
    SDCC uses pattern matching on the parse tree to determine this operation.Variations of this case will also be recognized as bit-rotation, i.e.:
    -
    i = ((i >> 7) | (i << + +
    +i = ((i >> 7) | (i << 1)); /* left-bit rotation */

    @@ -2482,29 +2808,44 @@ type (long, int, short or char types). SDCC recognizes the following expression to yield the highest order bit and generates optimized code for it, e.g.:
    -
    unsigned int gint;   + +
    + unsigned int gint;  
      -
    foo () {   -
    unsigned char hob;   -
      ...   -
      hob = (gint >> 15) & 1;   -
      ..   -
    }
    +foo () {   +
    +unsigned char hob;   +
    +  ...   +
    +  hob = (gint >> 15) & 1;   +
    +  ..   +
    +} +
    +
    will generate the following code:
      -
                                 61 +
    +                             61 ;  hob.c 7   -
       000A E5*01                62         +
    +   000A E5*01                62         mov  a,(_gint + 1)   -
       000C 33                   63         +
    +   000C 33                   63         rlc  a   -
       000D E4                   64         +
    +   000D E4                   64         clr  a   -
       000E 13                   65         +
    +   000E 13                   65         rrc  a   -
       000F F5*02                66         +
    +   000F F5*02                66         mov  _foo_hob_1_1,a 
     
    @@ -2513,8 +2854,11 @@ is a standard C expression, so I heartily recommend this be the only way to get the highest order bit, (it is portable). Of course it will be recognized even if it is embedded in other expressions, e.g.:
    -
    xyz = gint + ((gint >> 15) & 1); + +
    +xyz = gint + ((gint >> 15) & 1);
    +
    will still be recognized. @@ -2532,43 +2876,67 @@ set of rules are compiled into the compiler, additional rules may be added with the -peep-file <filename> option. The rule language is best illustrated with examples.
    -
    replace {   -
      mov %1,a   -
      mov a,%1  -
    } by {  -
      mov %1,a  -
    } +
    +replace {  
    -The above rule will change the following assembly sequence: +  mov %1,a  
    -
      mov r1,a   -
      mov a,r1 +  mov a,%1 
    +} by { 
    -to +  mov %1,a 
    -
    mov r1,a +}
    + +
    +The above rule will change the following assembly sequence: +
    + +
    +  mov r1,a   +
    +  mov a,r1 +
    + +
    +to +
    + +
    +mov r1,a +
    +
    Note: All occurrences of a %n (pattern variable) must denote the same string. With the above rule, the assembly sequence:
    -
      mov r1,a   -
      mov a,r2 + +
    +  mov r1,a  
    +  mov a,r2 +
    +
    will remain unmodified.
    +
    Other special case optimizations may be added by the user (via -peep-file option). E.g. some variants of the 8051 MCU allow only ajmp and acall. The following two rules will change all ljmp and lcall to ajmp and acall
    -
    replace { lcall %1 } by { acall %1 }   -
    replace { ljmp %1 } by { ajmp %1 } +
    +replace { lcall %1 } by { acall %1 }   +
    +replace { ljmp %1 } by { ajmp %1 } +
    +
    The inline-assembler code is also passed through the peep hole optimizer, thus the peephole optimizer can also be used as an assembly @@ -2576,21 +2944,30 @@ level macro expander. The rules themselves are MCU dependent whereas the rule language infra-structure is MCU independent. Peephole optimization rules for other MCU can be easily programmed using the rule language.
    +
    The syntax for a rule is as follows:
    -
    rule := replace [ restart ] '{' <assembly sequence> '\n' + +
    +rule := replace [ restart ] '{' <assembly sequence> '\n'   -
                                '}' by '{' '\n' +
    +                            '}' by '{' '\n'   -
                                    <assembly +
    +                                <assembly sequence> '\n'   -
                                '}' [if <functionName> +
    +                            '}' [if <functionName> ] '\n'  
    -
    <assembly sequence> := assembly instruction (each instruction including + +
    +<assembly sequence> := assembly instruction (each instruction including labels must be on a separate line).
    +
    The optimizer will apply to the rules one by one from the top in the sequence of their appearance, it will terminate when all rules are @@ -2600,47 +2977,80 @@ a rule is expensive (performance), it is intended to be used in situations where a transformation will trigger the same rule again. A good example of this the following rule:
    +
    -replace restart { -
      pop %1 -
      push %1 } by { -
      ; nop -
    } +replace restart {  
    +  pop %1   +
    +  push %1 } by {   +
    +  ; nop   +
    +} +
    +
    Note that the replace pattern cannot be a blank, but can be a comment line. Without the 'restart' option only the inner most 'pop' 'push' pair would be eliminated, i.e.:
    -
      pop ar1   -
      pop ar2   -
      push ar2   -
      push ar1 + +
    +  pop ar1   +
    +  pop ar2  
    +  push ar2   +
    +  push ar1 +
    +
    would result in:
    -
    pop ar1   -
    ; nop   -
    push ar1 + +
    +  pop ar1  
    -
    with the restart option the rule will be applied again to the +  ; nop   +
    +  push ar1 +
    + +
    +with the restart option the rule will be applied again to the resulting code and then all the pop-push pairs will be eliminated to yield:
    -
    ; nop   -
    ; nop + +
    +  ; nop  
    +  ; nop +
    +
    A conditional function can be attached to a rule. Attaching rules are somewhat more involved, let me illustrate this with an example.
    -
    replace {   -
         ljmp %5   -
    %2:} by {   -
         sjmp %5   -
    %2:} if labelInRange + +
    +replace {   +
    +     ljmp %5   +
    +%2:  +
    +} by {  
    +     sjmp %5   +
    +%2:  +
    +} if labelInRange +
    +
    The optimizer does a look-up of a function name table defined in function callFuncByName in the source file SDCCpeeph.c, with the name @@ -2656,8 +3066,6 @@ will have some better means. If you are looking at this file, you will also see the default rules that are compiled into the compiler, you can add your own rules in the default set there if you get tired of specifying the -peep-file option. -
    -
    <pending: this is as far as I got>

    @@ -2672,31 +3080,23 @@ applicable only at a function level.

      -
    • SAVE - this will save all the current options. -
    • +
    • SAVE - this will save all the current options.
    • RESTORE - will restore the saved options from the last save. Note that SAVES & RESTOREs cannot be nested. SDCC uses the same buffer -to save the options each time a SAVE is called. -
    • -
    • NOGCSE - will stop global subexpression elimination. -
    • -
    • NOINDUCTION - will stop loop induction optimizations. -
    • +to save the options each time a SAVE is called. +
    • NOGCSE - will stop global subexpression elimination.
    • +
    • NOINDUCTION - will stop loop induction optimizations.
    • NOJTBOUND - will not generate code for boundary value checking, when -switch statements are turned into jump-tables. -
    • +switch statements are turned into jump-tables.
    • NOOVERLAY - the compiler will not overlay the parameters and local -variables of a function. -
    • -
    • NOLOOPREVERSE - Will not do loop reversal optimization -
    • +variables of a function. +
    • NOLOOPREVERSE - Will not do loop reversal optimization
    • EXCLUDE NONE | {acc[,b[,dpl[,dph]]] - The exclude pragma disables generation of pair of push/pop instruction in ISR function (using interrupt keyword). The directive should be placed immediately before the ISR function definition and it affects ALL ISR functions following it. To enable the normal register saving for ISR functions -use #pragma EXCLUDE none. -
    • +use #pragma EXCLUDE none.
    • CALLEE-SAVES function1[,function2[,function3...]] - The compiler by default uses a caller saves convention for register saving across function calls, however this can cause unneccessary register pushing @@ -2710,8 +3110,7 @@ run time performance of the generated code. In future the compiler (with interprocedural analysis) will be able to determine the appropriate scheme to use for each function call. If -callee-saves command line option is used, the function names specified in #pragma CALLEE-SAVES -is appended to the list of functions specified inthe command line. -
    • +is appended to the list of functions specified inthe command line.
    The pragma's are intended to be used to turn-off certain optimizations which might cause the compiler to generate extra stack / data space @@ -2721,25 +3120,33 @@ following example, they are used to control options & optimizations for a given function; pragmas should be placed before and/or after a function, placing pragma's inside a function body could have unpredictable results. +
    -

    -eg - -

    -#pragma SAVE   /* save the current settings */ -
    #pragma NOGCSE /* turnoff global subexpression elimination */ - -
    #pragma NOINDUCTION /* turn off induction optimizations */
    -int foo () -
    { -
        ... -
        /* large code */ -
        ... -
    } -
    #pragma RESTORE /* turn the optimizations back on */ +#pragma SAVE /* save the current settings */   +
    +#pragma NOGCSE /* turnoff global subexpression elimination +*/   +
    +#pragma NOINDUCTION /* turn off induction optimizations +*/   +
    +int foo ()   +
    +{   +
    +    ...   +
    +    /* large code */   +
    +    ...   +
    +}   +
    +#pragma RESTORE /* turn the optimizations back on */ +
    -

    +
    The compiler will generate a warning message when extra space is allocated. It is strongly recommended that the SAVE and RESTORE pragma's be used when changing options for a function. @@ -2747,7 +3154,7 @@ when changing options for a function.

    -4.3 Library Routines +4.3 <pending: this is messy and incomplete> Library Routines

    @@ -2758,48 +3165,71 @@ stdio.h - Contains the following functions printf & sprintf these routines are developed by Martijn van Balen <balen@natlab.research.philips.com>.

    + %[flags][width][b|B|l|L]type

    +            flags: -        left justify output in specified field width -
                     +        prefix output with +
    +                 +        prefix output with +/- sign if output is signed type -
                     space    prefix output with a +
    +                 space    prefix output with a blank if it's a signed positive value -
              width:          specifies minimum number +
    +          width:          specifies minimum number of characters outputted for numbers -
                              or strings. -
                              - For numbers, +
    +                          or strings. +
    +                          - For numbers, spaces are added on the left when needed. -
                                If width starts +
    +                            If width starts with a zero character, zeroes and used -
                                instead of +
    +                            instead of spaces. -
                              - For strings, +
    +                          - For strings, spaces are are added on the left or right (when -
                                flag '-' is +
    +                            flag '-' is used) when needed. -
                              -
              b/B:            byte argument (used +
    +                          +
    +          b/B:            byte argument (used by d, u, o, x, X) -
              l/L:            long argument (used +
    +          l/L:            long argument (used by d, u, o, x, X) -
              type:  d        decimal number -
                     u        unsigned decimal +
    +          type:  d        decimal number +
    +                 u        unsigned decimal number -
                     o        unsigned octal number +
    +                 o        unsigned octal number -
                     x        unsigned hexadecimal +
    +                 x        unsigned hexadecimal number (0-9, a-f) -
                     X        unsigned hexadecimal +
    +                 X        unsigned hexadecimal number (0-9, A-F) -
                     c        character -
                     s        string (generic pointer) +
    +                 c        character +
    +                 s        string (generic pointer) -
                     p        generic pointer (I:data/idata, +
    +                 p        generic pointer (I:data/idata, C:code, X:xdata, P:paged) -
                     f        float (still to be +
    +                 f        float (still to be implemented)

    @@ -2808,17 +3238,28 @@ simplified version of printf supports only the following formats.

    format     output type     argument-type -
    %d         decimal       short/int -
    %ld        decimal       long -
    %hd        decimal       char -
    %x        hexadecimal    short/int -
    %lx       hexadecimal    long -
    %hx       hexadecimal    char -
    %o         octal         short/int -
    %lo        octal         long -
    %ho        octal         char -
    %c        character      char -
    %s        character     _generic pointer +
    +%d         decimal       short/int +
    +%ld        decimal       long +
    +%hd        decimal       char +
    +%x        hexadecimal    short/int +
    +%lx       hexadecimal    long +
    +%hx       hexadecimal    char +
    +%o         octal         short/int +
    +%lo        octal         long +
    +%ho        octal         char +
    +%c        character      char +
    +%s        character     _generic pointer

    The routine is very stack intesive, -stack-after-data parameter should @@ -2842,22 +3283,21 @@ parameter list if and only if it is 'reentrant' va_list, va_start, va_arg, va_end.

    - +

  • setjmp.h - contains defintion for ANSI setjmp & longjmp routines. Note in this case setjmp & longjmp can be used between functions executing within the same register bank, if long jmp is executed from a function that is using a different register bank from the function issuing the setjmp function, the results may be unpredictable. The jump buffer requires 3 bytes of data (the stack pointer & a 16 byte -return address), and can be placed in any address space. -
  • +return address), and can be placed in any address space.
  • stdlib.h - contains the following functions.

    atoi, atol.

    -

  • +
  • string.h - contains the following functions.

    @@ -2866,7 +3306,7 @@ strspn, strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp, memset.

    -

  • +
  • ctype.h - contains the following routines.

    @@ -2874,50 +3314,59 @@ iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace, isxdigit, isalnum, isalpha.

    -

  • +
  • malloc.h - The malloc routines are developed by Dmitry S. Obukhov (dso@usa.net). These routines will allocate memory from the external ram. Here is a description on how to use them (as described by the author).

    + //Example: -
         //     #define DYNAMIC_MEMORY_SIZE 0x2000 -
         //     ..... -
         //     unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE]; +
    +     //     #define DYNAMIC_MEMORY_SIZE 0x2000 +
    +     //     ..... +
    +     //     unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE]; -
         //     unsigned char xdata * current_buffer; -
         //     ..... -
         //     void main(void) -
         //     { -
         //         ... -
         //         init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE); +
    +     //     unsigned char xdata * current_buffer; +
    +     //     ..... +
    +     //     void main(void) +
    +     //     { +
    +     //         ... +
    +     //         init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE); -
         //         //Now it's possible to use malloc. -
         //         ... -
         //         current_buffer = malloc(0x100); -
         // +
    +     //         //Now it's possible to use malloc. +
    +     //         ... +
    +     //         current_buffer = malloc(0x100); +
    +     //

    -

  • +
  • serial.h - Serial IO routines are also developed by Dmitry S. Obukhov (dso@usa.net). These routines are interrupt driven with a 256 byte circular buffer, they also expect external ram to be present. Please see documentation in file SDCCDIR/sdcc51lib/serial.c. Note the header file ``serial.h'' MUST be included in the file containing the -'main' function. -
  • +'main' function.
  • ser.h - Alternate serial routine provided by Wolfgang Esslinger <wolfgang@WiredMinds.com> these routines are more compact and faster. Please see documentation -in file SDCCDIR/sdcc51lib/ser.c -
  • +in file SDCCDIR/sdcc51lib/ser.c
  • ser_ir.h - Another alternate set of serial routines provided by Josef -Wolf <jw@raven.inka.de>, these routines do not use the external ram. -
  • -
  • reg51.h - contains register definitions for a standard 8051 -
  • -
  • float.h - contains min, max and other floating point related stuff. -
  • +Wolf <jw@raven.inka.de>, these routines do not use the external ram. +
  • reg51.h - contains register definitions for a standard 8051
  • +
  • float.h - contains min, max and other floating point related stuff.
  • All library routines are compiled as -model-small, they are all non-reentrant, if you plan to use the large model or want to make these routines @@ -2936,62 +3385,79 @@ get to them shortly.

    -

    -4.5 Global Registers used for Parameter Passing -

    +

    +4.4.1 Global Registers used for Parameter Passing +

    -By default the compiler uses the global registers ``DPL,DPH,B,ACC'' -to pass the first parameter to a routine, the second parameter onwards -is either allocated on the stack (for reentrant routines or -stack-auto -is used) or in the internal / external ram (depending on the memory -model). +The compiler always uses the global registers DPL,DPH,B and +ACC to pass the first parameter to a routine. The second parameter +onwards is either allocated on the stack (for reentrant routines or +if -stack-auto is used) or in the internal / external ram (depending +on the memory model).

    -

    -4.5.1 Assembler Routine(non-reentrant) +

    +4.4.2 Assembler Routine(non-reentrant)

    In the following example the function cfunc calls an assembler routine asm_func, which takes two parameters. +
    -

    -extern int asm_func(unsigned char, unsigned char); - -


    -int c_func (unsigned char i, unsigned char j) -
    { -
            return asm_func(i,j); -
    } +extern int asm_func(unsigned char, unsigned char);  +
     
    -int main() -
    { -
       return c_func(10,9); -
    } - -

    -The corresponding assembler function is:- - -

    -        .globl _asm_func_PARM_2 -
            .globl _asm_func -
            .area OSEG +int c_func (unsigned char i, unsigned char j)  +
    +{  +
    +    return asm_func(i,j);  +
    +}  +
      +
    +int main() 
    -_asm_func_PARM_2:       .ds      1 -
            .area CSEG +{  +
    +    return c_func(10,9);  +
    +}  +
      +
    +The corresponding assembler function is:
    -_asm_func: -
            mov     a,dpl -
            add     a,_asm_func_PARM_2 -
            mov     dpl,a -
            mov     dpl,#0x00 -
            ret -

    +
    +.globl _asm_func_PARM_2   +
    +        .globl _asm_func   +
    +        .area OSEG   +
    +_asm_func_PARM_2:  +
    +        .ds 1   +
    +        .area CSEG   +
    +_asm_func:   +
    +        mov a,dpl   +
    +        add a,_asm_func_PARM_2   +
    +        mov dpl,a   +
    +        mov dpl,#0x00   +
    +        ret  +
      +
    Note here that the return values are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for two byte values. 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','b' & @@ -3002,75 +3468,101 @@ The parameter naming convention is _<function_name>_PARM_<n>, where n is the parameter number starting from 1, and counting from the left. The first parameter is passed in ``dpl'' for One bye parameter, ``dptr'' if two bytes, ``b,dptr'' for three bytes -and ``acc,b,dptr'' for four bytes, the varaible name for the second +and ``acc,b,dptr'' for four bytes, the varible name for the second parameter will be _<function_name>_PARM_2. +
    -

    -Assemble the assembler routine with the following command. - -

    -asx8051 -losg asmfunc.asm +
    +Assemble the assembler routine with the following command: +
    -

    +
    +asx8051 -losg asmfunc.asm +
    +
    Then compile and link the assembler routine to the C source file with -the following command, +the following command: +
    -

    -sdcc cfunc.c asmfunc.rel +
    +sdcc cfunc.c asmfunc.rel

    -

    -4.5.2 Assembler Routine(reentrant) +

    +4.4.3 Assembler Routine(reentrant)

    In this case the second parameter onwards will be passed on the stack, the parameters are pushed from right to left i.e. after the call the -left most parameter will be on the top of the stack. Here is an example. - -

    -extern int asm_func(unsigned char, unsigned char); - -

    -  - -

    -int c_func (unsigned char i, unsigned char j) reentrant -
    { -
            return asm_func(i,j); -
    } +left most parameter will be on the top of the stack. Here is an example:
    -int main() -
    { -
       return c_func(10,9); -
    } -

    -The corresponding assembler routine is. +
    +extern int asm_func(unsigned char, unsigned char);  +
      +
    +int c_func (unsigned char i, unsigned char j) reentrant   +
    +{   +
    +    return asm_func(i,j);   +
    +}   +
      +
    +int main()   +
    +{   +
    +    return c_func(10,9);   +
    +}  +
    -

    -        .globl _asm_func
    -_asm_func: -
            push  _bp -
            mov  _bp,sp -
            mov  r2,dpl -
            mov  a,_bp -
            clr  c -
            add  a,#0xfd -
            mov  r0,a -
            add  a,#0xfc -
            mov  r1,a -
            mov  a,@r0 -
            add  a,r2 -
            mov  dpl,a -
            mov  dph,#0x00 -
            mov  sp,_bp -
            pop  _bp -
            ret +The corresponding assembler routine is: +
    -

    +
    +.globl _asm_func   +
    +_asm_func:   +
    +    push _bp   +
    +    mov _bp,sp   +
    +    mov r2,dpl  +
    +    mov a,_bp   +
    +    clr c   +
    +    add a,#0xfd   +
    +    mov r0,a   +
    +    add a,#0xfc  +
    +    mov r1,a   +
    +    mov a,@r0   +
    +    add a,r2  +
    +    mov dpl,a   +
    +    mov dph,#0x00   +
    +    mov sp,_bp   +
    +    pop _bp   +
    +    ret  +
      +
    The compiling and linking procedure remains the same, however note the extra entry & exit linkage required for the assembler code, _bp is the stack frame pointer and is used to compute the offset into @@ -3078,8 +3570,8 @@ the stack for parameters and local variables.

    -

    -4.6 External Stack +

    +4.5 External Stack

    @@ -3098,8 +3590,8 @@ option, this port MAY NOT be used by the application program.

    -

    -4.7 ANSI-Compliance +

    +4.6 ANSI-Compliance

    @@ -3107,86 +3599,77 @@ Deviations from the compliancy.

    -

      -
    1. functions are not always reentrant. -
    2. +
        +
      • functions are not always reentrant.
      • structures cannot be assigned values directly, cannot be passed as function parameters or assigned to each other and cannot be a return -value from a function. - -

        -eg - -

        -

      • -
    -struct s { ... }; +value from a function, e.g.:  +
     
    -struct s s1, s2; +struct s { ... };  
    -foo() -
    { -
    ... +struct s s1, s2;  
    -s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ -
    ... -
    } - -

    -struct s foo1 (struct s parms) /* is invalid in SDCC although allowed -in ANSI */ -
    { +foo()  
    -struct s rets; -
    ... +{  
    -return rets;/* is invalid in SDCC although allowed in ANSI */ - -
    } - -

    - -

      -
    1. 'long long' (64 bit integers) not supported. -
    2. -
    3. 'double' precision floating point not supported. -
    4. -
    5. integral promotions are suppressed. What does this mean ? The compiler -will not implicitly promote an integer expression to a higher order -integer, exception is an assignment or parameter passing. -
    6. -
    7. No support for setjmp and longjmp (for now). -
    8. +    ...   +
      +    s1 = s2 ; /* is invalid in SDCC although allowed +in ANSI */   +
      +    ...   +
      +}  +
      +struct s foo1 (struct s parms) /* is invalid in SDCC although +allowed in ANSI */   +
      +{   +
      +    struct s rets;   +
      +    ...   +
      +    return rets;/* is invalid in SDCC although allowed +in ANSI */   +
      +} +
    9. 'long long' (64 bit integers) not supported.
    10. +
    11. 'double' precision floating point not supported.
    12. +
    13. No support for setjmp and longjmp (for now).
    14. Old K&R style function declarations are NOT allowed. -
    15. -
    -foo(i,j) /* this old style of function declarations */ +
     
    -int i,j; /* are valid in ANSI .. not valid in SDCC */ -
    { -
    ... -
    } - -

    - -

      +foo(i,j) /* this old style of function declarations */ +  +
      +int i,j; /* are valid in ANSI but not valid in SDCC */ +  +
      +{   +
      +    ...   +
      +}
    1. functions declared as pointers must be dereferenced during the call. - -

      -int (*foo)(); - -

      -

    2. -
    -   ... -
       /* has to be called like this */ -
       (*foo)();/* ansi standard allows calls to be made like 'foo()' -*/ +
      +
    +int (*foo)();  +
    +...   +
    +/* has to be called like this */   +
    +(*foo)(); /* ansi standard allows calls to be made like +'foo()' */ +

    -

    -4.8 Cyclomatic Complexity +

    +4.7 Cyclomatic Complexity

    @@ -3196,23 +3679,25 @@ is an important number since it defines the number test cases you have to generate to validate the function. The accepted industry standard for complexity number is 10, if the cyclomatic complexity reported by SDCC exceeds 10 you should think about simplification of the function -logic. +logic. Note that the complexity level is not related to the number +of lines of code in a function. Large functions can have low complexity, +and small functions can have large complexity levels. +
    -

    -Note that the complexity level is not related to the number of lines -of code in a function. Large functions can have low complexity, and -small functions can have large complexity levels. SDCC uses the following -formula to compute the complexity. +
    +SDCC uses the following formula to compute the complexity: +

    -complexity = (number of edges in control flow graph) - -
                 (number of nodes in control flow graph) + 2; +complexity = (number of edges in control flow graph) - (number of +nodes in control flow graph) + 2; +
    -

    +
    Having said that the industry standard is 10, you should be aware -that in some cases it may unavoidable to have a complexity level of -less than 10. For example if you have switch statement with more than -10 case labels, each case label adds one to the complexity level. +that in some cases it be may unavoidable to have a complexity level +of less than 10. For example if you have switch statement with more +than 10 case labels, each case label adds one to the complexity level. The complexity level is by no means an absolute measure of the algorithmic complexity of the function, it does however provide a good starting point for which functions you might look at for further optimization. @@ -3220,11 +3705,11 @@ point for which functions you might look at for further optimization.

    -5 TIPS +5. TIPS

    -Here are a few guide-lines that will help the compiler generate more +Here are a few guidelines that will help the compiler generate more efficient code, some of the tips are specific to this compiler others are generally good programming practice. @@ -3233,66 +3718,74 @@ are generally good programming practice.

    • Use the smallest data type to represent your data-value. If it is known in advance that the value is going to be less than 256 then -use a 'char' instead of a 'short' or 'int'. -
    • +use a 'char' instead of a 'short' or 'int'.
    • Use unsigned when it is known in advance that the value is not going to be negative. This helps especially if you are doing division or -multiplication. -
    • -
    • NEVER jump into a LOOP. -
    • +multiplication. +
    • NEVER jump into a LOOP.
    • Declare the variables to be local whenever possible, especially loop -control variables (induction). -
    • +control variables (induction).
    • Since the compiler does not do implicit integral promotion, the programmer -should do an explicit cast when integral promotion is required. -
    • +should do an explicit cast when integral promotion is required.
    • Reducing the size of division, multiplication & modulus operations -can reduce code size substantially. Take the following code for example. - -

      -foobar(unsigned int p1, unsigned char ch) -
      { -
          unsigned char ch1 = p1 % ch ; -
          ....     -
      } +can reduce code size substantially. Take the following code for example.  +
        +
      +foobar(unsigned int p1, unsigned char ch)  +
      +{  +
      + unsigned char ch1 = p1 % ch ;  +
      + ....   +
      +}  +
      -

      +
      For the modulus operation the variable ch will be promoted to unsigned int first then the modulus operation will be performed (this will -lead to a call to a support routine). If the code is changed to - -

      -foobar(unsigned int p1, unsigned char ch) -
      { -
          unsigned char ch1 = (unsigned char)p1 % ch ; -
          ....     -
      } +lead to a call to support routine _muduint()), and the result will +be casted to an int. If the code is changed to +
        +
      +foobar(unsigned int p1, unsigned char ch)  +
      +{  +
      + unsigned char ch1 = (unsigned char)p1 % ch ;  +
      + ....   +
      +}  +
      -

      +
      It would substantially reduce the code generated (future versions -of the compiler will be smart enough to detect such optimization oppurtunities). +of the compiler will be smart enough to detect such optimization oppurtunities).

    • +

    - - -Notes on MCS51 memory layout(Trefor@magera.freeserve.co.uk) + +

    +5.1 Notes on MCS51 memory layout +

    The 8051 family of micro controller have a minimum of 128 bytes of internal memory which is structured as follows +
    -

    +
    - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7 - -

    +
    - Bytes 20-2F - 16 bytes to hold 128 bit variables and - -

    +
    - Bytes 30-7F - 60 bytes for general purpose use. +
    -

    +
    Normally the SDCC compiler will only utilise the first bank of registers, but it is possible to specify that other banks of registers should be used in interrupt routines. By default, the compiler will place @@ -3316,18 +3809,19 @@ this from happening.

    The amount of stack being used is affected by the use of the "internal -stack" to save registers before a subroutine call is made, -- -stack-auto will declare parameters and local variables on the -stack - the number of nested subroutines. +stack" to save registers before a subroutine call is made +(-stack-auto will declare parameters and local variables on the stack) +and the number of nested subroutines.

    If you detect that the stack is over writing you data, then the following can be done. -xstack will cause an external stack to be used for saving registers and (if -stack-auto is being used) storing parameters -and local variables. However this will produce more and code which -will be slower to execute. +and local variables. However this will produce more code which will +be slower to execute.

    + -stack-loc will allow you specify the start of the stack, i.e. you could start it after any data in the general purpose area. However this may waste the memory not used by the register banks and if the @@ -3335,28 +3829,32 @@ size of the "near data" increases, it may creep into the bottom of the stack.

    + -stack-after-data, similar to the -stack-loc, but it automatically places the stack after the end of the "near data". Again this could waste any spare register space.

    + -data-loc allows you to specify the start address of the near data. This could be used to move the "near data" further away from the stack giving it more room to grow. This will only work if no bit variables are being used and the stack can grow to use the bit variable space. +
    -

    +
    Conclusion. +
    -

    +
    If you find that the stack is over writing your bit variables or "near data" then the approach which best utilised the internal memory is to position the "near data" after the last bank of used registers or, if you use bit variables, after the last bit variable by using the -data-loc, e.g. if two register banks -are being used and no data variables, -data-loc 16, and - use the --stack-after-data option. +are being used and no bit variables, -data-loc 16, and use the -stack-after-data +option.

    If bit variables are being used, another method would be to try and @@ -3366,7 +3864,7 @@ and start the stack after the last bit variable.

    -6 Retargetting for other MCUs. +6. Retargetting for other MCUs.

    @@ -3376,78 +3874,67 @@ of the seven phases of the compiler and its MCU dependency.

    -

      +
      • Parsing the source and building the annotated parse tree. This phase is largely MCU independent (except for the language extensions). Syntax & semantic checks are also done in this phase, along with some initial optimizations like back patching labels and the pattern matching optimizations -like bit-rotation etc. -
      • +like bit-rotation etc.
      • The second phase involves generating an intermediate code which can be easy manipulated during the later phases. This phase is entirely MCU independent. The intermediate code generation assumes the target machine has unlimited number of registers, and designates them with the name iTemp. The compiler can be made to dump a human readable -form of the code generated by using the -dumpraw option. -
      • +form of the code generated by using the -dumpraw option.
      • This phase does the bulk of the standard optimizations and is also -MCU independent. This phase can be broken down into several sub-phases. - -

        +MCU independent. This phase can be broken down into several sub-phases: +
        -

          -
        • Break down intermediate code (iCode) into basic blocks. -
        • -
        • Do control flow & data flow analysis on the basic blocks. -
        • -
        • Do local common subexpression elimination, then global subexpression +
          +Break down intermediate code (iCode) into basic blocks. +
          +Do control flow & data flow analysis on the basic blocks. +
          +Do local common subexpression elimination, then global subexpression elimination -
        • -
        • dead code elimination -
        • -
        • loop optimizations -
        • -
        • if loop optimizations caused any changes then do 'global subexpression -elimination' and 'dead code elimination' again. -
        • -
        -
      • +
        +Dead code elimination +
        +Loop optimizations +
        +If loop optimizations caused any changes then do 'global subexpression +elimination' and 'dead code elimination' again.
      • This phase determines the live-ranges; by live range I mean those iTemp variables defined by the compiler that still survive after all the optimizations. Live range analysis is essential for register allocation, since these computation determines which of these iTemps will be assigned -to registers, and for how long. -
      • +to registers, and for how long.
      • Phase five is register allocation. There are two parts to this process. +
        -

        - -

          -
        1. The first part I call 'register packing' (for lack of a better term). +
          +The first part I call 'register packing' (for lack of a better term). In this case several MCU specific expression folding is done to reduce register pressure. -
        2. -
        3. The second part is more MCU independent and deals with allocating +
          + +
          +The second part is more MCU independent and deals with allocating registers to the remaining live ranges. A lot of MCU specific code does creep into this phase because of the limited number of index -registers available in the 8051. -
        4. -
        -
      • +registers available in the 8051.
      • The Code generation phase is (unhappily), entirely MCU dependent and very little (if any at all) of this code can be reused for other MCU. However the scheme for allocating a homogenized assembler operand -for each iCode operand may be reused. -
      • +for each iCode operand may be reused.
      • As mentioned in the optimization section the peep-hole optimizer is -rule based system, which can reprogrammed for other MCUs. -
      • -
    +rule based system, which can reprogrammed for other MCUs. +

    -7 SDCDB - Source Level Debugger +7. SDCDB - Source Level Debugger

    @@ -3466,7 +3953,7 @@ source and at the ASM source level.

    -The -debug option must be specified for all files for which debug +The debug option must be specified for all files for which debug information is to be generated. The complier generates a .cdb file for each of these files. The linker updates the .cdb file with the address information. This .cdb is used by the debugger. @@ -3496,27 +3983,23 @@ commands for the simulator.

    The debugger can be started using the following command line. (Assume -the file you are debugging has - -

    -the file name foo). +the file you are debugging has the file name foo). +
    -

    ->sdcdb foo +
    +sdcdb foo +
    -

    +
    The debugger will look for the following files.

    -

      -
    1. foo.c - the source file. -
    2. -
    3. foo.cdb - the debugger symbol information file. -
    4. -
    5. foo.ihx - the intel hex format object file. -
    6. -
    +
      +
    • foo.c - the source file.
    • +
    • foo.cdb - the debugger symbol information file.
    • +
    • foo.ihx - the intel hex format object file.
    • +

    @@ -3533,22 +4016,17 @@ list specified for source, cdb & ihx files. The items in the directory list must be separated by ':', e.g. if the source files can be in the directories /home/src1 and /home/src2, the -directory option should be -directory=/home/src1:/home/src2. Note there can be no -spaces in the option. - -

  • -cd <directory> - change to the <directory>. -
  • -
  • -fullname - used by GUI front ends. -
  • +spaces in the option. +
  • -cd <directory> - change to the <directory>.
  • +
  • -fullname - used by GUI front ends.
  • -cpu <cpu-type> - this argument is passed to the simulator please -see the simulator docs for details. -
  • +see the simulator docs for details.
  • -X <Clock frequency > this options is passed to the simulator please -see simulator docs for details. -
  • -
  • -s <serial port file> passed to simulator see simulator docs for details. -
  • -
  • -S <serial in,out> passed to simulator see simulator docs for details. -
  • +see the simulator docs for details. +
  • -s <serial port file> passed to simulator see the simulator docs for +details.
  • +
  • -S <serial in,out> passed to simulator see the simulator docs for +details.
  • @@ -3559,8 +4037,8 @@ see simulator docs for details.

    As mention earlier the command interface for the debugger has been -deliberately kept as close the GNU debugger gdb, as possible, this -will help int integration with existing graphical user interfaces +deliberately kept as close the GNU debugger gdb, as possible. This +will help the integration with existing graphical user interfaces (like ddd, xxgdb or xemacs) existing for the GNU debugger.

    @@ -3570,16 +4048,17 @@ will help int integration with existing graphical user interfaces

    -Set breakpoint at specified line or function. +Set breakpoint at specified line or function: +
    -

    -sdcdb>break 100
    -sdcdb>break foo.c:100 +sdcdb>break 100 +
    +sdcdb>break foo.c:100
    -sdcdb>break funcfoo +sdcdb>break funcfoo
    -sdcdb>break foo.c:funcfoo +sdcdb>break foo.c:funcfoo

    @@ -3588,16 +4067,17 @@ sdcdb>break foo.c:funcfoo

    -Clear breakpoint at specified line or function. +Clear breakpoint at specified line or function: +
    -

    -sdcdb>clear 100
    -sdcdb>clear foo.c:100 +sdcdb>clear 100 +
    +sdcdb>clear foo.c:100
    -sdcdb>clear funcfoo +sdcdb>clear funcfoo
    -sdcdb>clear foo.c:funcfoo +sdcdb>clear foo.c:funcfoo

    @@ -3636,14 +4116,10 @@ user defined break points.

      -
    • info break - list all breakpoints -
    • -
    • info stack - show the function call stack. -
    • -
    • info frame - show information about the current execution frame. -
    • -
    • info registers - show content of all registers. -
    • +
    • info break - list all breakpoints
    • +
    • info stack - show the function call stack.
    • +
    • info frame - show information about the current execution frame.
    • +
    • info registers - show content of all registers.

    @@ -3738,6 +4214,7 @@ can loose its execution context and may display incorrect values.

    + "Watch me now. Iam going Down. My name is Bobby Brown"

    @@ -3747,93 +4224,133 @@ can loose its execution context and may display incorrect values.

    -Two files are (in emacs lisp) are provided for the interfacing with -XEmacs, sdcdb.el and sdcdbsrc.el. These two files can be found in -the $(prefix)/bin directory after the installation is complete. These -files need to be loaded into XEmacs for the interface to work, this -can be done at XEmacs startup time by inserting the following into -your '.xemacs' file (which can be found in your HOME directory) (load-file -sdcdbsrc.el) [ .xemacs is a lisp file so the () around the command -is REQUIRED), the files can also be loaded dynamically while XEmacs -is running, set the environment variable 'EMACSLOADPATH' to the installation -bin directory [$(prefix)/bin], then enter the following command -ESC-x load-file sdcdbsrc. To start the interface enter the following -command ESC-x sdcdbsrc, you will prompted to enter the file name to -be debugged. +Two files (in emacs lisp) are provided for the interfacing with XEmacs, +sdcdb.el and sdcdbsrc.el. These two files can be found in the $(prefix)/bin +directory after the installation is complete. These files need to +be loaded into XEmacs for the interface to work. This can be done +at XEmacs startup time by inserting the following into your '.xemacs' +file (which can be found in your HOME directory): +
    -

    +
    +(load-file sdcdbsrc.el) +
    + +
    +.xemacs is a lisp file so the () around the command is REQUIRED. The +files can also be loaded dynamically while XEmacs is running, set +the environment variable 'EMACSLOADPATH' to the installation bin directory +(<installdir>/bin), then enter the following command ESC-x load-file +sdcdbsrc. To start the interface enter the following command: +
    + +
    +ESC-x sdcdbsrc +
    + +
    +You will prompted to enter the file name to be debugged. +
    + +
    The command line options that are passed to the simulator directly -are bound to default values in the file sdcdbsrc.el the variables -are listed below these values maybe changed as required. +are bound to default values in the file sdcdbsrc.el. The variables +are listed below, these values maybe changed as required.

      -
    • sdcdbsrc-cpu-type '51 -
    • -
    • sdcdbsrc-frequency '11059200 -
    • -
    • sdcdbsrc-serial nil -
    • +
    • sdcdbsrc-cpu-type '51
    • +
    • sdcdbsrc-frequency '11059200
    • +
    • sdcdbsrc-serial nil
    The following is a list of key mapping for the debugger interface.

    -  -
    ;; Current Listing :: -
    ;;key               binding                      Comment - -
    ;;--               ----                      ---- - -
    ;; -
    ;; n               sdcdb-next-from-src          SDCDB -next command -
    ;; b               sdcdb-back-from-src          SDCDB -back command -
    ;; c               sdcdb-cont-from-src          SDCDB -continue command -
    ;; s               sdcdb-step-from-src          SDCDB -step command -
    ;; ?               sdcdb-whatis-c-sexp          SDCDB -ptypecommand for data at -
    ;;                                           -buffer point -
    ;; x               sdcdbsrc-delete              SDCDB -Delete all breakpoints if no arg -
    ;;                                              given -or delete arg (C-u arg x) -
    ;; m               sdcdbsrc-frame               SDCDB -Display current frame if no arg, -
    ;;                                              given -or display frame arg -
    ;;                                             buffer -point -
    ;; !               sdcdbsrc-goto-sdcdb          Goto -the SDCDB output buffer -
    ;; p               sdcdb-print-c-sexp           SDCDB -print command for data at -
    ;;                                           -buffer point -
    ;; g               sdcdbsrc-goto-sdcdb          Goto -the SDCDB output buffer -
    ;; t               sdcdbsrc-mode                Toggles -Sdcdbsrc mode (turns it off) -
    ;; -
    ;; C-c C-f         sdcdb-finish-from-src        SDCDB -finish command -
    ;; -
    ;; C-x SPC         sdcdb-break                  Set -break for line with point -
    ;; ESC t           sdcdbsrc-mode                Toggle -Sdcdbsrc mode -
    ;; ESC m           sdcdbsrc-srcmode             -Toggle list mode -
    ;; + +   +
    +;; Current Listing ::   +
    +;;key               binding                      Comment +  +
    +;;--               ----                      ---- +  +
    +;;   +
    +;; n               sdcdb-next-from-src          SDCDB +next command   +
    +;; b               sdcdb-back-from-src          SDCDB +back command   +
    +;; c               sdcdb-cont-from-src          SDCDB +continue command  +
    +;; s               sdcdb-step-from-src          SDCDB +step command   +
    +;; ?               sdcdb-whatis-c-sexp          SDCDB +ptypecommand for data at   +
    +;;                                               +buffer point   +
    +;; x               sdcdbsrc-delete              SDCDB +Delete all breakpoints if no arg   +
    +;;                                              given +or delete arg (C-u arg x)   +
    +;; m               sdcdbsrc-frame               SDCDB +Display current frame if no arg,  
    +;;                                               given +or display frame arg   +
    +;;                                               buffer +point   +
    +;; !               sdcdbsrc-goto-sdcdb          Goto +the SDCDB output buffer   +
    +;; p               sdcdb-print-c-sexp           SDCDB +print command for data at   +
    +;;                                               +buffer point   +
    +;; g               sdcdbsrc-goto-sdcdb          Goto +the SDCDB output buffer   +
    +;; t               sdcdbsrc-mode                Toggles +Sdcdbsrc mode (turns it off)   +
    +;;   +
    +;; C-c C-f         sdcdb-finish-from-src        SDCDB +finish command   +
    +;;   +
    +;; C-x SPC         sdcdb-break                  Set +break for line with point   +
    +;; ESC t           sdcdbsrc-mode                Toggle +Sdcdbsrc mode   +
    +;; ESC m           sdcdbsrc-srcmode             +Toggle list mode   +
    +;; +
    +

    -8 Other Processors +8. Other Processors

    @@ -3846,7 +4363,7 @@ Toggle list mode SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80. The port is incomplete - long support is incomplete (mul, div and mod are unimplimented), and both float and bitfield support is -missing, but apart from that the code generated is correct. +missing. Apart from that the code generated is correct.

    As always, the code is the authoritave reference - see z80/ralloc.c @@ -3860,16 +4377,16 @@ is limited to 127 bytes - this will be fixed in a later version.

    -9 Support +9. Support

    -SDCC has grown to be large project, the compiler alone (without the -Assembler Package, Preprocessor) is about 40,000 lines of code (blank -stripped). The open source nature of this project is a key to its -continued growth and support. You gain the benefit and support of -many active software developers and end users. Is SDCC perfect? No, -that's why we need your help. The developers take pride in fixing +SDCC has grown to be a large project. The compiler alone (without +the preprocessor, assembler and linker) is about 40,000 lines of code +(blank stripped). The open source nature of this project is a key +to its continued growth and support. You gain the benefit and support +of many active software developers and end users. Is SDCC perfect? +No, that's why we need your help. The developers take pride in fixing reported bugs. You can help by reporting the bugs and helping other SDCC users. There are lots of ways to contribute, and we encourage you to take part in making SDCC a great software package. @@ -3891,13 +4408,13 @@ locating optimization problems.

    -

    -9.2 Acknowledgments -

    +

    +10. Acknowledgments +

    -Sandeep Dutta(sandeep.dutta@usa.net) - SDCC, the compiler, MCS51 code -generator, Debugger, AVR port +Sandeep Dutta (sandeep.dutta@usa.net) - SDCC, the compiler, MCS51 +code generator, Debugger, AVR port
    Alan Baldwin (baldwin@shop-pdp.kent.edu) - Initial version of ASXXXX & ASLINK. @@ -3907,7 +4424,7 @@ John Hartman (jhartman@compuserve.com) - Porting ASXXX & ASLINK for
    Dmitry S. Obukhov (dso@usa.net) - malloc & serial i/o routines.
    -Daniel Drotos <drdani@mazsola.iit.uni-miskolc.hu> - for his Freeware +Daniel Drotos (drdani@mazsola.iit.uni-miskolc.hu) - for his Freeware simulator
    Malini Dutta(malini_dutta@hotmail.com) - my wife for her patience @@ -3919,29 +4436,41 @@ Michael Hope - The Z80 and Z80GB port, 186 development
    Kevin Vigor - The DS390 port.
    -Johan Knol - DS390/TINI libs, lots of fixes and enhancements. +Johan Knol - Lots of fixes and enhancements, DS390/TINI libs. +
    +Scott Datallo - The PIC port.
    -Scott Datallo - PIC port. -
    (Thanks to all the other volunteer developers who have helped with -coding, testing, web-page creation, distribution sets, etc. You know -who you are :-) +
    +Thanks to all the other volunteer developers who have helped +with coding, testing, web-page creation, distribution sets, etc. You +know who you are :-) +
    +

    -This document initially written by Sandeep Dutta +This document was initially written by Sandeep Dutta

    All product names mentioned herein may be trademarks of their respective companies.

    - +
    -

    +

    +Index +

    +
    index +
    1.7 Wishes for the + +
    + +

    About this document ...

    - lSDCC Compiler User Guide

    + SDCC Compiler User Guide

    This document was generated using the -LaTeX2HTML translator Version 2K.1beta (1.47) +LaTeX2HTML translator Version 99.1 release (March 30, 1999)

    Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, @@ -3952,13 +4481,13 @@ Copyright © 1997, 1998, 1999, Mathematics Department, Macquarie University, Sydney.

    The command line arguments were:
    - latex2html -no_subdir -split 0 -show_section_numbers /tmp/lyx_tmpdir1913F54AWM/lyx_tmpbuf1913544rwj/SDCCUdoc.tex + latex2html -split 0 -show_section_numbers -dir fullhtml SDCCUdoc

    -The translation was initiated by Karl Bongers on 2001-07-05 +The translation was initiated by Johan Knol on 2001-07-07


    Footnotes

    -
    ... -anyway... +anyway1
    possible exception: if a function is called ONLY from 'interrupt' functions using a particular bank, it can be declared with the same @@ -3971,17 +4500,17 @@ to the stack on entry and switch to bank zero before calling the function

    -next_inactive +next_group up + SRC="/home/johan/latex2html/icons.gif/up_motif_gr.gif"> previous + SRC="/home/johan/latex2html/icons.gif/previous_motif_gr.gif">
    -Karl Bongers -2001-07-05 +Johan Knol +
    2001-07-07
    diff --git a/doc/SDCCUdoc.lyx b/doc/SDCCUdoc.lyx index 2a3f5128..d615fcbe 100644 --- a/doc/SDCCUdoc.lyx +++ b/doc/SDCCUdoc.lyx @@ -20,11 +20,11 @@ \quotes_times 2 \papercolumns 1 \papersides 1 -\paperpagestyle default +\paperpagestyle fancy \layout Title -lSDCC Compiler User Guide +SDCC Compiler User Guide \layout Standard @@ -42,71 +42,112 @@ About SDCC \layout Standard -\emph on - -\newline - -\newline - \series bold -\emph default SDCC \series default - is a Free ware, retargettable, optimizing ANSI-C compiler by + is a Freeware, retargettable, optimizing ANSI-C compiler by \series bold Sandeep Dutta \series default designed for 8 bit Microprocessors. The current version targets Intel MCS51 based Microprocessors(8051,8052, - etc), Zilog Z80 based MCUs, and the Dallas 80C390 MCS51 variant. + etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant. It can be retargetted for other microprocessors, support for PIC, AVR and 186 is under development. The entire source code for the compiler is distributed under GPL. SDCC uses ASXXXX & ASLINK, a Freeware, retargettable assembler & linker. SDCC has extensive language extensions suitable for utilizing various microcont -rollers underlying hardware effectively. - In addition to the MCU specific optimizations SDCC also does a host of - standard optimizations like -\emph on - global sub expression elimination, loop optimizations (loop invariant, - strength reduction of induction variables and loop reversing), constant - folding & propagation, copy propagation, dead code elimination and jumptables - for 'switch' statements. +rollers and underlying hardware effectively. +\newline + +\newline +In addition to the MCU specific optimizations SDCC also does a host of standard + optimizations like: +\layout Itemize + +global sub expression elimination, +\layout Itemize + +loop optimizations (loop invariant, strength reduction of induction variables + and loop reversing), +\layout Itemize + +constant folding & propagation, +\layout Itemize + +copy propagation, +\layout Itemize + +dead code elimination +\layout Itemize + +jumptables for +\emph on +switch \emph default + statements. +\layout Standard + For the back-end SDCC uses a global register allocation scheme which should be well suited for other 8 bit MCUs. - The peep hole optimizer uses a rule based substitution mechanism which - is MCU dependent. - Supported data-types are -\emph on -char (8 bits, 1 byte), short and int (16 bits, 2 bytes), long (32 bit, 4 - bytes) -\emph default -and -\emph on - float (4 byte IEEE). -\emph default +\newline + +\newline +The peep hole optimizer uses a rule based substitution mechanism which is + MCU independent. + +\newline + +\newline +Supported data-types are: +\layout Itemize + +char (8 bits, 1 byte), +\layout Itemize + +short and int (16 bits, 2 bytes), +\layout Itemize + +long (32 bit, 4 bytes) +\layout Itemize + +float (4 byte IEEE). + +\layout Standard + The compiler also allows \emph on inline assembler code \emph default to be embedded anywhere in a function. - In addition routines developed in assembly can also be called. - SDCC also provides an option to report the relative complexity of a function, - these functions can then be further optimized, or hand coded in assembly + In addition, routines developed in assembly can also be called. +\newline + +\newline +SDCC also provides an option (--cyclomatic) to report the relative complexity + of a function. + These functions can then be further optimized, or hand coded in assembly if needed. - SDCC also comes with a companion source level debugger SDCDB, the debugger + +\newline + +\newline +SDCC also comes with a companion source level debugger SDCDB, the debugger currently uses ucSim a freeware simulator for 8051 and other micro-controllers. - The latest version can be downloaded from -\series bold + +\newline +\newline +The latest version can be downloaded from \begin_inset LatexCommand \htmlurl{http://sdcc.sourceforge.net/} \end_inset - . + +\series bold +. \layout Subsection Open Source @@ -140,12 +181,6 @@ This program is free software; you can redistribute it and/or modify it You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! -\newline - -\newline - -\emph on - \layout Subsection Typographic conventions @@ -170,30 +205,55 @@ typewriter font. italicised type. \layout Subsection -Pending: compatibilaty with previous versions +Compatibility with previous versions \layout Standard -This version has numerous bug fixes comperated with the previous version. - But we also introduced some incompatibilaties with older versions. +This version has numerous bug fixes compared with the previous version. + But we also introduced some incompatibilities with older versions. Not just for the fun of it, but to make the compiler more stable, efficient and ANSI compliant. \newline +\layout Itemize + +short is now equivalent to int (16 bits), it used to be equivalent to char + (8 bits) +\layout Itemize + +the default directory where include, library and documention files are stored + is no in /usr/local/share +\layout Itemize + +char type parameters to vararg functions are casted to int unless explicitly + casted, e.g.: \newline -short char -\newline -directory structure (2.7) -\newline -vararg pars expl int unless casted -\newline -never had a regextend -\newline -no --noreparms anymore + +\family typewriter +\SpecialChar ~ +\SpecialChar ~ +char a=3; \newline +\SpecialChar ~ +\SpecialChar ~ +printf ("%d %c +\backslash +n", a, (char)a); +\family default \newline -more? + will push a as an int and as a char resp. +\layout Itemize + +option --regextend has been removed +\layout Itemize + +option --noreparms has been removed +\layout Standard + + +\emph on + \layout Subsection System Requirements @@ -202,7 +262,7 @@ System Requirements What do you need before you start installation of SDCC? A computer, and a desire to compute. The preferred method of installation is to compile SDCC from source using - GNU GCC and make. + GNU gcc and make. For Windows some pre-compiled binary distributions are available for your convenience. You should have some experience with command line tools and compiler use. @@ -226,6 +286,48 @@ The SDCC home page at their own documentation and can be found in the source distribution. If you want the latest unreleased software, the complete source package is available directly by anonymous CVS on cvs.sdcc.sourceforge.net. +\layout Subsection + +Wishes for the future +\layout Standard + +There are (and always will be) some things that could be done. + Here are some I can think of: +\newline + +\layout Standard + + +\family sans +\series bold +sdcc -c --model-large -o large _atoi.c +\family default +\series default + (where large could be a different basename or a directory) +\newline + +\layout Standard + + +\family typewriter +char KernelFunction3(char p) at 0x340; +\newline + +\newline + +\family default +If you can think of some more, please send them to the list. +\newline + +\newline + +\emph on + \layout Section Installation @@ -249,8 +351,10 @@ Bring up a command line terminal, such as xterm. Unpack the file using a command like: \family sans \series bold -"tar -xzf sdcc-2.x.x.tgz" +"tar -xzf sdcc-2.x.x.tgz \family default +\series default +" \series medium , this will create a sub-directory called sdcc with all of the sources. \layout Enumerate @@ -258,9 +362,9 @@ Unpack the file using a command like: Change directory into the main SDCC directory, for example type: \family sans \series bold -"cd sdcc" +"cd sdcc \series default -. +". \layout Enumerate @@ -268,10 +372,10 @@ Change directory into the main SDCC directory, for example type: Type \family sans \series bold -"./configure" +"./configure \family default \series default -. +". This configures the package for compilation on your system. \layout Enumerate @@ -280,8 +384,10 @@ Type Type \family sans \series bold -"make" +"make \family default +\series default +" \series medium . @@ -302,7 +408,8 @@ Type . \series default - This copies the binary executables to the install directories. + This copies the binary executables, the include files, the libraries and + the documentation to the install directories. \layout Subsection Windows Installation @@ -472,8 +579,7 @@ SDCC binaries are commonly installed in a directory arrangement like this: \newline -\layout Standard - +\newline \begin_inset Tabular @@ -572,12 +678,32 @@ Make sure the compiler works on a very simple example. \newline +\family typewriter +\emph default +int test(int t) { +\newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +return t+3; +\newline +} +\family default + +\newline + +\emph on + +\newline + \series medium \emph default Compile this using the following command: \family sans \series bold -"sdcc -c test.c" +"sdcc -c test.c". + \family default \series default @@ -597,8 +723,10 @@ The next step is to try it with the linker. Type in \family sans \series bold -"sdcc test.c" +"sdcc test.c \family default +\series default +" \series medium . If all goes well the compiler will link with the libraries and produce @@ -1029,7 +1157,7 @@ The command \family default \series default -will configure the compiler to be installed in directory /usr/local/bin. +will configure the compiler to be installed in directory /usr/local. \layout Subsection Components of SDCC @@ -1042,78 +1170,71 @@ SDCC is not just a compiler, but a collection of tools by various developers. which you can find in the source package in their respective directories. As SDCC grows to include support for other processors, other packages from various developers are included and may have their own sets of documentation. -\layout Standard +\newline -You might want to look at the various executables which are installed in - the bin directory. +\newline +You might want to look at the files which are installed in . At the time of this writing, we find the following programs: \newline - + \newline +In /bin: +\layout Itemize -\emph on - -\emph default +sdcc - The compiler. +\layout Itemize -\newline +sdcpp - The C preprocessor. +\layout Itemize -\newline +asx8051 - The assembler for 8051 type processors. +\layout Itemize +as-z80 \series bold -sdcc +, \series default - - The compiler. -\newline +as-gbz80 - The Z80 and GameBoy Z80 assemblers. +\layout Itemize -\series bold -sdcpp -\series default - - The C preprocessor. -\newline +aslink -The linker for 8051 type processors. +\layout Itemize +link-z80 \series bold -asx8051 +, \series default - - The assembler for 8051 type processors. -\newline +link-gbz80 - The Z80 and GameBoy Z80 linkers. +\layout Itemize -\series bold -as-z80, as-gbz80 -\series default - - The Z80 and GameBoy Z80 assemblers. -\newline +s51 - The ucSim 8051 simulator. +\layout Itemize -\series bold -aslink -\series default - -The linker for 8051 type processors. -\newline +sdcdb - The source debugger. +\layout Itemize -\series bold -link-z80, link-gbz80 -\series default - - The Z80 and GameBoy Z80 linkers. -\newline +packihx - A tool to pack Intel hex files. +\layout Standard -\series bold -s51 -\series default - - The ucSim 8051 simulator. -\newline +In /share/sdcc/include +\layout Itemize -\series bold -sdcdb -\series default - - The source debugger. -\newline +the include files +\layout Standard -\series bold -packihx -\series default - - A tool to pack Intel hex files. -\newline +In /share/sdcc/lib +\layout Itemize + +the sources of the runtime library and the subdirs small large and ds390 + with the precompiled relocatables. +\layout Standard + +In /share/sdcc/doc +\layout Itemize + +the documentation +\layout Standard -\newline As development for other processors proceeds, this list will expand to include executables to support processors like AVR, PIC, etc. \layout Subsubsection @@ -4363,8 +4484,9 @@ SDCC changes switch statements to jump tables when the following conditions The case labels are in numerical sequence, the labels need not be in order, and the starting number need not be one or zero. -\layout Standard +\newline +\newline \family typewriter switch(i) {\SpecialChar ~ @@ -4593,6 +4715,8 @@ g. possible, e.g.: \newline +\family typewriter + \newline unsigned char i; \newline @@ -4604,10 +4728,14 @@ i>>= 4; ... \newline +\family default + \newline generates the following code: \newline +\family typewriter + \newline mov a,_i \newline @@ -4616,6 +4744,8 @@ swap a anl a,#0x0f \newline mov _i,a +\family default + \newline \newline @@ -5210,6 +5340,8 @@ The optimizer will apply to the rules one by one from the top in the sequence \newline \newline + +\family typewriter replace restart { \newline \SpecialChar ~ @@ -5225,6 +5357,8 @@ push %1 } by { ; nop \newline } +\family default + \newline \newline @@ -5262,10 +5396,16 @@ would result in: \newline \family typewriter +\SpecialChar ~ +\SpecialChar ~ pop ar1 \newline +\SpecialChar ~ +\SpecialChar ~ ; nop \newline +\SpecialChar ~ +\SpecialChar ~ push ar1 \family default @@ -5283,8 +5423,12 @@ with \newline \family typewriter +\SpecialChar ~ +\SpecialChar ~ ; nop \newline +\SpecialChar ~ +\SpecialChar ~ ; nop \family default @@ -5306,14 +5450,18 @@ replace { \SpecialChar ~ ljmp %5 \newline -%2:} by { +%2: +\newline +} by { \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ sjmp %5 \newline -%2:} if labelInRange +%2: +\newline +} if labelInRange \family default \newline @@ -5348,12 +5496,6 @@ g the variable bindings is passed as a parameter). If you are looking at this file, you will also see the default rules that are compiled into the compiler, you can add your own rules in the default set there if you get tired of specifying the --peep-file option. -\newline - -\newline - -\emph on - \layout Subsection Pragmas @@ -5423,13 +5565,12 @@ The pragma's are intended to be used to turn-off certain optimizations which are used to control options & optimizations for a given function; pragmas should be placed before and/or after a function, placing pragma's inside a function body could have unpredictable results. -\layout Standard +\newline -eg -\layout Standard +\newline -#pragma SAVE \SpecialChar ~ - /* save the current settings */ +\family typewriter +#pragma SAVE /* save the current settings */ \newline #pragma NOGCSE /* turnoff global subexpression elimination */ \newline @@ -5456,14 +5597,21 @@ int foo () } \newline #pragma RESTORE /* turn the optimizations back on */ -\layout Standard +\family default + +\newline +\newline The compiler will generate a warning message when extra space is allocated. It is strongly recommended that the SAVE and RESTORE pragma's be used when changing options for a function. \layout Subsection -Library Routines + +\emph on + +\emph default + Library Routines \layout Standard The following library routines are provided for your convenience. @@ -6493,22 +6641,23 @@ Have not had time to do the more involved routines like printf, will get \layout Subsection Interfacing with Assembly Routines -\layout Subsection +\layout Subsubsection Global Registers used for Parameter Passing \layout Standard -By default the compiler uses the global registers -\begin_inset Quotes eld -\end_inset - -DPL,DPH,B,ACC -\begin_inset Quotes erd -\end_inset - - to pass the first parameter to a routine, the second parameter onwards - is either allocated on the stack (for reentrant routines or --stack-auto - is used) or in the internal / external ram (depending on the memory model). +The compiler always uses the global registers +\emph on +DPL,DPH,B +\emph default +and +\emph on + ACC +\emph default + to pass the first parameter to a routine. + The second parameter onwards is either allocated on the stack (for reentrant + routines or if --stack-auto is used) or in the internal / external ram + (depending on the memory model). \layout Subsubsection @@ -6517,52 +6666,52 @@ Assembler Routine(non-reentrant) In the following example the function cfunc calls an assembler routine asm_func, which takes two parameters. -\layout Standard +\newline -extern int asm_func(unsigned char, unsigned char); -\layout Standard +\newline -\SpecialChar ~ +\family typewriter +extern int asm_func(unsigned char, unsigned char); +\newline \newline -int c_func (unsigned char i, unsigned char j) +int c_func (unsigned char i, unsigned char j) \newline -{ +{ \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - return asm_func(i,j); +return asm_func(i,j); \newline -} +} \newline -int main() + \newline -{ +int main() +\newline +{ \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -return c_func(10,9); +\SpecialChar ~ +return c_func(10,9); \newline } -\layout Standard +\newline -The corresponding assembler function is:- -\layout Standard +\newline -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - .globl _asm_func_PARM_2 +\family default +The corresponding assembler function is: +\newline + +\newline + +\family typewriter +.globl _asm_func_PARM_2 \newline \SpecialChar ~ \SpecialChar ~ @@ -6571,7 +6720,8 @@ The corresponding assembler function is:- \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ - .globl _asm_func +\SpecialChar ~ +.globl _asm_func \newline \SpecialChar ~ \SpecialChar ~ @@ -6580,20 +6730,20 @@ The corresponding assembler function is:- \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ - .area OSEG -\newline -_asm_func_PARM_2:\SpecialChar ~ \SpecialChar ~ +.area OSEG +\newline +_asm_func_PARM_2: +\newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ - .ds\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ - 1 +.ds 1 \newline \SpecialChar ~ \SpecialChar ~ @@ -6602,7 +6752,8 @@ _asm_func_PARM_2:\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ - .area CSEG +\SpecialChar ~ +.area CSEG \newline _asm_func: \newline @@ -6612,12 +6763,9 @@ _asm_func: \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ - a,dpl +mov a,dpl \newline \SpecialChar ~ \SpecialChar ~ @@ -6625,12 +6773,9 @@ _asm_func: \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ - add\SpecialChar ~ -\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ - a,_asm_func_PARM_2 +add a,_asm_func_PARM_2 \newline \SpecialChar ~ \SpecialChar ~ @@ -6638,12 +6783,9 @@ _asm_func: \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ - dpl,a +mov dpl,a \newline \SpecialChar ~ \SpecialChar ~ @@ -6651,12 +6793,9 @@ _asm_func: \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ -\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ - dpl,#0x00 +mov dpl,#0x00 \newline \SpecialChar ~ \SpecialChar ~ @@ -6665,9 +6804,13 @@ _asm_func: \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ - ret -\layout Standard +\SpecialChar ~ +ret +\newline + +\newline +\family default Note here that the return values are placed in 'dpl' - One byte return value, 'dpl' LSB & 'dph' MSB for two byte values. 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph',' @@ -6708,20 +6851,33 @@ acc,b,dptr \begin_inset Quotes erd \end_inset - for four bytes, the varaible name for the second parameter will be __PARM_2. -\layout Standard + for four bytes, the varible name for the second parameter will be __PARM_2. +\newline -Assemble the assembler routine with the following command. -\layout Standard +\newline +Assemble the assembler routine with the following command: +\newline + +\newline +\family sans +\series bold asx8051 -losg asmfunc.asm -\layout Standard +\newline +\newline + +\family default +\series default Then compile and link the assembler routine to the C source file with the - following command, -\layout Standard + following command: +\newline +\newline + +\family sans +\series bold sdcc cfunc.c asmfunc.rel \layout Subsubsection @@ -6731,16 +6887,16 @@ Assembler Routine(reentrant) In this case the second parameter onwards will be passed on the stack, the parameters are pushed from right to left i.e. after the call the left most parameter will be on the top of the stack. - Here is an example. -\layout Standard - -extern int asm_func(unsigned char, unsigned char); -\layout Standard + Here is an example: +\newline -\SpecialChar ~ +\newline -\layout Standard +\family typewriter +extern int asm_func(unsigned char, unsigned char); +\newline +\newline int c_func (unsigned char i, unsigned char j) reentrant \newline { @@ -6749,12 +6905,11 @@ int c_func (unsigned char i, unsigned char j) reentrant \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - return asm_func(i,j); +return asm_func(i,j); \newline } +\newline + \newline int main() \newline @@ -6763,22 +6918,22 @@ int main() \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ +\SpecialChar ~ return c_func(10,9); \newline } -\layout Standard +\newline -The corresponding assembler routine is. -\layout Standard +\family default -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - .globl _asm_func +\newline +The corresponding assembler routine is: +\newline + +\newline + +\family typewriter +.globl _asm_func \newline _asm_func: \newline @@ -6786,163 +6941,102 @@ _asm_func: \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - push\SpecialChar ~ - _bp +push _bp \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ - _bp,sp +mov _bp,sp \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -mov\SpecialChar ~ - r2,dpl +mov r2,dpl \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ - a,_bp +mov a,_bp \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - clr\SpecialChar ~ - c +clr c \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - add\SpecialChar ~ - a,#0xfd +add a,#0xfd \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ - r0,a +mov r0,a \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - add\SpecialChar ~ - a,#0xfc +add a,#0xfc \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ - r1,a +mov r1,a \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ - a,@r0 +mov a,@r0 \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - add\SpecialChar ~ - a,r2 +add a,r2 \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ - dpl,a +mov dpl,a \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ - dph,#0x00 +mov dph,#0x00 \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - mov\SpecialChar ~ - sp,_bp +mov sp,_bp \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - pop\SpecialChar ~ - _bp +pop _bp \newline \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - ret -\layout Standard +ret +\newline +\newline + +\family default The compiling and linking procedure remains the same, however note the extra entry & exit linkage required for the assembler code, _bp is the stack frame pointer and is used to compute the offset into the stack for parameters @@ -6971,21 +7065,19 @@ ANSI-Compliance \layout Standard Deviations from the compliancy. -\layout Enumerate +\layout Itemize functions are not always reentrant. -\layout Enumerate +\layout Itemize structures cannot be assigned values directly, cannot be passed as function parameters or assigned to each other and cannot be a return value from - a function. -\begin_deeper -\layout Standard + a function, e.g.: +\family typewriter -eg -\end_deeper -\layout Standard +\newline +\newline struct s { ... }; \newline @@ -6995,84 +7087,100 @@ foo() \newline { \newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ ... \newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */ \newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ ... \newline } -\layout Standard - +\newline struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in ANSI */ \newline { \newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ struct s rets; \newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ ... \newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ return rets;/* is invalid in SDCC although allowed in ANSI */ \newline } -\layout Enumerate +\layout Itemize 'long long' (64 bit integers) not supported. -\layout Enumerate +\layout Itemize 'double' precision floating point not supported. -\layout Enumerate - -integral promotions are suppressed. - What does this mean ? The compiler will not implicitly promote an integer - expression to a higher order integer, exception is an assignment or parameter - passing. - -\layout Enumerate +\layout Itemize No support for setjmp and longjmp (for now). -\layout Enumerate +\layout Itemize Old K&R style function declarations are NOT allowed. -\layout Standard +\newline + +\family typewriter +\newline foo(i,j) /* this old style of function declarations */ \newline -int i,j; /* are valid in ANSI .. - not valid in SDCC */ +int i,j; /* are valid in ANSI but not valid in SDCC */ \newline { \newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ ... \newline } -\layout Enumerate +\layout Itemize functions declared as pointers must be dereferenced during the call. -\begin_deeper -\layout Standard +\newline -int (*foo)(); -\end_deeper -\layout Standard +\family typewriter -\SpecialChar ~ - \SpecialChar ~ +\newline +int (*foo)(); +\newline ... \newline -\SpecialChar ~ - \SpecialChar ~ /* has to be called like this */ \newline -\SpecialChar ~ - \SpecialChar ~ -(*foo)();/* ansi standard allows calls to be made like 'foo()' */ +(*foo)(); /* ansi standard allows calls to be made like 'foo()' */ \layout Subsection Cyclomatic Complexity @@ -7085,29 +7193,27 @@ Cyclomatic complexity of a function is defined as the number of independent The accepted industry standard for complexity number is 10, if the cyclomatic complexity reported by SDCC exceeds 10 you should think about simplification of the function logic. -\layout Standard - -Note that the complexity level is not related to the number of lines of + Note that the complexity level is not related to the number of lines of code in a function. Large functions can have low complexity, and small functions can have large complexity levels. - SDCC uses the following formula to compute the complexity. -\layout Standard + +\newline -complexity = (number of edges in control flow graph) - \newline -\SpecialChar ~ - \SpecialChar ~ - \SpecialChar ~ - \SpecialChar ~ - \SpecialChar ~ - \SpecialChar ~ - \SpecialChar ~ -(number of nodes in control flow graph) + 2; +SDCC uses the following formula to compute the complexity: +\newline + \layout Standard +complexity = (number of edges in control flow graph) - (number of nodes + in control flow graph) + 2; +\newline + +\newline Having said that the industry standard is 10, you should be aware that in - some cases it may unavoidable to have a complexity level of less than 10. + some cases it be may unavoidable to have a complexity level of less than + 10. For example if you have switch statement with more than 10 case labels, each case label adds one to the complexity level. The complexity level is by no means an absolute measure of the algorithmic @@ -7118,7 +7224,7 @@ Having said that the industry standard is 10, you should be aware that in TIPS \layout Standard -Here are a few guide-lines that will help the compiler generate more efficient +Here are a few guidelines that will help the compiler generate more efficient code, some of the tips are specific to this compiler others are generally good programming practice. \layout Itemize @@ -7147,83 +7253,72 @@ Since the compiler does not do implicit integral promotion, the programmer Reducing the size of division, multiplication & modulus operations can reduce code size substantially. Take the following code for example. -\begin_deeper -\layout Standard +\family typewriter + +\newline +\newline foobar(unsigned int p1, unsigned char ch) \newline { \newline -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -unsigned char ch1 = p1 % ch ; + unsigned char ch1 = p1 % ch ; \newline -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -....\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - + .... + \newline } -\layout Standard +\newline + +\family default +\newline For the modulus operation the variable ch will be promoted to unsigned int first then the modulus operation will be performed (this will lead to a - call to a support routine). + call to support routine _muduint()), and the result will be casted to an + int. If the code is changed to -\layout Standard +\newline + +\family typewriter +\newline foobar(unsigned int p1, unsigned char ch) \newline { \newline -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -unsigned char ch1 = (unsigned char)p1 % ch ; + unsigned char ch1 = (unsigned char)p1 % ch ; \newline -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -....\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ -\SpecialChar ~ - + .... + \newline } -\layout Standard +\newline + +\family default +\newline It would substantially reduce the code generated (future versions of the compiler will be smart enough to detect such optimization oppurtunities). -\end_deeper -\layout Standard +\layout Subsection -Notes on MCS51 memory layout(Trefor@magera.freeserve.co.uk) +Notes on MCS51 memory layout \layout Standard The 8051 family of micro controller have a minimum of 128 bytes of internal memory which is structured as follows -\layout Standard +\newline +\newline - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7 -\layout Standard - +\newline - Bytes 20-2F - 16 bytes to hold 128 bit variables and -\layout Standard - +\newline - Bytes 30-7F - 60 bytes for general purpose use. -\layout Standard +\newline +\newline Normally the SDCC compiler will only utilise the first bank of registers, but it is possible to specify that other banks of registers should be used in interrupt routines. @@ -7250,16 +7345,16 @@ If any of the 128 bit variables are used, or near data is being used then \layout Standard The amount of stack being used is affected by the use of the "internal stack" - to save registers before a subroutine call is made, - --stack-auto will - declare parameters and local variables on the stack - the number of nested - subroutines. + to save registers before a subroutine call is made (--stack-auto will declare + parameters and local variables on the stack) and the number of nested subroutin +es. \layout Standard If you detect that the stack is over writing you data, then the following can be done. --xstack will cause an external stack to be used for saving registers and (if --stack-auto is being used) storing parameters and local variables. - However this will produce more and code which will be slower to execute. + However this will produce more code which will be slower to execute. \layout Standard @@ -7280,17 +7375,19 @@ If you detect that the stack is over writing you data, then the following giving it more room to grow. This will only work if no bit variables are being used and the stack can grow to use the bit variable space. -\layout Standard +\newline +\newline Conclusion. -\layout Standard +\newline +\newline If you find that the stack is over writing your bit variables or "near data" then the approach which best utilised the internal memory is to position the "near data" after the last bank of used registers or, if you use bit variables, after the last bit variable by using the --data-loc, e.g. - if two register banks are being used and no data variables, --data-loc - 16, and - use the --stack-after-data option. + if two register banks are being used and no bit variables, --data-loc 16, + and use the --stack-after-data option. \layout Standard If bit variables are being used, another method would be to try and squeeze @@ -7305,14 +7402,14 @@ The issues for retargetting the compiler are far too numerous to be covered by this document. What follows is a brief description of each of the seven phases of the compiler and its MCU dependency. -\layout Enumerate +\layout Itemize Parsing the source and building the annotated parse tree. This phase is largely MCU independent (except for the language extensions). Syntax & semantic checks are also done in this phase, along with some initial optimizations like back patching labels and the pattern matching optimizations like bit-rotation etc. -\layout Enumerate +\layout Itemize The second phase involves generating an intermediate code which can be easy manipulated during the later phases. @@ -7321,33 +7418,27 @@ The second phase involves generating an intermediate code which can be easy number of registers, and designates them with the name iTemp. The compiler can be made to dump a human readable form of the code generated by using the --dumpraw option. -\layout Enumerate +\layout Itemize This phase does the bulk of the standard optimizations and is also MCU independe nt. - This phase can be broken down into several sub-phases. -\begin_deeper -\layout Itemize + This phase can be broken down into several sub-phases: +\newline +\newline Break down intermediate code (iCode) into basic blocks. -\layout Itemize - +\newline Do control flow & data flow analysis on the basic blocks. -\layout Itemize - +\newline Do local common subexpression elimination, then global subexpression elimination -\layout Itemize - -dead code elimination -\layout Itemize - -loop optimizations -\layout Itemize - -if loop optimizations caused any changes then do 'global subexpression eliminati +\newline +Dead code elimination +\newline +Loop optimizations +\newline +If loop optimizations caused any changes then do 'global subexpression eliminati on' and 'dead code elimination' again. -\end_deeper -\layout Enumerate +\layout Itemize This phase determines the live-ranges; by live range I mean those iTemp variables defined by the compiler that still survive after all the optimization @@ -7355,30 +7446,30 @@ s. Live range analysis is essential for register allocation, since these computati on determines which of these iTemps will be assigned to registers, and for how long. -\layout Enumerate +\layout Itemize Phase five is register allocation. There are two parts to this process. -\begin_deeper -\layout Enumerate +\newline +\newline The first part I call 'register packing' (for lack of a better term). In this case several MCU specific expression folding is done to reduce register pressure. -\layout Enumerate +\newline +\newline The second part is more MCU independent and deals with allocating registers to the remaining live ranges. A lot of MCU specific code does creep into this phase because of the limited number of index registers available in the 8051. -\end_deeper -\layout Enumerate +\layout Itemize The Code generation phase is (unhappily), entirely MCU dependent and very little (if any at all) of this code can be reused for other MCU. However the scheme for allocating a homogenized assembler operand for each iCode operand may be reused. -\layout Enumerate +\layout Itemize As mentioned in the optimization section the peep-hole optimizer is rule based system, which can reprogrammed for other MCUs. @@ -7400,7 +7491,9 @@ on, which also builds and installs the debugger in the target directory Compiling for Debugging \layout Standard -The --debug option must be specified for all files for which debug information +The \SpecialChar \- +\SpecialChar \- +debug option must be specified for all files for which debug information is to be generated. The complier generates a .cdb file for each of these files. The linker updates the .cdb file with the address information. @@ -7426,23 +7519,28 @@ Starting the Debugger \layout Standard The debugger can be started using the following command line. - (Assume the file you are debugging has -\layout Standard + (Assume the file you are debugging has the file name foo). +\newline -the file name foo). -\layout Standard +\newline ->sdcdb foo -\layout Standard +\family sans +\series bold +sdcdb foo +\newline + +\family default +\series default +\newline The debugger will look for the following files. -\layout Enumerate +\layout Itemize foo.c - the source file. -\layout Enumerate +\layout Itemize foo.cdb - the debugger symbol information file. -\layout Enumerate +\layout Itemize foo.ihx - the intel hex format object file. \layout Subsection @@ -7472,30 +7570,34 @@ Command Line Options. \layout Itemize -X this options is passed to the simulator please see - simulator docs for details. + the simulator docs for details. \layout Itemize --s passed to simulator see simulator docs for details. +-s passed to simulator see the simulator docs for details. \layout Itemize --S passed to simulator see simulator docs for details. +-S passed to simulator see the simulator docs for details. \layout Subsection Debugger Commands. \layout Standard As mention earlier the command interface for the debugger has been deliberately - kept as close the GNU debugger gdb, as possible, this will help int integration - with existing graphical user interfaces (like ddd, xxgdb or xemacs) existing - for the GNU debugger. + kept as close the GNU debugger gdb, as possible. + This will help the integration with existing graphical user interfaces + (like ddd, xxgdb or xemacs) existing for the GNU debugger. \layout Subsubsection break [line | file:line | function | file:function] \layout Standard -Set breakpoint at specified line or function. -\layout Standard +Set breakpoint at specified line or function: +\newline +\newline + +\family sans +\series bold sdcdb>break 100 \newline sdcdb>break foo.c:100 @@ -7508,9 +7610,13 @@ sdcdb>break foo.c:funcfoo clear [line | file:line | function | file:function ] \layout Standard -Clear breakpoint at specified line or function. -\layout Standard +Clear breakpoint at specified line or function: +\newline + +\newline +\family sans +\series bold sdcdb>clear 100 \newline sdcdb>clear foo.c:100 @@ -7624,25 +7730,50 @@ quit. Interfacing with XEmacs. \layout Standard -Two files are (in emacs lisp) are provided for the interfacing with XEmacs, +Two files (in emacs lisp) are provided for the interfacing with XEmacs, sdcdb.el and sdcdbsrc.el. These two files can be found in the $(prefix)/bin directory after the installat ion is complete. - These files need to be loaded into XEmacs for the interface to work, this - can be done at XEmacs startup time by inserting the following into your - '.xemacs' file (which can be found in your HOME directory) (load-file sdcdbsrc.el -) [ .xemacs is a lisp file so the () around the command is REQUIRED), the - files can also be loaded dynamically while XEmacs is running, set the environme -nt variable 'EMACSLOADPATH' to the installation bin directory [$(prefix)/bin], - then enter the following command ESC-x load-file sdcdbsrc. - To start the interface enter the following command ESC-x sdcdbsrc, you - will prompted to enter the file name to be debugged. + These files need to be loaded into XEmacs for the interface to work. + This can be done at XEmacs startup time by inserting the following into + your '.xemacs' file (which can be found in your HOME directory): +\newline + +\newline + +\family typewriter +(load-file sdcdbsrc.el) +\family default + +\newline + +\newline +.xemacs is a lisp file so the () around the command is REQUIRED. + The files can also be loaded dynamically while XEmacs is running, set the + environment variable 'EMACSLOADPATH' to the installation bin directory + (/bin), then enter the following command ESC-x load-file sdcdbsrc. + To start the interface enter the following command: +\newline + +\newline + +\family sans +\series bold +ESC-x sdcdbsrc +\family default +\series default + +\newline + +\newline +You will prompted to enter the file name to be debugged. -\layout Standard +\newline +\newline The command line options that are passed to the simulator directly are bound - to default values in the file sdcdbsrc.el the variables are listed below - these values maybe changed as required. + to default values in the file sdcdbsrc.el. + The variables are listed below, these values maybe changed as required. \layout Itemize sdcdbsrc-cpu-type '51 @@ -7659,6 +7790,8 @@ The following is a list of key mapping for the debugger interface. \SpecialChar ~ +\family typewriter + \newline ;; Current Listing :: \newline @@ -7913,6 +8046,10 @@ SDCDB ptypecommand for data at \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ \SpecialChar ~ buffer point \newline @@ -8071,6 +8208,7 @@ SDCDB Display current frame if no arg, \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ +\SpecialChar ~ given or display frame arg \newline ;;\SpecialChar ~ @@ -8118,6 +8256,8 @@ given or display frame arg \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ buffer point \newline ;; !\SpecialChar ~ @@ -8214,6 +8354,10 @@ SDCDB print command for data at \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ \SpecialChar ~ buffer point \newline @@ -8378,6 +8522,8 @@ Toggle Sdcdbsrc mode Toggle list mode \newline ;; +\family default + \newline \layout Section @@ -8390,8 +8536,8 @@ The Z80 and gbz80 port SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80. The port is incomplete - long support is incomplete (mul, div and mod are - unimplimented), and both float and bitfield support is missing, but apart - from that the code generated is correct. + unimplimented), and both float and bitfield support is missing. + Apart from that the code generated is correct. \layout Standard As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c. @@ -8407,8 +8553,9 @@ As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen. Support \layout Standard -SDCC has grown to be large project, the compiler alone (without the Assembler - Package, Preprocessor) is about 40,000 lines of code (blank stripped). +SDCC has grown to be a large project. + The compiler alone (without the preprocessor, assembler and linker) is + about 40,000 lines of code (blank stripped). The open source nature of this project is a key to its continued growth and support. You gain the benefit and support of many active software developers and @@ -8432,12 +8579,12 @@ cc@sdcc.sourceforge.net'. this can be very helpful. Compiling your program with the --dumpall option can sometimes be useful in locating optimization problems. -\layout Subsection +\layout Section Acknowledgments \layout Standard -Sandeep Dutta(sandeep.dutta@usa.net) - SDCC, the compiler, MCS51 code generator, +Sandeep Dutta (sandeep.dutta@usa.net) - SDCC, the compiler, MCS51 code generator, Debugger, AVR port \newline Alan Baldwin (baldwin@shop-pdp.kent.edu) - Initial version of ASXXXX & ASLINK. @@ -8449,7 +8596,7 @@ Dmitry S. Obukhov (dso@usa.net) - malloc & serial i/o routines. \newline -Daniel Drotos - for his Freeware simulator +Daniel Drotos (drdani@mazsola.iit.uni-miskolc.hu) - for his Freeware simulator \newline Malini Dutta(malini_dutta@hotmail.com) - my wife for her patience and support. \newline @@ -8459,18 +8606,24 @@ Michael Hope - The Z80 and Z80GB port, 186 development \newline Kevin Vigor - The DS390 port. \newline -Johan Knol - DS390/TINI libs, lots of fixes and enhancements. +Johan Knol - Lots of fixes and enhancements, DS390/TINI libs. +\newline +Scott Datallo - The PIC port. \newline -Scott Datallo - PIC port. + \newline -(Thanks to all the other volunteer developers who have helped with coding, + +\emph on +Thanks to all the other volunteer developers who have helped with coding, testing, web-page creation, distribution sets, etc. You know who you are :-) +\emph default + \newline \layout Standard -This document initially written by Sandeep Dutta +This document was initially written by Sandeep Dutta \layout Standard All product names mentioned herein may be trademarks of their respective @@ -8479,7 +8632,7 @@ All product names mentioned herein may be trademarks of their respective \layout Standard -\begin_inset LatexCommand \index{} +\begin_inset LatexCommand \printindex{} \end_inset diff --git a/doc/SDCCUdoc.pdf b/doc/SDCCUdoc.pdf new file mode 100644 index 00000000..1d950eda Binary files /dev/null and b/doc/SDCCUdoc.pdf differ diff --git a/doc/SDCCUdoc.txt b/doc/SDCCUdoc.txt index f84d0181..a03ea704 100644 --- a/doc/SDCCUdoc.txt +++ b/doc/SDCCUdoc.txt @@ -1,6 +1,6 @@ -lSDCC Compiler User Guide +SDCC Compiler User Guide Table of Contents @@ -8,9 +8,10 @@ Table of Contents 1.1 About SDCC 1.2 Open Source 1.3 Typographic conventions - 1.4 Pending: compatibilaty with previous versions + 1.4 Compatibility with previous versions 1.5 System Requirements 1.6 Other Resources + 1.7 Wishes for the future 2 Installation 2.1 Linux/Unix Installation 2.2 Windows Installation @@ -83,15 +84,16 @@ Table of Contents 4.1.10 Highest Order Bit 4.1.11 Peep-hole Optimizer 4.2 Pragmas - 4.3 Library Routines + 4.3 Library Routines 4.4 Interfacing with Assembly Routines - 4.5 Global Registers used for Parameter Passing - 4.5.1 Assembler Routine(non-reentrant) - 4.5.2 Assembler Routine(reentrant) - 4.6 External Stack - 4.7 ANSI-Compliance - 4.8 Cyclomatic Complexity + 4.4.1 Global Registers used for Parameter Passing + 4.4.2 Assembler Routine(non-reentrant) + 4.4.3 Assembler Routine(reentrant) + 4.5 External Stack + 4.6 ANSI-Compliance + 4.7 Cyclomatic Complexity 5 TIPS + 5.1 Notes on MCS51 memory layout 6 Retargetting for other MCUs. 7 SDCDB - Source Level Debugger 7.1 Compiling for Debugging @@ -120,7 +122,7 @@ Table of Contents 8.1 The Z80 and gbz80 port 9 Support 9.1 Reporting Bugs - 9.2 Acknowledgments +10 Acknowledgments @@ -128,39 +130,64 @@ Table of Contents 1.1 About SDCC - - -SDCC is a Free ware, retargettable, optimizing ANSI-C compiler +SDCC is a Freeware, retargettable, optimizing ANSI-C compiler by Sandeep Dutta designed for 8 bit Microprocessors. The current version targets Intel MCS51 based Microprocessors(8051,8052, -etc), Zilog Z80 based MCUs, and the Dallas 80C390 MCS51 -variant. It can be retargetted for other microprocessors, -support for PIC, AVR and 186 is under development. The entire -source code for the compiler is distributed under GPL. SDCC -uses ASXXXX & ASLINK, a Freeware, retargettable assembler -& linker. SDCC has extensive language extensions suitable -for utilizing various microcontrollers underlying hardware -effectively. In addition to the MCU specific optimizations -SDCC also does a host of standard optimizations like global -sub expression elimination, loop optimizations (loop invariant, -strength reduction of induction variables and loop reversing), -constant folding & propagation, copy propagation, dead code -elimination and jumptables for 'switch' statements. For -the back-end SDCC uses a global register allocation scheme -which should be well suited for other 8 bit MCUs. The peep -hole optimizer uses a rule based substitution mechanism -which is MCU dependent. Supported data-types are char (8 -bits, 1 byte), short and int (16 bits, 2 bytes), long (32 -bit, 4 bytes) and float (4 byte IEEE). The compiler also -allows inline assembler code to be embedded anywhere in -a function. In addition routines developed in assembly can -also be called. SDCC also provides an option to report the -relative complexity of a function, these functions can then +etc), Zilog Z80 based MCUs, and the Dallas DS80C390 variant. +It can be retargetted for other microprocessors, support +for PIC, AVR and 186 is under development. The entire source +code for the compiler is distributed under GPL. SDCC uses +ASXXXX & ASLINK, a Freeware, retargettable assembler & linker. +SDCC has extensive language extensions suitable for utilizing +various microcontrollers and underlying hardware effectively. + + +In addition to the MCU specific optimizations SDCC also does +a host of standard optimizations like: + +* global sub expression elimination, + +* loop optimizations (loop invariant, strength reduction + of induction variables and loop reversing), + +* constant folding & propagation, + +* copy propagation, + +* dead code elimination + +* jumptables for switch statements. + +For the back-end SDCC uses a global register allocation scheme +which should be well suited for other 8 bit MCUs. + +The peep hole optimizer uses a rule based substitution mechanism +which is MCU independent. + +Supported data-types are: + +* char (8 bits, 1 byte), + +* short and int (16 bits, 2 bytes), + +* long (32 bit, 4 bytes) + +* float (4 byte IEEE). + +The compiler also allows inline assembler code to be embedded +anywhere in a function. In addition, routines developed +in assembly can also be called. + +SDCC also provides an option (--cyclomatic) to report the +relative complexity of a function. These functions can then be further optimized, or hand coded in assembly if needed. + + SDCC also comes with a companion source level debugger SDCDB, the debugger currently uses ucSim a freeware simulator for -8051 and other micro-controllers. The latest version can -be downloaded from [http://sdcc.sourceforge.net/] . +8051 and other micro-controllers. + +The latest version can be downloaded from [http://sdcc.sourceforge.net/]. 1.2 Open Source @@ -186,8 +213,6 @@ this program. You are forbidden to forbid anyone else to use, share and improve what you give them. Help stamp out software-hoarding! - - 1.3 Typographic conventions Throughout this manual, we will use the following convention. @@ -195,28 +220,38 @@ Commands you have to type in are printed in "sans serif". Code samples are printed in typewriter font. Interesting items and new terms are printed in italicised type. -1.4 Pending: compatibilaty with previous versions +1.4 Compatibility with previous versions -This version has numerous bug fixes comperated with the previous -version. But we also introduced some incompatibilaties with +This version has numerous bug fixes compared with the previous +version. But we also introduced some incompatibilities with older versions. Not just for the fun of it, but to make -the compiler more stable, efficient and ANSI compliant. +the compiler more stable, efficient and ANSI compliant. + +* short is now equivalent to int (16 bits), it used to be + equivalent to char (8 bits) -short char -directory structure (2.7) -vararg pars expl int unless casted -never had a regextend -no --noreparms anymore +* the default directory where include, library and documention + files are stored is no in /usr/local/share -more? +* char type parameters to vararg functions are casted to + int unless explicitly casted, e.g.: + char a=3; + printf ("%d %c\n", a, (char)a); + will push a as an int and as a char resp. + +* option --regextend has been removed + +* option --noreparms has been removed + + 1.5 System Requirements What do you need before you start installation of SDCC? A computer, and a desire to compute. The preferred method of installation is to compile SDCC from source using GNU -GCC and make. For Windows some pre-compiled binary distributions +gcc and make. For Windows some pre-compiled binary distributions are available for your convenience. You should have some experience with command line tools and compiler use. @@ -234,6 +269,22 @@ and can be found in the source distribution. If you want the latest unreleased software, the complete source package is available directly by anonymous CVS on cvs.sdcc.sourceforge.net. +1.7 Wishes for the future + +There are (and always will be) some things that could be +done. Here are some I can think of: + + +sdcc -c --model-large -o large _atoi.c (where large could +be a different basename or a directory) + + +char KernelFunction3(char p) at 0x340; + +If you can think of some more, please send them to the list. + + + 2 Installation 2.1 Linux/Unix Installation @@ -256,7 +307,8 @@ is available directly by anonymous CVS on cvs.sdcc.sourceforge.net. 6. Type "make". All of the source packages will compile, this can take a while. -7. Type "make install" as root. This copies the binary executables +7. Type "make install" as root. This copies the binary executables, + the include files, the libraries and the documentation to the install directories. 2.2 Windows Installation @@ -322,7 +374,6 @@ something did not install correctly. SDCC binaries are commonly installed in a directory arrangement like this: - +--------------------------------+-------------------------------------------+ | /usr/local/bin | Holds executables(sdcc, s51, aslink, ...) | +--------------------------------+-------------------------------------------+ @@ -336,7 +387,11 @@ like this: Make sure the compiler works on a very simple example. Type in the following test.c program using your favorite editor: -Compile this using the following command: "sdcc -c test.c" +int test(int t) { + return t+3; +} + +Compile this using the following command: "sdcc -c test.c". If all goes well, the compiler will generate a test.asm and test.rel file. Congratulations, you've just compiled your first program with SDCC. We used the -c option to tell @@ -508,7 +563,7 @@ library The command "./configure --prefix=/usr/local" will configure the compiler to be installed in directory -/usr/local/bin. +/usr/local. 2.8 Components of SDCC @@ -521,21 +576,42 @@ their respective directories. As SDCC grows to include support for other processors, other packages from various developers are included and may have their own sets of documentation. -You might want to look at the various executables which are -installed in the bin directory. At the time of this writing, -we find the following programs: +You might want to look at the files which are installed in +. At the time of this writing, we find the following +programs: + +In /bin: + +* sdcc - The compiler. + +* sdcpp - The C preprocessor. + +* asx8051 - The assembler for 8051 type processors. + +* as-z80, as-gbz80 - The Z80 and GameBoy Z80 assemblers. + +* aslink -The linker for 8051 type processors. + +* link-z80, link-gbz80 - The Z80 and GameBoy Z80 linkers. + +* s51 - The ucSim 8051 simulator. - +* sdcdb - The source debugger. -sdcc - The compiler. -sdcpp - The C preprocessor. -asx8051 - The assembler for 8051 type processors. -as-z80, as-gbz80 - The Z80 and GameBoy Z80 assemblers. -aslink -The linker for 8051 type processors. -link-z80, link-gbz80 - The Z80 and GameBoy Z80 linkers. -s51 - The ucSim 8051 simulator. -sdcdb - The source debugger. -packihx - A tool to pack Intel hex files. +* packihx - A tool to pack Intel hex files. + +In /share/sdcc/include + +* the include files + +In /share/sdcc/lib + +* the sources of the runtime library and the subdirs small + large and ds390 with the precompiled relocatables. + +In /share/sdcc/doc + +* the documentation As development for other processors proceeds, this list will expand to include executables to support processors like @@ -1813,28 +1889,28 @@ conditions are true. * The case labels are in numerical sequence, the labels need not be in order, and the starting number need not be one or zero. - -switch(i) { + + switch(i) { - switch (i) { -case 4:... + switch (i) { + case 4:... - case 1: ... -case 5:... + case 1: ... + case 5:... - case 2: ... -case 3:... + case 2: ... + case 3:... - case 3: ... -case 6:... + case 3: ... + case 6:... - case 4: ... -} + case 4: ... + } - } - -Both the above switch statements will be implemented using -a jump-table. + } + + Both the above switch statements will be implemented using + a jump-table. * The number of case labels is at least three, since it takes two conditional statements to handle the boundary conditions. @@ -2077,16 +2153,16 @@ inner most 'pop' 'push' pair would be eliminated, i.e.: would result in: -pop ar1 -; nop -push ar1 + pop ar1 + ; nop + push ar1 with the restart option the rule will be applied again to the resulting code and then all the pop-push pairs will be eliminated to yield: -; nop -; nop + ; nop + ; nop A conditional function can be attached to a rule. Attaching rules are somewhat more involved, let me illustrate this @@ -2094,9 +2170,11 @@ with an example. replace { ljmp %5 -%2:} by { +%2: +} by { sjmp %5 -%2:} if labelInRange +%2: +} if labelInRange The optimizer does a look-up of a function name table defined in function callFuncByName in the source file SDCCpeeph.c, @@ -2115,8 +2193,6 @@ rules that are compiled into the compiler, you can add your own rules in the default set there if you get tired of specifying the --peep-file option. - - 4.2 Pragmas SDCC supports the following #pragma directives. This directives @@ -2176,10 +2252,7 @@ function; pragmas should be placed before and/or after a function, placing pragma's inside a function body could have unpredictable results. -eg - -#pragma SAVE /* save the current settings -*/ +#pragma SAVE /* save the current settings */ #pragma NOGCSE /* turnoff global subexpression elimination */ #pragma NOINDUCTION /* turn off induction optimizations */ @@ -2196,7 +2269,7 @@ The compiler will generate a warning message when extra space is allocated. It is strongly recommended that the SAVE and RESTORE pragma's be used when changing options for a function. -4.3 Library Routines +4.3 Library Routines The following library routines are provided for your convenience. @@ -2400,48 +2473,45 @@ will get to them shortly. 4.4 Interfacing with Assembly Routines -4.5 Global Registers used for Parameter Passing +4.4.1 Global Registers used for Parameter Passing -By default the compiler uses the global registers "DPL,DPH,B,ACC" -to pass the first parameter to a routine, the second parameter -onwards is either allocated on the stack (for reentrant -routines or --stack-auto is used) or in the internal / external -ram (depending on the memory model). +The compiler always uses the global registers DPL,DPH,B and +ACC to pass the first parameter to a routine. The second +parameter onwards is either allocated on the stack (for +reentrant routines or if --stack-auto is used) or in the +internal / external ram (depending on the memory model). -4.5.1 Assembler Routine(non-reentrant) +4.4.2 Assembler Routine(non-reentrant) In the following example the function cfunc calls an assembler routine asm_func, which takes two parameters. extern int asm_func(unsigned char, unsigned char); - -int c_func (unsigned char i, unsigned char j) -{ - return asm_func(i,j); -} -int main() -{ - return c_func(10,9); +int c_func (unsigned char i, unsigned char j) +{ + return asm_func(i,j); +} + +int main() +{ + return c_func(10,9); } -The corresponding assembler function is:- +The corresponding assembler function is: - .globl _asm_func_PARM_2 +.globl _asm_func_PARM_2 .globl _asm_func .area OSEG -_asm_func_PARM_2: -.ds 1 +_asm_func_PARM_2: + .ds 1 .area CSEG _asm_func: - mov -a,dpl - add -a,_asm_func_PARM_2 - mov -dpl,a - mov -dpl,#0x00 + mov a,dpl + add a,_asm_func_PARM_2 + + mov dpl,a + mov dpl,#0x00 ret Note here that the return values are placed in 'dpl' - One @@ -2455,65 +2525,64 @@ from the left. The first parameter is passed in "dpl" for One bye parameter, "dptr" if two bytes, "b,dptr" for three bytes and "acc,b,dptr" -for four bytes, the varaible name for the second parameter +for four bytes, the varible name for the second parameter will be __PARM_2. -Assemble the assembler routine with the following command. +Assemble the assembler routine with the following command: asx8051 -losg asmfunc.asm Then compile and link the assembler routine to the C source -file with the following command, +file with the following command: sdcc cfunc.c asmfunc.rel -4.5.2 Assembler Routine(reentrant) +4.4.3 Assembler Routine(reentrant) In this case the second parameter onwards will be passed on the stack, the parameters are pushed from right to left i.e. after the call the left most parameter will be on the -top of the stack. Here is an example. +top of the stack. Here is an example: extern int asm_func(unsigned char, unsigned char); - - int c_func (unsigned char i, unsigned char j) reentrant { - return asm_func(i,j); + return asm_func(i,j); } + int main() { - return c_func(10,9); + return c_func(10,9); } -The corresponding assembler routine is. +The corresponding assembler routine is: - .globl _asm_func +.globl _asm_func _asm_func: - push _bp - mov _bp,sp - mov r2,dpl - mov a,_bp - clr c - add a,#0xfd - mov r0,a - add a,#0xfc - mov r1,a - mov a,@r0 - add a,r2 - mov dpl,a - mov dph,#0x00 - mov sp,_bp - pop _bp - ret + push _bp + mov _bp,sp + mov r2,dpl + mov a,_bp + clr c + add a,#0xfd + mov r0,a + add a,#0xfc + mov r1,a + mov a,@r0 + add a,r2 + mov dpl,a + mov dph,#0x00 + mov sp,_bp + pop _bp + ret The compiling and linking procedure remains the same, however note the extra entry & exit linkage required for the assembler code, _bp is the stack frame pointer and is used to compute the offset into the stack for parameters and local variables. -4.6 External Stack +4.5 External Stack The external stack is located at the start of the external ram segment, and is 256 bytes in size. When --xstack option @@ -2530,67 +2599,60 @@ external ram segment into PORT P2, therefore when using the External Stack option, this port MAY NOT be used by the application program. -4.7 ANSI-Compliance +4.6 ANSI-Compliance Deviations from the compliancy. -1. functions are not always reentrant. +* functions are not always reentrant. -2. structures cannot be assigned values directly, cannot be +* structures cannot be assigned values directly, cannot be passed as function parameters or assigned to each other - and cannot be a return value from a function. - - eg - -struct s { ... }; -struct s s1, s2; -foo() -{ -... -s1 = s2 ; /* is invalid in SDCC although allowed in ANSI -*/ -... -} - -struct s foo1 (struct s parms) /* is invalid in SDCC although -allowed in ANSI */ -{ -struct s rets; -... -return rets;/* is invalid in SDCC although allowed in ANSI -*/ -} - -1. 'long long' (64 bit integers) not supported. - -2. 'double' precision floating point not supported. + and cannot be a return value from a function, e.g.: + + struct s { ... }; + struct s s1, s2; + foo() + { + ... + s1 = s2 ; /* is invalid in SDCC although + allowed in ANSI */ + ... + } + struct s foo1 (struct s parms) /* is invalid in SDCC although + allowed in ANSI */ + { + struct s rets; + ... + return rets;/* is invalid in SDCC although + allowed in ANSI */ + } -3. integral promotions are suppressed. What does this mean - ? The compiler will not implicitly promote an integer - expression to a higher order integer, exception is an - assignment or parameter passing. +* 'long long' (64 bit integers) not supported. -4. No support for setjmp and longjmp (for now). +* 'double' precision floating point not supported. -5. Old K&R style function declarations are NOT allowed. +* No support for setjmp and longjmp (for now). -foo(i,j) /* this old style of function declarations */ -int i,j; /* are valid in ANSI .. not valid in SDCC */ -{ -... -} +* Old K&R style function declarations are NOT allowed. + + foo(i,j) /* this old style of function declarations */ + + int i,j; /* are valid in ANSI but not valid in SDCC */ + + { + ... + } -1. functions declared as pointers must be dereferenced during +* functions declared as pointers must be dereferenced during the call. - + int (*foo)(); + ... + /* has to be called like this */ + (*foo)(); /* ansi standard allows calls to be made like + 'foo()' */ - ... - /* has to be called like this */ - (*foo)();/* ansi standard allows calls to be made like -'foo()' */ - -4.8 Cyclomatic Complexity +4.7 Cyclomatic Complexity Cyclomatic complexity of a function is defined as the number of independent paths the program can take during execution @@ -2599,20 +2661,20 @@ the number test cases you have to generate to validate the function. The accepted industry standard for complexity number is 10, if the cyclomatic complexity reported by SDCC exceeds 10 you should think about simplification of the -function logic. +function logic. Note that the complexity level is not related +to the number of lines of code in a function. Large functions +can have low complexity, and small functions can have large +complexity levels. + +SDCC uses the following formula to compute the complexity: -Note that the complexity level is not related to the number -of lines of code in a function. Large functions can have -low complexity, and small functions can have large complexity -levels. SDCC uses the following formula to compute the complexity. -complexity = (number of edges in control flow graph) - - (number +complexity = (number of edges in control flow graph) - (number of nodes in control flow graph) + 2; Having said that the industry standard is 10, you should -be aware that in some cases it may unavoidable to have a -complexity level of less than 10. For example if you have +be aware that in some cases it be may unavoidable to have +a complexity level of less than 10. For example if you have switch statement with more than 10 case labels, each case label adds one to the complexity level. The complexity level is by no means an absolute measure of the algorithmic complexity @@ -2622,7 +2684,7 @@ optimization. 5 TIPS -Here are a few guide-lines that will help the compiler generate +Here are a few guidelines that will help the compiler generate more efficient code, some of the tips are specific to this compiler others are generally good programming practice. @@ -2647,39 +2709,37 @@ compiler others are generally good programming practice. * Reducing the size of division, multiplication & modulus operations can reduce code size substantially. Take the following code for example. - + foobar(unsigned int p1, unsigned char ch) { unsigned char ch1 = p1 % ch ; .... } - + For the modulus operation the variable ch will be promoted to unsigned int first then the modulus operation will - be performed (this will lead to a call to a support routine). + be performed (this will lead to a call to support routine + _muduint()), and the result will be casted to an int. If the code is changed to - + foobar(unsigned int p1, unsigned char ch) { - unsigned char ch1 = (unsigned char)p1 - % ch ; + unsigned char ch1 = (unsigned char)p1 % ch ; .... } - + It would substantially reduce the code generated (future versions of the compiler will be smart enough to detect such optimization oppurtunities). -Notes on MCS51 memory layout(Trefor@magera.freeserve.co.uk) +5.1 Notes on MCS51 memory layout The 8051 family of micro controller have a minimum of 128 bytes of internal memory which is structured as follows - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7 - - Bytes 20-2F - 16 bytes to hold 128 bit variables and - - Bytes 30-7F - 60 bytes for general purpose use. Normally the SDCC compiler will only utilise the first bank @@ -2705,15 +2765,14 @@ checking to prevent this from happening. The amount of stack being used is affected by the use of the "internal stack" to save registers before a subroutine -call is made, - --stack-auto will declare parameters and -local variables on the stack - the number of nested subroutines. +call is made (--stack-auto will declare parameters and local +variables on the stack) and the number of nested subroutines. If you detect that the stack is over writing you data, then the following can be done. --xstack will cause an external stack to be used for saving registers and (if --stack-auto is being used) storing parameters and local variables. However -this will produce more and code which will be slower to -execute. +this will produce more code which will be slower to execute. --stack-loc will allow you specify the start of the stack, i.e. you could start it after any data in the general purpose @@ -2738,8 +2797,8 @@ or "near data" then the approach which best utilised the internal memory is to position the "near data" after the last bank of used registers or, if you use bit variables, after the last bit variable by using the --data-loc, e.g. -if two register banks are being used and no data variables, ---data-loc 16, and - use the --stack-after-data option. +if two register banks are being used and no bit variables, +--data-loc 16, and use the --stack-after-data option. If bit variables are being used, another method would be to try and squeeze the data area in the unused register @@ -2753,14 +2812,14 @@ to be covered by this document. What follows is a brief description of each of the seven phases of the compiler and its MCU dependency. -1. Parsing the source and building the annotated parse tree. +* Parsing the source and building the annotated parse tree. This phase is largely MCU independent (except for the language extensions). Syntax & semantic checks are also done in this phase, along with some initial optimizations like back patching labels and the pattern matching optimizations like bit-rotation etc. -2. The second phase involves generating an intermediate code +* The second phase involves generating an intermediate code which can be easy manipulated during the later phases. This phase is entirely MCU independent. The intermediate code generation assumes the target machine has unlimited @@ -2768,52 +2827,47 @@ and its MCU dependency. iTemp. The compiler can be made to dump a human readable form of the code generated by using the --dumpraw option. -3. This phase does the bulk of the standard optimizations +* This phase does the bulk of the standard optimizations and is also MCU independent. This phase can be broken - down into several sub-phases. - - * Break down intermediate code (iCode) into basic blocks. - - * Do control flow & data flow analysis on the basic blocks. - - * Do local common subexpression elimination, then global - subexpression elimination - - * dead code elimination - - * loop optimizations - - * if loop optimizations caused any changes then do 'global - subexpression elimination' and 'dead code elimination' - again. - -4. This phase determines the live-ranges; by live range I + down into several sub-phases: + + Break down intermediate code (iCode) into basic blocks. + Do control flow & data flow analysis on the basic blocks. + Do local common subexpression elimination, then global + subexpression elimination + Dead code elimination + Loop optimizations + If loop optimizations caused any changes then do 'global + subexpression elimination' and 'dead code elimination' + again. + +* This phase determines the live-ranges; by live range I mean those iTemp variables defined by the compiler that still survive after all the optimizations. Live range analysis is essential for register allocation, since these computation determines which of these iTemps will be assigned to registers, and for how long. -5. Phase five is register allocation. There are two parts +* Phase five is register allocation. There are two parts to this process. + + The first part I call 'register packing' (for lack of a + better term). In this case several MCU specific expression + folding is done to reduce register pressure. + + The second part is more MCU independent and deals with + allocating registers to the remaining live ranges. A lot + of MCU specific code does creep into this phase because + of the limited number of index registers available in + the 8051. - (a) The first part I call 'register packing' (for lack of - a better term). In this case several MCU specific expression - folding is done to reduce register pressure. - - (b) The second part is more MCU independent and deals with - allocating registers to the remaining live ranges. A - lot of MCU specific code does creep into this phase - because of the limited number of index registers available - in the 8051. - -6. The Code generation phase is (unhappily), entirely MCU +* The Code generation phase is (unhappily), entirely MCU dependent and very little (if any at all) of this code can be reused for other MCU. However the scheme for allocating a homogenized assembler operand for each iCode operand may be reused. -7. As mentioned in the optimization section the peep-hole +* As mentioned in the optimization section the peep-hole optimizer is rule based system, which can reprogrammed for other MCUs. @@ -2830,11 +2884,11 @@ at the C source and at the ASM source level. 7.1 Compiling for Debugging -The --debug option must be specified for all files for which -debug information is to be generated. The complier generates -a .cdb file for each of these files. The linker updates -the .cdb file with the address information. This .cdb is -used by the debugger. +The debug option must be specified for all files +for which debug information is to be generated. The complier +generates a .cdb file for each of these files. The linker +updates the .cdb file with the address information. This +.cdb is used by the debugger. 7.2 How the Debugger Works @@ -2852,19 +2906,17 @@ translates it into appropriate commands for the simulator. 7.3 Starting the Debugger The debugger can be started using the following command line. -(Assume the file you are debugging has +(Assume the file you are debugging has the file name foo). -the file name foo). - ->sdcdb foo +sdcdb foo The debugger will look for the following files. -1. foo.c - the source file. +* foo.c - the source file. -2. foo.cdb - the debugger symbol information file. +* foo.cdb - the debugger symbol information file. -3. foo.ihx - the intel hex format object file. +* foo.ihx - the intel hex format object file. 7.4 Command Line Options. @@ -2885,25 +2937,25 @@ The debugger will look for the following files. please see the simulator docs for details. * -X this options is passed to the simulator - please see simulator docs for details. + please see the simulator docs for details. -* -s passed to simulator see simulator +* -s passed to simulator see the simulator docs for details. -* -S passed to simulator see simulator docs - for details. +* -S passed to simulator see the simulator + docs for details. 7.5 Debugger Commands. As mention earlier the command interface for the debugger has been deliberately kept as close the GNU debugger gdb, -as possible, this will help int integration with existing +as possible. This will help the integration with existing graphical user interfaces (like ddd, xxgdb or xemacs) existing for the GNU debugger. 7.5.1 break [line | file:line | function | file:function] -Set breakpoint at specified line or function. +Set breakpoint at specified line or function: sdcdb>break 100 sdcdb>break foo.c:100 @@ -2912,7 +2964,7 @@ sdcdb>break foo.c:funcfoo 7.5.2 clear [line | file:line | function | file:function ] -Clear breakpoint at specified line or function. +Clear breakpoint at specified line or function: sdcdb>clear 100 sdcdb>clear foo.c:100 @@ -2990,24 +3042,31 @@ and may display incorrect values. 7.6 Interfacing with XEmacs. -Two files are (in emacs lisp) are provided for the interfacing +Two files (in emacs lisp) are provided for the interfacing with XEmacs, sdcdb.el and sdcdbsrc.el. These two files can be found in the $(prefix)/bin directory after the installation is complete. These files need to be loaded into XEmacs for -the interface to work, this can be done at XEmacs startup +the interface to work. This can be done at XEmacs startup time by inserting the following into your '.xemacs' file -(which can be found in your HOME directory) (load-file sdcdbsrc.el) -[ .xemacs is a lisp file so the () around the command is -REQUIRED), the files can also be loaded dynamically while -XEmacs is running, set the environment variable 'EMACSLOADPATH' -to the installation bin directory [$(prefix)/bin], then +(which can be found in your HOME directory): + +(load-file sdcdbsrc.el) + +.xemacs is a lisp file so the () around the command is REQUIRED. +The files can also be loaded dynamically while XEmacs is +running, set the environment variable 'EMACSLOADPATH' to +the installation bin directory (/bin), then enter the following command ESC-x load-file sdcdbsrc. To -start the interface enter the following command ESC-x sdcdbsrc, -you will prompted to enter the file name to be debugged. +start the interface enter the following command: + +ESC-x sdcdbsrc + +You will prompted to enter the file name to be debugged. + The command line options that are passed to the simulator -directly are bound to default values in the file sdcdbsrc.el -the variables are listed below these values maybe changed +directly are bound to default values in the file sdcdbsrc.el. +The variables are listed below, these values maybe changed as required. * sdcdbsrc-cpu-type '51 @@ -3040,7 +3099,7 @@ step command ;; ? sdcdb-whatis-c-sexp SDCDB ptypecommand for data at -;; +;; buffer point ;; x sdcdbsrc-delete SDCDB @@ -3050,9 +3109,9 @@ or delete arg (C-u arg x) ;; m sdcdbsrc-frame SDCDB Display current frame if no arg, -;; given +;; given or display frame arg -;; buffer +;; buffer point ;; ! sdcdbsrc-goto-sdcdb Goto @@ -3060,7 +3119,7 @@ the SDCDB output buffer ;; p sdcdb-print-c-sexp SDCDB print command for data at -;; +;; buffer point ;; g sdcdbsrc-goto-sdcdb Goto @@ -3092,8 +3151,8 @@ Toggle list mode SDCC can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80. The port is incomplete - long support is incomplete (mul, div and mod are unimplimented), and both -float and bitfield support is missing, but apart from that -the code generated is correct. +float and bitfield support is missing. Apart from that the +code generated is correct. As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c. The stack frame is similar to that generated @@ -3106,16 +3165,17 @@ to 127 bytes - this will be fixed in a later version. 9 Support -SDCC has grown to be large project, the compiler alone (without -the Assembler Package, Preprocessor) is about 40,000 lines -of code (blank stripped). The open source nature of this -project is a key to its continued growth and support. You -gain the benefit and support of many active software developers -and end users. Is SDCC perfect? No, that's why we need your -help. The developers take pride in fixing reported bugs. -You can help by reporting the bugs and helping other SDCC -users. There are lots of ways to contribute, and we encourage -you to take part in making SDCC a great software package. +SDCC has grown to be a large project. The compiler alone +(without the preprocessor, assembler and linker) is about +40,000 lines of code (blank stripped). The open source nature +of this project is a key to its continued growth and support. +You gain the benefit and support of many active software +developers and end users. Is SDCC perfect? No, that's why +we need your help. The developers take pride in fixing reported +bugs. You can help by reporting the bugs and helping other +SDCC users. There are lots of ways to contribute, and we +encourage you to take part in making SDCC a great software +package. 9.1 Reporting Bugs @@ -3128,9 +3188,9 @@ code, this can be very helpful. Compiling your program with the --dumpall option can sometimes be useful in locating optimization problems. -9.2 Acknowledgments +10 Acknowledgments -Sandeep Dutta(sandeep.dutta@usa.net) - SDCC, the compiler, +Sandeep Dutta (sandeep.dutta@usa.net) - SDCC, the compiler, MCS51 code generator, Debugger, AVR port Alan Baldwin (baldwin@shop-pdp.kent.edu) - Initial version of ASXXXX & ASLINK. @@ -3138,21 +3198,22 @@ John Hartman (jhartman@compuserve.com) - Porting ASXXX & ASLINK for 8051 Dmitry S. Obukhov (dso@usa.net) - malloc & serial i/o routines. -Daniel Drotos - for his +Daniel Drotos (drdani@mazsola.iit.uni-miskolc.hu) - for his Freeware simulator Malini Dutta(malini_dutta@hotmail.com) - my wife for her patience and support. Unknown - for the GNU C - preprocessor. Michael Hope - The Z80 and Z80GB port, 186 development Kevin Vigor - The DS390 port. -Johan Knol - DS390/TINI libs, lots of fixes and enhancements. -Scott Datallo - PIC port. -(Thanks to all the other volunteer developers who have helped +Johan Knol - Lots of fixes and enhancements, DS390/TINI libs. +Scott Datallo - The PIC port. + +Thanks to all the other volunteer developers who have helped with coding, testing, web-page creation, distribution sets, etc. You know who you are :-) -This document initially written by Sandeep Dutta +This document was initially written by Sandeep Dutta All product names mentioned herein may be trademarks of their respective companies.