1 #This file was created by <sandeep> Sun Mar 26 12:40:23 2000
2 #LyX 1.0 (C) 1995-1999 Matthias Ettrich and the LyX Team
15 \paperorientation portrait
18 \paragraph_separation indent
20 \quotes_language english
24 \paperpagestyle default
28 SDCC Compiler User Guide
31 Sandeep Dutta (sandeep.dutta@usa.net)
37 SDCC is a Free ware , retargettable, optimizing ANSI-C compiler.
38 The current version targets Intel 8051 based MCUs, it can be retargetted
39 for other 8 bit MCUs or PICs.
40 The entire source code for the compiler is distributed under GPL.
41 SDCC used ASXXXX & ASLINK a Free ware, retargettable assembler & linker.
42 SDCC has extensive MCU (8051) specific language extensions, which lets
43 it utilize the underlying hardware effectively.
44 The front-end (parser) will be enhanced to handle language extensions for
45 other MCUs as and when they are targetted.
46 In addition to the MCU Specific optimizations SDCC also does a host of
47 standard optimizations like
49 global sub expression elimination, loop optimizations (loop invariant,
50 strength reduction of induction variables and loop reversing), constant
51 folding & propagation, copy propagation, dead code elimination and jumptables
52 for 'switch' statements.
55 For the back-end SDCC uses a global register allocation scheme which should
56 be well suited for other 8 bit MCUs , the peep hole optimizer uses a rule
57 based substitution mechanism which is MCU independent.
58 Supported data-types are
60 short (8 bits, 1 byte), char (8 bits, 1 byte), int (16 bits, 2 bytes ),
61 long (32 bit, 4 bytes) & float (4 byte IEEE).
64 The compiler also allows
68 to be embedded anywhere in a function.
69 In addition routines developed in assembly can also be called.
70 SDCC also provides an option to report the relative complexity of a function,
71 these functions can then be further optimized , or hand coded in assembly
73 SDCC also comes with a companion source level debugger SDCDB, the debugger
74 currently uses S51 a freeware simulator for 8051, it can be easily modified
75 to use other simulators.
76 The latest version can be downloaded from
78 http://www.geocities.com/ResearchTriangle/Forum/1353
81 All packages used in this compiler system are
85 (freeware); source code for all the sub-packages ( asxxxx assembler/linker
90 a conservative garbage collector) are distributed with the package.
91 Documentation was created using a freeware word processor (LyX).
95 This program is free software; you can redistribute it and/or modify it
96 under the terms of the GNU General Public License as published by the Free
97 Software Foundation; either version 2, or (at your option) any later version.
98 This program is distributed in the hope that it will be useful, but WITHOUT
99 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
100 FOR A PARTICULAR PURPOSE.
101 See the GNU General Public License for more details.
102 You should have received a copy of the GNU General Public License along
103 with this program; if not, write to the Free Software Foundation, 59 Temple
104 Place - Suite 330, Boston, MA 02111-1307, USA.
105 In other words, you are welcome to use, share and improve this program.
106 You are forbidden to forbid anyone else to use, share and improve what
108 Help stamp out software-hoarding!
112 \begin_inset LatexCommand \label{Installation}
119 What you need before you start installation of SDCC ? A C Compiler, not
120 just any C Compiler, gcc to be exact, you can get adventurous and try another
121 compiler , I HAVEN'T tried it.
122 GCC is free , and is available for almost all major platforms, if you are
127 you probably already have it, if you are using
139 you will need the full development version of their tool (
143 , follow their instructions for installation (this is also free and is very
152 users be aware that the compiler runs substantially slower on the Windows
153 platform, I am not sure why.
156 After you have installed
160 you are ready to build the compiler (sorry no binary distributions yet).
161 SDCC is native to Linux but can be ported to any platform on which GCC
163 Extract the source file package (
171 ) into some directory , which we shall refer to as
179 \begin_inset LatexCommand \label{Components}
184 \layout Subsubsection
186 gc ( a conservative garbage collector)
189 SDCC relies on this component to do all the memory management, this excellent
190 package is copyrighted by
192 Jans J Boehm(boehm@sgi.com) and Alan J Demers
194 but can be used with minimum restrictions.
195 The GC source will be extracted into the directory
201 \layout Subsubsection
203 cpp ( C-Preprocessor)
206 The preprocessor is extracted into the directory
210 , it is a modified version of the GNU preprocessor.
211 \layout Subsubsection
213 asxxxx & aslink ( The assembler and Linkage Editor)
216 This is retargettable assembler & linkage editor, it was developed by Alan
217 Baldwin, John Hartman created the version for 8051, and I (Sandeep) have
218 some enhancements and bug fixes for it to work properly with the SDCC.
219 This component is extracted into the directory
222 \layout Subsubsection
227 This is the actual compiler, it uses
231 and invokes the assembler and linkage editor.
232 All files with the prefix
236 are part of the compiler and is extracted into the the directory
239 \layout Subsubsection
244 Version 2.1.8 onwards contains s51 a freeware , opensource simulator developed
245 by Daniel Drotos <drdani@mazsola.iit.uni-miskolc.hu>.
246 The executable is built as part of build process, for more information
247 visit Daniel's website at <http://mazsola.iit.uni-miskolc.hu/~drdani/embedded/s51/
249 \layout Subsubsection
251 SDCDB - Source level Debugger.
254 SDCDB is the companion source level debugger .
255 The current version of the debugger uses Daniel's Simulator S51, but can
256 be easily changed to use other simulators.
259 Installation for Version <= 2.1.7
262 After the package is extracted (
270 , change to the directory where you extracted the package and give the command.
280 shell script, it will compile all the above mentioned components and install
281 the executables into the directory
285 make sure you add this directory to your
289 environment variable.
290 This script will also compile all the support routines ( library routines
292 The support routines are all developed in C and need to be compiled.
295 Installation for Version >= 2.1.8a
298 The distribution method from Version 2.1.8a has been changed to be conforment
300 \begin_inset Quotes eld
304 \begin_inset Quotes erd
308 The source is now distributed as
312 sdcc-<version number>.tar.gz format
316 , instead of the older .zip format.
317 The steps for installation are as follows.
318 \layout Subsubsection
323 This is usually done by the following command
324 \begin_inset Quotes eld
331 gunzip -c sdcc-<version number>.tar.gz | tar -xv -
336 \begin_inset Quotes eld
340 \layout Subsubsection
342 Change to the main source directory (usually sdcc or sdcc-<version number>)
343 \layout Subsubsection
345 Issue command to configure your system
348 The configure command has several options the most commonly used option
349 is --prefix=<directory name>, where <directory name> is the final location
350 for the sdcc executables and libraries, (default location is /usr/local).
351 The installation process will create the following directory structure
352 under the <directory name> specified.
355 bin/ - binary exectables (add to PATH environment variable)
371 sdcc51inc/ - include header files
413 small/ - Object & Library files for small model library
441 large/ - Object & library files for large model library
451 './configure --prefix=/usr/local
452 \begin_inset Quotes erd
458 will create configure the compiler to be installed in directory /usr/local/bin.
459 \layout Subsubsection
464 After configuration step issue the command
472 \begin_inset Quotes eld
476 \begin_inset Quotes erd
482 This will compile the compiler
483 \layout Subsubsection
486 \begin_inset Quotes eld
490 \begin_inset Quotes erd
496 Will install the compiler and libraries in the appropriate directories.
497 \layout Subsubsection
499 Special Notes for Windows Users.
500 Provided by Michael Jamet[ mjamet@computer.org]
510 How to install SDCC from source on a Windows 95 or Windows NT 4 system
521 This document describes how to install SDCC on a Win 95 or Win NT 4 system.
527 These instructions probably work for Win 98 as well, but have not been
533 tested on that platform.
544 There are lots of little differences between UNIX and the Win32 Cygnus
550 environment which make porting more difficult than it should be.
557 you want the details, please contact me.
559 Otherwise just follow these
576 Install the Cygnus Software
581 Go to http://sourceware.cygnus.com/cygwin.
583 Cygnus provides a UNIX like
588 environment for Win 32 systems.
590 Download "full.exe" and install.
597 MUST install it on your C drive.
599 "full.exe" contains a shell AND many
604 common UNIX utilities.
616 Download and Extract the Latest SDCC
621 The latest version can be found at
628 www.geocities.com/ResearchTriange/Forum/1353.
634 It can be uncompressed with winzip.
652 There should be an entry in the Start Menu for Cygnus.
660 This gives you a UNIX like environment.
662 FROM THIS POINT ON, DIRECTORIES
667 MUST BE SPECIFIED WITH FORWARD SLASHES (/) NOT THE DOS STYLE BACK
674 ) BECAUSE THIS IS WHAT UNIX EXPECTS.
686 winnt" would be "/winnt" under the shell.
698 Change Directory to Where SDCC was extracted (referred to as INSTALLDIR)
712 If you extracted to a drive OTHER THAN C, the drive
717 must be specified as part of the path.
718 For example, if you extracted to
723 your "g drive", type the following: "cd //g/mydir".
730 to specify the drive.
742 Make Dirs Which are Automatically Made During the UNIX Installation
763 (not a typo, just "bin")
777 mkdir -p /usr/local/bin
784 mkdir -p /usr/local/share
791 mkdir -p /usr/local/share/sdcc51lib
798 mkdir -p /usr/local/share/sdcc51inc
815 (When a path from the root directory is specified WITHOUT a drive, the
823 For example /michael/newuser => c:
839 Add Programs to /bin Expected by the Installation Process
846 - Look at your path: echo $PATH
857 One of the fields is the diretory with the CYGNUS programs.
868 /CYGNUS/CYGWIN~1/H-I586/BIN
880 - cd to the directory found above.
882 You may have to fiddle with the
893 case (upper or lower) here because the PATH is SHOWN as all upper
904 case, but is actually mixed.
906 To help you along, you may type
917 a letter or 2 followed by the escape key.
930 out the remaining letters IF THEY describe a unique directory.
942 If you have problems here, cd one directory and type "ls".
955 is the equivalent of "dir/w".
968 - Copy the following:
1004 \protected_separator
1006 Go back to the INSTALLDIR
1010 \protected_separator
1012 \protected_separator
1017 \protected_separator
1023 \protected_separator
1028 \protected_separator
1030 Run the configure Program
1034 \protected_separator
1036 \protected_separator
1041 \protected_separator
1042 The "./" is important because your current directory is NOT in your path.
1047 \protected_separator
1048 Under DOS, your current directory was implicitly always the first entry
1053 \protected_separator
1059 \protected_separator
1064 \protected_separator
1070 \protected_separator
1072 \protected_separator
1077 \protected_separator
1082 \protected_separator
1083 This process takes quite some time under Win 32.
1088 \protected_separator
1093 \protected_separator
1095 Install the Newly Built Software
1099 \protected_separator
1101 \protected_separator
1106 \protected_separator
1111 \protected_separator
1112 This will partially install the software into the /usr/local directories
1117 \protected_separator
1119 \protected_separator
1120 What it actually doing is copying the .c, .h and
1124 \protected_separator
1125 library files to directories under /usr/local/share.
1130 \protected_separator
1135 \protected_separator
1136 It will NOT be able to install the actual programs (binaries) because
1140 \protected_separator
1141 it does not know programs on Win32 systems have ".exe" extensions.
1146 \protected_separator
1147 For example, it tries to install sdcc instead of sdcc.exe.
1152 \protected_separator
1157 \protected_separator
1158 After the automated part is finished, you must manually copy the binaries:
1163 \protected_separator
1165 \protected_separator
1167 \protected_separator
1168 (This is the bin directory in your INSTALLDIR)
1172 \protected_separator
1174 \protected_separator
1179 \protected_separator
1184 \protected_separator
1186 Make sure /usr/local/bin is in Your PATH
1190 \protected_separator
1197 bin to your path however your Win32 system allows.
1198 \protected_separator
1203 \protected_separator
1204 example you may add it to the PATH statement in autoexec.bat.
1209 \protected_separator
1214 \protected_separator
1216 \protected_separator
1217 If you have any questions send them to me or post them
1221 \protected_separator
1227 \begin_inset LatexCommand \label{Compiling}
1234 Single Source file projects.
1235 \begin_inset LatexCommand \label{One Source File}
1242 For single source file projects the process is very simple.
1243 Compile your programs with the following command
1251 The above command will compile ,assemble and link your source file.
1252 Output files are as follows.
1257 sourcefile.asm - Assembler source file created by the compiler
1262 sourcefile.lst - Assembler listing file created by the Assembler
1267 sourcefile.rst - Assembler listing file updated with linkedit information
1268 , created by linkage editor
1273 sourcefile.sym - symbol listing for the sourcefile, created by the assembler.
1278 sourcefile.rel - Object file created by the assembler, input to Linkage editor.
1283 sourcefile.map - The memory map for the load module, created by the Linker.
1288 sourcefile.<ihx | s19> - The load module : ihx - Intel hex format (default
1289 ), s19 - Motorola S19 format when compiler option --out-fmt-s19 is used.
1292 Projects with multiple source files.
1295 SDCC can compile only ONE file at a time.
1296 Let us for example assume that you have a project containing the following
1302 foo1.c ( contains some functions )
1307 foo2.c (contains some more functions)
1312 foomain.c (contains more functions and the function main)
1315 The first two files will need to be compiled separately with the commands
1328 Then compile the source file containing main and link the other files together
1329 with the following command.
1334 sdcc foomain.c foo1.rel foo2.rel
1341 can be separately compiled as well
1351 sdcc foomain.rel foo1.rel foo2.rel
1354 The file containing the main function MUST be the FIRST file specified in
1355 the command line , since the linkage editor processes file in the order
1356 they are presented to it.
1359 Projects with additional libraries.
1362 Some reusable routines may be compiled into a library, see the documentation
1363 for the assembler and linkage editor in the directory
1365 SDCCDIR/asxxxx/asxhtm.htm
1367 this describes how to create a
1371 library file, the libraries created in this manner may be included using
1372 the command line, make sure you include the -L <library-path> option to
1373 tell the linker where to look for these files.
1374 Here is an example, assuming you have the source file
1391 sdcc foomain.c foolib.lib -L mylib
1398 ' must be an absolute path name.
1401 The view of the way the linkage editor processes the library files, it is
1402 recommended that you put each source routine in a separate file and combine
1403 them using the .lib file.
1404 For an example see the standard library file 'libsdcc.lib' in the directory
1408 Command Line options
1409 \begin_inset LatexCommand \label{Command Line Options}
1422 \begin_inset LatexCommand \label{--model-large}
1430 Generate code for Large model programs see section Memory Models for more
1432 If this option is used all source files in the project should be compiled
1434 In addition the standard library routines are compiled with small model
1435 , they will need to be recompiled.
1450 \begin_inset LatexCommand \label{--model-small}
1454 Generate code for Small Model programs see section Memory Models for more
1456 This is the default model.
1471 \begin_inset LatexCommand \ref[--model-flat24]{--model-flat24}
1475 Generate code for Small Model programs see section Memory Models for more
1477 This is the default model.
1493 \begin_inset LatexCommand \label{--stack-auto}
1497 All functions in the source file will be compiled as
1502 the parameters and local variables will be allocated on the stack.
1503 see section Parameters and Local Variables for more details.
1504 If this option is used all source files in the project should be compiled
1518 \begin_inset LatexCommand \label{--xstack}
1522 Uses a pseudo stack in the first 256 bytes in the external ram for allocating
1523 variables and passing parameters.
1524 See section on external stack for more details.
1536 \begin_inset LatexCommand \label{--nogcse}
1540 Will not do global subexpression elimination, this option may be used when
1541 the compiler creates undesirably large stack/data spaces to store compiler
1543 A warning message will be generated when this happens and the compiler
1544 will indicate the number of extra bytes it allocated.
1545 It recommended that this option NOT be used , #pragma NOGCSE can be used
1546 to turn off global subexpression elimination for a given function only.
1558 \begin_inset LatexCommand \label{--noinvariant}
1562 Will not do loop invariant optimizations, this may be turned off for reasons
1563 explained for the previous option .
1564 For more details of loop optimizations performed see section Loop Invariants.It
1565 recommended that this option NOT be used , #pragma NOINVARIANT can be used
1566 to turn off invariant optimizations for a given function only.
1578 \begin_inset LatexCommand \label{--noinduction}
1582 Will not do loop induction optimizations, see section Strength reduction
1583 for more details.It recommended that this option NOT be used , #pragma NOINDUCTI
1584 ON can be used to turn off induction optimizations for given function only.
1596 \begin_inset LatexCommand \label{--nojtbound}
1600 Will not generate boundary condition check when switch statements are implement
1601 ed using jump-tables.
1602 See section Switch Statements for more details.It recommended that this
1603 option NOT be used , #pragma NOJTBOUND can be used to turn off boundary
1604 checking for jump tables for a given function only.
1617 \begin_inset LatexCommand \label{--noloopreverse}
1621 Will not do loop reversal optimization
1633 \begin_inset LatexCommand \label{--noregparms}
1637 By default the first parameter is passed using global registers (DPL,DPH,B,ACC).
1638 This option will disable parameter passing using registers.
1639 NOTE: if your program uses the 16/32 bit support routines (for multiplication/d
1640 ivision) these library routines will need to be recompiled with the --noregparms
1648 --callee-saves function1[,function2][,function3]....
1654 \begin_inset LatexCommand \label{--callee-saves}
1658 The compiler by default uses a caller saves convention for register saving
1659 across function calls, however this can cause unneccessary register pushing
1660 & popping when calling small functions from larger functions.
1661 This option can be used to switch the register saving convention for the
1662 function names specified.
1663 The compiler will not save registers when calling these functions, extra
1664 code will be generated at the entry & exit for these functions to save
1665 & restore the registers used by these functions, this can SUBSTANTIALLY
1666 reduce code & improve run time performance of the generated code.
1667 In future the compiler (with interprocedural analysis) will be able to
1668 determine the appropriate scheme to use for each function call.
1669 DO NOT use this option for built-in functions such as _muluint..., if this
1670 option is used for a library function the appropriate library function
1671 needs to be recompiled with the same option.
1672 If the project consists of multiple source files then all the source file
1673 should be compiled with the same --callee-saves option string.
1674 Also see Pragma Directive
1675 \begin_inset LatexCommand \ref{Pragmaa}
1680 \begin_inset LatexCommand \ref{pragma callee-saves}
1694 \begin_inset LatexCommand \label{--debug}
1698 When this option is used the compiler will generate debug information ,
1699 that can be used with the SDCDB.
1700 The debug information is collected in a file with .cdb extension.
1701 For more information see documentation for SDCDB.
1714 \begin_inset LatexCommand \label{--regextend}
1718 This option will cause the compiler to define pseudo registers , if this
1719 option is used, all source files in the project should be compiled with
1721 See section Register Extension for more details.
1734 \begin_inset LatexCommand \label{--compile-only}
1738 will compile and assemble the source only, will not call the linkage editor.
1750 \begin_inset LatexCommand \label{--xram-loc}
1754 <Value> The start location of the external ram, default value is 0.
1755 The value entered can be in Hexadecimal or Decimal format .eg.
1756 --xram-loc 0x8000 or --xram-loc 32768.
1769 \begin_inset LatexCommand \label{--code-loc}
1773 <Value> The start location of the code segment , default value 0.
1774 Note when this option is used the interrupt vector table is also relocated
1775 to the given address.
1776 The value entered can be in Hexadecimal or Decimal format .eg.
1777 --code-loc 0x8000 or --code-loc 32768.
1789 \begin_inset LatexCommand \label{--stack-loc}
1793 <Value> The initial value of the stack pointer.
1794 The default value of the stack pointer is 0x07 if only register bank 0
1795 is used, if other register banks are used then the stack pointer is initialized
1796 to the location above the highest register bank used.
1798 if register banks 1 & 2 are used the stack pointer will default to location
1800 The value entered can be in Hexadecimal or Decimal format .eg.
1801 --stack-loc 0x20 or --stack-loc 32.
1802 If all four register banks are used the stack will be placed after the
1803 data segment (equivalent to --stack-after-data)
1815 \begin_inset LatexCommand \label{--stack-after-data}
1819 This option will cause the stack to be located in the internal ram after
1833 \begin_inset LatexCommand \label{--data-loc}
1837 <Value> The start location of the internal ram data segment, the default
1838 value is 0x30.The value entered can be in Hexadecimal or Decimal format
1840 --data-loc 0x20 or --data-loc 32.
1852 \begin_inset LatexCommand \label{--idata-loc}
1856 <Value> The start location of the indirectly addressable internal ram, default
1858 The value entered can be in Hexadecimal or Decimal format .eg.
1859 --idata-loc 0x88 or --idata-loc 136.
1869 \begin_inset LatexCommand \label{--peep-file}
1876 <filename> This option can be used to use additional rules to be used by
1877 the peep hole optimizer.
1878 See section Peep Hole optimizations for details on how to write these rules.
1891 \begin_inset LatexCommand \label{--lib-path}
1895 <absolute path to additional libraries> This option is passed to the linkage
1896 editor, additional libraries search path.
1897 The path name must be absolute.
1898 Additional library files may be specified in the command line .
1899 See section Compiling programs for more details.
1906 \begin_inset LatexCommand \label{-I}
1913 The additional location where the pre processor will look for <..h> or
1914 \begin_inset Quotes eld
1918 \begin_inset Quotes erd
1933 \begin_inset LatexCommand \label{-D}
1937 Command line definition of macros.
1938 Passed to the pre processor.
1950 \begin_inset LatexCommand \label{-E}
1954 Run only the C preprocessor.
1955 Preprocess all the C source files specified and output the results to standard
1966 \begin_inset LatexCommand \label{-M}
1973 Tell the preprocessor to output a rule suitable for make describing the
1974 dependencies of each object file.
1975 For each source file, the preprocessor outputs one make-rule whose target
1976 is the object file name for that source file and whose dependencies are
1977 all the files `#include'd in it.
1978 This rule may be a single line or may be continued with `
1980 '-newline if it is long.
1981 The list of rules is printed on standard output instead of the preprocessed
1995 \begin_inset LatexCommand \label{-C}
1999 Tell the preprocessor not to discard comments.
2000 Used with the `-E' option.
2012 \begin_inset LatexCommand \label{-MM}
2016 Like `-M' but the output mentions only the user header files included with
2018 System header files included with `#include <file>' are omitted.
2030 \begin_inset LatexCommand \label{-Aquestion(answer)}
2034 Assert the answer answer for question, in case it is tested with a preprocessor
2035 conditional such as `#if #question(answer)'.
2036 `-A-' disables the standard asser- tions that normally describe the target
2049 \begin_inset LatexCommand \label{-Aquestion}
2053 (answer) Assert the answer answer for question, in case it is tested with
2054 a preprocessor conditional such as `#if #question(answer)'.
2055 `-A-' disables the standard assertions that normally describe the target
2068 \begin_inset LatexCommand \label{-Umacro}
2072 Undefine macro macro.
2073 `-U' options are evaluated after all `-D' options, but before any `-include'
2074 and `-imac- ros' options.
2086 \begin_inset LatexCommand \label{-dM}
2090 Tell the preprocessor to output only a list of the mac- ro definitions
2091 that are in effect at the end of prepro- cessing.
2092 Used with the `-E' option.
2104 \begin_inset LatexCommand \label{-dD}
2108 Tell the preprocessor to pass all macro definitions into the output, in
2109 their proper sequence in the rest of the output.
2121 \begin_inset LatexCommand \label{-dN}
2125 Like `-dD' except that the macro arguments and contents are omitted.
2126 Only `#define name' is included in the output.
2138 \begin_inset LatexCommand \label{-S}
2142 Stop after the stage of compilation proper; do not as- semble.
2143 The output is an assembler code file for the input file specified.
2149 -Wa asmOption[,asmOption]
2153 Pass the asmOption to the assembler
2159 -Wl linkOption[,linkOption]
2163 Pass the linkOption to the linker.
2176 \begin_inset LatexCommand \label{--int-long-rent}
2180 Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
2181 Note by default these libraries are compiled as non-reentrant.
2182 See section Installation for more details.
2195 \begin_inset LatexCommand \label{--cyclomatic}
2199 This option will cause the compiler to generate an information message for
2200 each function in the source file.
2201 The message contains some
2205 information about the function.
2206 The number of edges and nodes the compiler detected in the control flow
2207 graph of the function, and most importantly the
2209 cyclomatic complexity
2211 see section on Cyclomatic Complexity for more details.
2224 \begin_inset LatexCommand \label{--float-reent}
2228 Floating point library is compiled as reentrant.See section Installation
2239 \begin_inset LatexCommand \label{--out-fmt-ihx}
2246 The linker output (final object code) is in Intel Hex format.
2247 (This is the default option).
2260 \begin_inset LatexCommand \label{--out-fmt-s19}
2264 The linker output (final object code) is in Motorola S19 format.
2276 \begin_inset LatexCommand \label{--nooverlay}
2280 The compiler will not overlay parameters and local variables of any function,
2281 see section Parameters and local variables for more details.
2293 \begin_inset LatexCommand \label{--main-return}
2297 This option can be used when the code generated is called by a monitor
2299 The compiler will generate a 'ret' upon return from the 'main' function.
2300 The default option is to lock up i.e.
2301 generate a 'ljmp .' .
2313 \begin_inset LatexCommand \label{--no-peep}
2317 Disable peep-hole optimization.
2329 \begin_inset LatexCommand \label{--peep-asm}
2333 Pass the inline assembler code through the peep hole optimizer.
2334 Can cause unexpected changes to inline assembler code , please go through
2335 the peephole optimizer rules defnied in file 'SDCCpeeph.def' before using
2348 \begin_inset LatexCommand \label{--iram-size}
2352 <Value> Causes the linker to check if the interal ram usage is within limits
2356 The following options are provided for the purpose of retargetting and debugging
2358 These provided a means to dump the intermediate code (iCode) generated
2359 by the compiler in human readable form at various stages of the compilation
2373 \begin_inset LatexCommand \label{--dumpraw}
2378 This option will cause the compiler to dump the intermediate code into
2381 <source filename>.dumpraw
2383 just after the intermediate code has been generated for a function , i.e.
2384 before any optimizations are done.
2385 The basic blocks at this stage ordered in the depth first number, so they
2386 may not be in sequence of execution.
2399 \begin_inset LatexCommand \label{--dumpgcse}
2403 Will create a dump if iCode, after global subexpression elimination, into
2406 <source filename>.dumpgcse.
2418 \begin_inset LatexCommand \label{--dumpdeadcode}
2422 .Will create a dump if iCode, after deadcode elimination, into a file named
2425 <source filename>.dumpdeadcode.
2439 \begin_inset LatexCommand \label{--dumploop}
2443 Will create a dump if iCode, after loop optimizations, into a file named
2446 <source filename>.dumploop.
2460 \begin_inset LatexCommand \label{--dump-range}
2464 Will create a dump if iCode, after live range analysis, into a file named
2467 <source filename>.dumprange.
2481 \begin_inset LatexCommand \label{--dumpregassign}
2485 Will create a dump if iCode, after register assignment , into a file named
2488 <source filename>.dumprassgn.
2501 \begin_inset LatexCommand \label{--dumpall}
2505 Will cause all the above mentioned dumps to be created.
2508 Note that the files created for the dump are appended to each time.
2509 So the files should be deleted manually , before each dump is created.
2513 When reporting bugs, it will be very helpful if you could include these
2514 dumps along with the portion of the code that is causing the problem.
2518 \begin_inset LatexCommand \label{Language Extension}
2526 \begin_inset LatexCommand \label{Storage Classes}
2533 In addition to the ANSI storage classes SDCC allows the following 8051 specific
2535 \layout Subsubsection
2538 \begin_inset LatexCommand \label{xdata}
2545 Variables declared with this storage class will be placed in the extern
2551 storage class for Large Memory model .
2559 xdata unsigned char xduc;
2560 \layout Subsubsection
2563 \begin_inset LatexCommand \label{data}
2574 storage class for Small Memory model.
2575 Variables declared with this storage class will be allocated in the internal
2585 \layout Subsubsection
2588 \begin_inset LatexCommand \label{idata}
2595 Variables declared with this storage class will be allocated into the indirectly
2596 addressable portion of the internal ram of a 8051 .
2604 \layout Subsubsection
2607 \begin_inset LatexCommand \label{bit}
2614 This is a data-type and a storage class specifier.
2615 When a variable is declared as a bit , it is allocated into the bit addressable
2622 \layout Subsubsection
2625 \begin_inset LatexCommand \label{sfr / sbit}
2632 Like the bit keyword,
2636 signifies both a data-type and storage class, they are used to describe
2637 the special function registers and special bit variables of a 8051.
2652 /* special function register P0 at location 0x80 */
2663 \begin_inset LatexCommand \label{Optimizations}
2670 SDCC performs a a host of standard optimizations in addition to some MCU
2671 specific optimizations.
2675 Sub-expression elimination
2676 \begin_inset LatexCommand \label{Sub-expression Elimination}
2687 common subexpression elimination.
2708 will be translated to
2720 Some subexpressions are not as obvious as the above example.
2733 In this case the address arithmetic
2737 will be computed only once; the equivalent code in C would be.
2749 The compiler will try to keep these temporary variables in registers.
2752 Dead-Code elimination.
2753 \begin_inset LatexCommand \label{Dead-code elimination}
2770 \protected_separator
2772 \protected_separator
2776 \protected_separator
2778 \protected_separator
2780 \protected_separator
2782 \protected_separator
2784 \protected_separator
2788 \protected_separator
2790 \protected_separator
2791 global = 1; /* dead store */
2794 \protected_separator
2796 \protected_separator
2800 \protected_separator
2802 \protected_separator
2806 \protected_separator
2808 \protected_separator
2809 global = 3; /* unreachable */
2819 int global; void f ()
2822 \protected_separator
2824 \protected_separator
2828 \protected_separator
2830 \protected_separator
2832 \protected_separator
2836 \protected_separator
2843 \begin_inset LatexCommand \label{Copy-Propagation}
2858 \protected_separator
2860 \protected_separator
2862 \protected_separator
2866 \protected_separator
2868 \protected_separator
2870 \protected_separator
2874 \protected_separator
2876 \protected_separator
2878 \protected_separator
2882 \protected_separator
2884 \protected_separator
2886 \protected_separator
2900 \protected_separator
2902 \protected_separator
2906 \protected_separator
2908 \protected_separator
2912 \protected_separator
2914 \protected_separator
2918 \protected_separator
2920 \protected_separator
2926 Note: the dead stores created by this copy propagation will be eliminated
2927 by dead-code elimination .
2931 \begin_inset LatexCommand \label{Loop Optimizations}
2938 Two types of loop optimizations are done by SDCC loop invariant lifting
2939 and strength reduction of loop induction variables.In addition to the strength
2940 reduction the optimizer marks the induction variables and the register
2941 allocator tries to keep the induction variables in registers for the duration
2943 Because of this preference of the register allocator , loop induction optimizat
2944 ion causes an increase in register pressure, which may cause unwanted spilling
2945 of other temporary variables into the stack / data space .
2946 The compiler will generate a warning message when it is forced to allocate
2947 extra space either on the stack or data space.
2948 If this extra space allocation is undesirable then induction optimization
2949 can be eliminated either for the entire source file ( with --noinduction
2950 option) or for a given function only (#pragma NOINDUCTION).
2951 \layout Subsubsection
2954 \begin_inset LatexCommand \label{Loop Invariant}
2966 for (i = 0 ; i < 100 ; i ++)
2969 \protected_separator
2971 \protected_separator
2973 \protected_separator
2984 for ( i = 0; i < 100; i++ ) f += itemp;
2987 As mentioned previously some loop invariants are not as apparent, all static
2988 address computations are also moved out of the loop.
2989 \layout Subsubsection
2991 Strength reduction :
2992 \begin_inset LatexCommand \label{Strength Reduction}
2999 This optimization substitutes an expression by a cheaper expression.
3007 for (i=0;i < 100; i++) ar[i*5] = i*3;
3019 for (i=0;i< 100;i++) {
3022 \protected_separator
3024 \protected_separator
3026 \protected_separator
3027 ar[itemp1] = itemp2;
3030 \protected_separator
3032 \protected_separator
3034 \protected_separator
3038 \protected_separator
3040 \protected_separator
3042 \protected_separator
3048 The more expensive multiplication is changed to a less expensive addition.
3049 \layout Subsubsection
3052 \begin_inset LatexCommand \label{Loop reversing}
3059 This optimization is done to reduce the overhead of checking loop boundaries
3060 for every iteration.
3061 Some simple loops can be reversed and implemented using a
3062 \begin_inset Quotes eld
3065 decrement and jump if not zero
3066 \begin_inset Quotes erd
3070 SDCC checks for the following criterion to determine if a loop is reversible
3071 (note: more sophisticated compiers use data-dependency analysis to make
3072 this determination, SDCC uses a more simple minded analysis).
3075 The 'for' loop is of the form
3078 \begin_inset Quotes eld
3081 for ( <symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ |
3085 \protected_separator
3087 \protected_separator
3089 \protected_separator
3091 \protected_separator
3093 \protected_separator
3095 \protected_separator
3097 \protected_separator
3099 \begin_inset Quotes erd
3105 The <for body> does not contain
3106 \begin_inset Quotes eld
3110 \begin_inset Quotes erd
3114 \begin_inset Quotes erd
3120 All goto's are contained within the loop.
3123 No function calls within the loop.
3126 The loop control variable <sym> is not assigned any value within the loop
3129 The loop control variable does NOT participate in any arithmetic operation
3133 There are NO switch statements in the loop.
3136 Note djnz instruction can be used for 8-bit values ONLY, therefore it is
3137 advantageous to declare loop control symbols as either 'char' or 'short',
3138 ofcourse this may not be possible on all situations.
3141 Algebraic simplifications:
3142 \begin_inset LatexCommand \label{Algebraic Simplifications}
3149 SDCC does numerous algebraic simplifications, the following is a small sub-set
3150 of these optimizations.
3161 i = j + 0 ; /* changed to */ i = j;
3163 i /= 2; /* changed to */ i >>= 1;
3165 i = j - j ; /* changed to */ i = 0;
3167 i = j / 1 ; /* changed to */ i = j;
3170 Note the subexpressions given above are generally introduced by macro expansions
3171 or as a result of copy/constant propagation.
3174 'switch' statements.
3175 \begin_inset LatexCommand \label{Switch Statement}
3182 SDCC changes switch statements to jump tables when the following conditions
3187 The case labels are in numerical sequence , the labels need not be in order,
3188 and the starting number need not be one or zero.
3197 \protected_separator
3199 \protected_separator
3201 \protected_separator
3203 \protected_separator
3205 \protected_separator
3207 \protected_separator
3209 \protected_separator
3211 \protected_separator
3213 \protected_separator
3215 \protected_separator
3217 \protected_separator
3219 \protected_separator
3221 \protected_separator
3226 \protected_separator
3228 \protected_separator
3230 \protected_separator
3232 \protected_separator
3234 \protected_separator
3236 \protected_separator
3238 \protected_separator
3240 \protected_separator
3242 \protected_separator
3244 \protected_separator
3246 \protected_separator
3248 \protected_separator
3250 \protected_separator
3256 \protected_separator
3258 \protected_separator
3260 \protected_separator
3262 \protected_separator
3264 \protected_separator
3266 \protected_separator
3268 \protected_separator
3270 \protected_separator
3272 \protected_separator
3274 \protected_separator
3276 \protected_separator
3278 \protected_separator
3280 \protected_separator
3286 \protected_separator
3288 \protected_separator
3290 \protected_separator
3292 \protected_separator
3294 \protected_separator
3296 \protected_separator
3298 \protected_separator
3300 \protected_separator
3302 \protected_separator
3304 \protected_separator
3306 \protected_separator
3308 \protected_separator
3310 \protected_separator
3316 \protected_separator
3318 \protected_separator
3320 \protected_separator
3322 \protected_separator
3324 \protected_separator
3326 \protected_separator
3328 \protected_separator
3330 \protected_separator
3332 \protected_separator
3334 \protected_separator
3336 \protected_separator
3338 \protected_separator
3340 \protected_separator
3345 \protected_separator
3347 \protected_separator
3349 \protected_separator
3351 \protected_separator
3353 \protected_separator
3355 \protected_separator
3357 \protected_separator
3359 \protected_separator
3361 \protected_separator
3363 \protected_separator
3365 \protected_separator
3367 \protected_separator
3369 \protected_separator
3371 \protected_separator
3373 \protected_separator
3375 \protected_separator
3377 \protected_separator
3379 \protected_separator
3383 Both the above switch statements will be implemented using a jump-table.
3386 The number of case labels is at least three, since it takes two conditional
3387 statements to handle the boundary conditions.
3390 The number of case labels is less than 84, since each label takes 3 bytes
3391 and a jump-table can be utmost 256 bytes long.
3395 Switch statements which have gaps in the numeric sequence or those that
3396 have more that 84 case labels can be split into more than one switch statement
3397 for efficient code generation.
3434 If the above switch statement is broken down into two switch statements
3475 then both the switch statements will be implemented using jump-tables whereas
3476 the unmodified switch statement will not be .
3479 bit-shifting operations.
3480 \begin_inset LatexCommand \label{bit shifting}
3487 Bit shifting is one of the most frequently used operation in embedded programmin
3489 SDCC tries to implement bit-shift operations in the most efficient way
3511 generates the following code.
3525 In general SDCC will never setup a loop if the shift count is known.
3557 Note that SDCC stores numbers in
3563 \layout Subsubsection
3566 \begin_inset LatexCommand \label{bit rotation}
3573 A special case of the bit-shift operation is bit rotation, SDCC recognizes
3574 the following expression to be a left bit-rotation.
3584 i = ( ( i << 1) | ( i >> 7));
3589 will generate the following code.
3601 SDCC uses pattern matching on the parse tree to determine this operation
3602 .Variations of this case will also be recognized as bit-rotation i.e
3604 i = ((i >> 7) | (i << 1));
3606 /* left-bit rotation */
3610 \begin_inset LatexCommand \label{Highest Order Bit}
3617 It is frequently required to obtain the highest order bit of an integral
3618 type (int,long,short or char types).
3619 SDCC recognizes the following expression to yield the highest order bit
3620 and generates optimized code for it.
3634 \protected_separator
3636 \protected_separator
3638 \protected_separator
3643 \protected_separator
3645 \protected_separator
3647 \protected_separator
3648 hob = (gint >> 15) & 1;
3651 \protected_separator
3653 \protected_separator
3655 \protected_separator
3662 Will generate the following code.
3668 \protected_separator
3670 \protected_separator
3672 \protected_separator
3674 \protected_separator
3676 \protected_separator
3678 \protected_separator
3680 \protected_separator
3682 \protected_separator
3684 \protected_separator
3686 \protected_separator
3688 \protected_separator
3690 \protected_separator
3692 \protected_separator
3694 \protected_separator
3696 \protected_separator
3698 \protected_separator
3700 \protected_separator
3702 \protected_separator
3704 \protected_separator
3706 \protected_separator
3708 \protected_separator
3710 \protected_separator
3712 \protected_separator
3714 \protected_separator
3716 \protected_separator
3718 \protected_separator
3720 \protected_separator
3722 \protected_separator
3724 \protected_separator
3728 \protected_separator
3730 \protected_separator
3732 \protected_separator
3734 \protected_separator
3736 \protected_separator
3738 \protected_separator
3740 \protected_separator
3742 \protected_separator
3744 \protected_separator
3746 \protected_separator
3748 \protected_separator
3750 \protected_separator
3752 \protected_separator
3754 \protected_separator
3756 \protected_separator
3758 \protected_separator
3760 \protected_separator
3762 \protected_separator
3764 \protected_separator
3766 \protected_separator
3768 \protected_separator
3770 \protected_separator
3772 \protected_separator
3774 \protected_separator
3776 \protected_separator
3778 \protected_separator
3782 \protected_separator
3784 \protected_separator
3786 \protected_separator
3788 \protected_separator
3790 \protected_separator
3792 \protected_separator
3794 \protected_separator
3796 \protected_separator
3798 \protected_separator
3800 \protected_separator
3802 \protected_separator
3804 \protected_separator
3806 \protected_separator
3808 \protected_separator
3810 \protected_separator
3812 \protected_separator
3814 \protected_separator
3816 \protected_separator
3818 \protected_separator
3820 \protected_separator
3822 \protected_separator
3824 \protected_separator
3826 \protected_separator
3828 \protected_separator
3830 \protected_separator
3832 \protected_separator
3834 \protected_separator
3836 \protected_separator
3838 \protected_separator
3842 \protected_separator
3844 \protected_separator
3846 \protected_separator
3848 \protected_separator
3850 \protected_separator
3852 \protected_separator
3854 \protected_separator
3856 \protected_separator
3858 \protected_separator
3860 \protected_separator
3862 \protected_separator
3864 \protected_separator
3866 \protected_separator
3868 \protected_separator
3870 \protected_separator
3872 \protected_separator
3874 \protected_separator
3876 \protected_separator
3878 \protected_separator
3880 \protected_separator
3882 \protected_separator
3884 \protected_separator
3886 \protected_separator
3888 \protected_separator
3890 \protected_separator
3892 \protected_separator
3894 \protected_separator
3896 \protected_separator
3898 \protected_separator
3902 \protected_separator
3904 \protected_separator
3906 \protected_separator
3908 \protected_separator
3910 \protected_separator
3912 \protected_separator
3914 \protected_separator
3916 \protected_separator
3918 \protected_separator
3920 \protected_separator
3922 \protected_separator
3924 \protected_separator
3926 \protected_separator
3928 \protected_separator
3930 \protected_separator
3932 \protected_separator
3934 \protected_separator
3936 \protected_separator
3938 \protected_separator
3940 \protected_separator
3942 \protected_separator
3944 \protected_separator
3946 \protected_separator
3948 \protected_separator
3950 \protected_separator
3952 \protected_separator
3954 \protected_separator
3956 \protected_separator
3958 \protected_separator
3962 \protected_separator
3964 \protected_separator
3966 \protected_separator
3968 \protected_separator
3970 \protected_separator
3972 \protected_separator
3974 \protected_separator
3976 \protected_separator
3978 \protected_separator
3980 \protected_separator
3982 \protected_separator
3984 \protected_separator
3986 \protected_separator
3988 \protected_separator
3990 \protected_separator
3992 \protected_separator
3994 \protected_separator
3996 \protected_separator
3998 \protected_separator
4000 \protected_separator
4002 \protected_separator
4004 \protected_separator
4006 \protected_separator
4008 \protected_separator
4010 \protected_separator
4012 \protected_separator
4016 Variations of this case however will NOT be recognized .
4017 It is a standard C expression , so I heartily recommend this be the only
4018 way to get the highest order bit, (it is portable).
4019 Of course it will be recognized even if it is embedded in other expressions.
4029 xyz = gint + ((gint >> 15) & 1);
4032 will still be recognized.
4035 Peep-hole optimizer.
4036 \begin_inset LatexCommand \label{Peep-Hole}
4043 The compiler uses a rule based , pattern matching and re-writing mechanism
4044 for peep-hole optimization .
4049 a peep-hole optimizer by Christopher W.
4050 Fraser (cwfraser@microsoft.com).
4051 A default set of rules are compiled into the compiler, additional rules
4052 may be added with the --peep-file <filename> option.
4053 The rule language is best illustrated with examples.
4062 mov a,%1 } by { mov %1,a }
4065 The above rule will the following assembly sequence
4083 Note: All occurrences of a '%n' ( pattern variable ) must denote the same
4085 With the above rule, the assembly sequence
4095 will remain unmodified.
4096 Other special case optimizations may be added by the user (via --peep-file
4098 some variants of the 8051 MCU allow only 'AJMP' and 'ACALL' , the following
4099 two rules will change all 'LJMP' & 'LCALL' to 'AJMP' & 'ACALL'.
4104 replace { lcall %1 } by { acall %1 }
4106 replace { ljmp %1 } by { ajmp %1 }
4109 The inline-assembler' code is also passed through the peep hole optimizer,
4110 thus the peephole optimizer can also be used as an assembly level macro
4112 The rules themselves are MCU dependent whereas the rule language infra-structur
4113 e is MCU independent.
4114 Peephole optimization rules for other MCU can be easily programmed using
4118 The syntax for a rule is as follows ,
4123 rule := replace [ restart ] '{' <assembly sequence> '
4128 \protected_separator
4130 \protected_separator
4132 \protected_separator
4134 \protected_separator
4136 \protected_separator
4138 \protected_separator
4140 \protected_separator
4142 \protected_separator
4144 \protected_separator
4146 \protected_separator
4148 \protected_separator
4150 \protected_separator
4152 \protected_separator
4154 \protected_separator
4160 \protected_separator
4162 \protected_separator
4164 \protected_separator
4166 \protected_separator
4168 \protected_separator
4170 \protected_separator
4172 \protected_separator
4174 \protected_separator
4176 \protected_separator
4178 \protected_separator
4180 \protected_separator
4182 \protected_separator
4184 \protected_separator
4186 \protected_separator
4188 \protected_separator
4190 \protected_separator
4191 <assembly sequence> '
4196 \protected_separator
4198 \protected_separator
4200 \protected_separator
4202 \protected_separator
4204 \protected_separator
4206 \protected_separator
4208 \protected_separator
4210 \protected_separator
4212 \protected_separator
4214 \protected_separator
4216 \protected_separator
4218 \protected_separator
4220 \protected_separator
4222 \protected_separator
4223 '}' [if <functionName> ] '
4227 <assembly sequence> := assembly instruction (each instruction including
4228 labels must be on a separate line).
4229 \protected_separator
4231 \protected_separator
4235 The optimizer will apply to the rules one by one from the top in the sequence
4236 of their appearance, it will terminate when all rules are exhausted.
4241 ' option is specified, then the optimizer will start matching the rules
4242 again from the top, this option for a rule is expensive (performance),
4243 it is intended to be used in situations where a transformation will trigger
4244 the same rule again.
4245 A good example of this the following rule.
4261 Note that the replace pattern cannot be a blank, but can be a comment line.
4266 ' option only the inner most 'pop' 'push' pair would be eliminated.
4297 ' option the rule will be applied again to the resulting code and the all
4302 pairs will be eliminated to yield
4312 A conditional function can be attached to a rule.
4313 Attaching rules are somewhat more involved, let me illustrate this with
4322 \protected_separator
4324 \protected_separator
4326 \protected_separator
4332 \protected_separator
4334 \protected_separator
4336 \protected_separator
4339 %2:} if labelInRange
4342 The optimizer does a look-up of a function name table defined in function
4355 ', if it finds a corresponding entry the function is called.
4356 Note there can be no parameters specified for these functions, in this
4361 ' is crucial, since the function
4365 expects to find the label in that particular variable (the hash table containin
4366 g the variable bindings is passed as a parameter).
4367 If you want to code more such functions , take a close look at the function
4372 and the calling mechanism in source file
4377 I know this whole thing is a little kludgey , may be some day we will have
4379 If you are looking at this file, you will also see the default rules that
4380 are compiled into the compiler, you can your own rules in the default set
4381 there if you get tired of specifying the
4389 \begin_inset LatexCommand \label{Pointers}
4396 SDCC allows (via language extensions) pointers to explicitly point to any
4397 of the memory spaces of the 8051.
4398 In addition to the explicit pointers, the compiler also allows a
4402 class of pointers which can be used to point to any of the memory spaces.
4406 Pointer declaration examples.
4411 /* pointer physically in xternal ram pointing to object in internal ram
4414 data unsigned char * xdata p;
4421 /* pointer physically in code rom pointing to data in xdata space */
4423 xdata unsigned char * code p;
4430 /* pointer physically in code space pointing to data in code space */
4432 code unsigned char * code p;
4436 /* the folowing is a generic pointer physically located in xdata space */
4441 Well you get the idea.
4442 For compatibility with the previous version of the compiler, the following
4443 syntax for pointer declaration is also supported.
4444 Note the above examples will be portable to other commercially available
4450 unsigned char _xdata *ucxdp; /* pointer to data in external ram */
4453 \protected_separator
4454 *ucdp ; /* pointer to data in internal ram */
4457 \protected_separator
4458 *uccp ; /* pointer to data in R/O code space */
4460 unsigned char _idata *uccp;
4461 \protected_separator
4462 /* pointer to upper 128 bytes of ram */
4465 All unqualified pointers are treated as 3 - byte '_generic' pointers.
4466 These type of pointers can also to be explicitly declared.
4471 unsigned char _generic *ucgp;
4474 The highest order byte of the generic pointers contains the data space informati
4476 Assembler support routines are called whenever data is stored or retrieved
4477 using _generic pointers.
4478 These are useful for developing reusable library routines.
4479 Explicitly specifying the pointer type will generate the most efficient
4481 Pointers declared using a mixture of OLD/NEW style could have unpredictable
4485 Parameters & Local Variables
4486 \begin_inset LatexCommand \label{Auto Variables}
4493 Automatic (local) variables and parameters to functions can either be placed
4494 on the stack or in data-space.
4495 The default action of the compiler is to place these variables in the internal
4496 RAM ( for small model) or external RAM (for Large model).
4497 They can be placed on the stack either by using the
4501 compiler option or by using the 'reentrant' keyword in the function declaration.
4512 unsigned short foo( short i) reentrant {
4520 Note that when the parameters & local variables are declared in the internal/ext
4521 ernal ram the functions are non-reentrant.
4522 Since stack space on 8051 is limited the
4530 option should be used sparingly.
4531 Note the reentrant keyword just means that the parameters & local variables
4532 will be allocated to the stack, it DOES NOT mean that the function is register
4536 When compiled with the default option (i.e.
4537 non-reentrant ), local variables can be assigned storage classes and absolute
4550 unsigned short foo() {
4553 \protected_separator
4555 \protected_separator
4556 xdata unsigned short i;
4559 \protected_separator
4561 \protected_separator
4565 \protected_separator
4567 \protected_separator
4568 data at 0x31 unsiged short j;
4576 In the above example the variable
4580 will be allocated in the external ram,
4584 in bit addressable space and
4589 When compiled with the
4593 or when a function is declared as
4597 local variables cannot be assigned storage classes or absolute addresses.
4600 Parameters however are not allowed any storage class, (storage classes for
4601 parameters will be ignored), their allocation is governed by the memory
4602 model in use , and the reentrancy options.
4606 \begin_inset LatexCommand \label{Overlaying}
4613 For non-reentrant functions SDCC will try to reduce internal ram space usage
4614 by overlaying parameters and local variables of a function (if possible).
4615 Parameters and local variables of a function will be allocated to an overlayabl
4616 e segment if the function has
4618 no other function calls and the function is non-reentrant and the memory
4622 If an explicit storage class is specified for a local variable , it will
4626 Note that the compiler (not the linkage editor) makes the decision for overlayin
4628 Functions that are called from an interrupt service routine should be preceded
4629 by a #pragma NOOVERLAY if they are not reentrant Along the same lines the
4630 compiler does not do any processing with the inline assembler code so the
4631 compiler might incorrectly assign local variables and parameters of a function
4632 into the overlay segment if the only function call from a function is from
4633 inline assembler code, it is safe to use the #pragma NOOVERLAY for functions
4634 which call other functions using inline assembler code.
4637 Parameters and Local variables of functions that contain 16 or 32 bit multiplica
4638 tion or division will NOT be overlayed since these are implemented using
4651 void set_error( unsigned short errcd)
4656 \protected_separator
4658 \protected_separator
4665 void some_isr () interrupt 2 using 1
4670 \protected_separator
4672 \protected_separator
4677 \protected_separator
4679 \protected_separator
4683 \protected_separator
4685 \protected_separator
4692 In the above example the parameter
4700 would be assigned to the overlayable segment (if the #pragma NOOVERLAY
4701 was not present) , this could cause unpredictable runtime behavior.
4702 The pragma NOOVERLAY ensures that the parameters and local variables for
4703 the function are NOT overlayed.
4707 \begin_inset LatexCommand \label{Critical}
4714 A special keyword may be associated with a function declaring it as '
4719 SDCC will generate code to disable all interrupts upon entry to a critical
4720 function and enable them back before returning .
4721 Note that nesting critical functions may cause unpredictable results.
4742 The critical attribute maybe used with other attributes like
4747 Absolute addressing.
4748 \begin_inset LatexCommand \label{Absolute Addressing}
4755 Data items can be assigned an absolute address with the
4759 keyword, in addition to a storage class.
4768 xdata at 0x8000 unsigned char PORTA_8255 ;
4771 In the above example the
4775 will be allocated to the location 0x8000 of the external ram.
4779 Note that is this feature is provided to give the programmer access to
4783 devices attached to the controller.
4784 The compiler does not actually reserve any space for variables declared
4785 in this way (they are implemented with an equate in the assembler), thus
4786 it is left to the programmer to make sure there are no overlaps with other
4787 variables that are declared without the absolute address, the assembler
4788 listing file (.lst) and the linker output files (<filename>.rst) and (<filename>.m
4789 ap) are a good places to look for such overlaps.
4792 Absolute address can be specified for variables in all storage classes.
4805 The above example will allocate the variable at offset 0x02 in the bit-addressab
4807 There is no real advantage to assigning absolute addresses to variables
4808 in this manner , unless you want strict control over all the variables
4812 Interrupt Service Routines
4813 \begin_inset LatexCommand \label{Interrupt Service Rouines}
4820 SDCC allows interrupt service routines to be coded in C, with some extended
4826 void timer_isr (void) interrupt 2 using 1
4836 The number following the 'interrupt' keyword is the interrupt number this
4837 routine will service.
4838 The compiler will insert a call to this routine in the interrupt vector
4839 table for the interrupt number specified.
4840 The 'using' keyword is used to tell the compiler to use the specified register
4841 bank (8051 specific) when generating code for this function.
4842 Note that when some function is called from an interrupt service routine
4843 it should be preceded by a #pragma NOOVERLAY (if it is not reentrant) .
4844 A special note here, int (16 bit) and long (32 bit) integer division, multiplic
4845 ation & modulus operations are implemented using external support routines
4846 developed in ANSI-C, if an interrupt service routine needs to do any of
4847 these operations then the support routines (as mentioned in a following
4848 section) will have to recompiled using the --stack-auto option and the
4849 source file will need to be compiled using the --int-long-rent compiler
4853 If you have multiple source files in your project, interrupt service routines
4854 can be present in any of them, but a prototype of the isr MUST be present
4855 in the file that contains the function
4862 Interrupt Numbers and the corresponding address & descriptions for the Standard
4863 8051 are listed below.
4864 SDCC will automatically adjust the interrupt vector table to the maximum
4865 interrupt number specified.
4869 \protected_separator
4871 \protected_separator
4873 \protected_separator
4875 \protected_separator
4877 \protected_separator
4879 \protected_separator
4881 \protected_separator
4883 \protected_separator
4885 \protected_separator
4887 \protected_separator
4889 \protected_separator
4891 \protected_separator
4893 \protected_separator
4895 \protected_separator
4897 \protected_separator
4899 \protected_separator
4901 \protected_separator
4903 \protected_separator
4907 \protected_separator
4909 \protected_separator
4911 \protected_separator
4913 \protected_separator
4915 \protected_separator
4917 \protected_separator
4919 \protected_separator
4921 \protected_separator
4923 \protected_separator
4925 \protected_separator
4927 \protected_separator
4929 \protected_separator
4931 \protected_separator
4933 \protected_separator
4935 \protected_separator
4937 \protected_separator
4939 \protected_separator
4941 \protected_separator
4943 \protected_separator
4945 \protected_separator
4947 \protected_separator
4949 \protected_separator
4951 \protected_separator
4953 \protected_separator
4955 \protected_separator
4957 \protected_separator
4959 \protected_separator
4961 \protected_separator
4963 \protected_separator
4965 \protected_separator
4969 \protected_separator
4971 \protected_separator
4973 \protected_separator
4975 \protected_separator
4977 \protected_separator
4979 \protected_separator
4981 \protected_separator
4983 \protected_separator
4985 \protected_separator
4987 \protected_separator
4989 \protected_separator
4991 \protected_separator
4993 \protected_separator
4995 \protected_separator
4997 \protected_separator
4999 \protected_separator
5001 \protected_separator
5003 \protected_separator
5005 \protected_separator
5007 \protected_separator
5009 \protected_separator
5011 \protected_separator
5013 \protected_separator
5015 \protected_separator
5017 \protected_separator
5019 \protected_separator
5021 \protected_separator
5023 \protected_separator
5025 \protected_separator
5027 \protected_separator
5029 \protected_separator
5031 \protected_separator
5033 \protected_separator
5037 \protected_separator
5039 \protected_separator
5041 \protected_separator
5043 \protected_separator
5045 \protected_separator
5047 \protected_separator
5049 \protected_separator
5051 \protected_separator
5053 \protected_separator
5055 \protected_separator
5057 \protected_separator
5059 \protected_separator
5061 \protected_separator
5063 \protected_separator
5065 \protected_separator
5067 \protected_separator
5069 \protected_separator
5071 \protected_separator
5073 \protected_separator
5075 \protected_separator
5077 \protected_separator
5079 \protected_separator
5081 \protected_separator
5083 \protected_separator
5085 \protected_separator
5087 \protected_separator
5089 \protected_separator
5091 \protected_separator
5093 \protected_separator
5095 \protected_separator
5099 \protected_separator
5101 \protected_separator
5103 \protected_separator
5105 \protected_separator
5107 \protected_separator
5109 \protected_separator
5111 \protected_separator
5113 \protected_separator
5115 \protected_separator
5117 \protected_separator
5119 \protected_separator
5121 \protected_separator
5123 \protected_separator
5125 \protected_separator
5127 \protected_separator
5129 \protected_separator
5131 \protected_separator
5133 \protected_separator
5135 \protected_separator
5137 \protected_separator
5139 \protected_separator
5141 \protected_separator
5143 \protected_separator
5145 \protected_separator
5147 \protected_separator
5149 \protected_separator
5151 \protected_separator
5153 \protected_separator
5155 \protected_separator
5157 \protected_separator
5159 \protected_separator
5161 \protected_separator
5165 \protected_separator
5167 \protected_separator
5169 \protected_separator
5171 \protected_separator
5173 \protected_separator
5175 \protected_separator
5177 \protected_separator
5179 \protected_separator
5181 \protected_separator
5183 \protected_separator
5185 \protected_separator
5187 \protected_separator
5189 \protected_separator
5191 \protected_separator
5193 \protected_separator
5195 \protected_separator
5197 \protected_separator
5199 \protected_separator
5201 \protected_separator
5203 \protected_separator
5205 \protected_separator
5207 \protected_separator
5209 \protected_separator
5211 \protected_separator
5213 \protected_separator
5215 \protected_separator
5217 \protected_separator
5219 \protected_separator
5221 \protected_separator
5223 \protected_separator
5225 \protected_separator
5227 \protected_separator
5229 \protected_separator
5233 If the interrupt service routine is defined without a register bank or with
5234 register bank 0 (using 0), the compiler will save the registers used by
5235 itself on the stack (upon entry and restore them at exit), however if such
5236 an interrupt service routine calls another function then the entire register
5237 bank will be saved on the stack.
5238 This scheme may be advantageous for small interrupt service routines which
5239 have low register usage.
5242 If the interrupt service routine is defined to be using a specific register
5244 \begin_inset Quotes eld
5248 \begin_inset Quotes erd
5252 \begin_inset Quotes erd
5256 \begin_inset Quotes erd
5260 \begin_inset Quotes eld
5264 \begin_inset Quotes erd
5267 are save and restored, if such an interrupt service routine calls another
5268 function (using another register bank) then the entire register bank of
5269 the called function will be saved on the stack.
5270 This scheme is recommended for larger interrupt service routines.
5273 Calling other functions from an interrupt service routine is not recommended
5274 avoid it if possible.
5278 \begin_inset LatexCommand \label{Startup}
5285 The compiler inserts a jump to the C routine
5287 _sdcc__external__startup()
5289 at the start of the CODE area.
5290 This routine can be found in the file
5292 SDCCDIR/sdcc51lib/_startup.c
5294 , by default this routine returns 0, if this routine returns a non-zero
5295 value , the static & global variable initialization will be skipped and
5296 the function main will be invoked, other wise static & global variables
5297 will be initialized before the function main is invoked.
5300 Inline assembler code.
5301 \begin_inset LatexCommand \label{Inline}
5308 SDCC allows the use of in-line assembler with a few restriction as regards
5310 All labels defined within inline assembler code HAS TO BE of the
5314 where nnnn is a number less than 100 (which implies a limit of utmost 100
5315 inline assembler labels
5320 It is strongly recommended that each assembly instruction (including labels)
5321 be placed in a separate line ( as the example shows).
5328 command line option is used, the inline assembler code will be passed through
5329 the peephole optimizer, this might cause some unexpected changes in the
5330 inline assembler code, please go throught the peephole optimizer rules
5331 defined in file 'SDCCpeeph.def' carefully before using this option.
5344 \protected_separator
5346 \protected_separator
5348 \protected_separator
5350 \protected_separator
5352 \protected_separator
5358 \protected_separator
5360 \protected_separator
5362 \protected_separator
5364 \protected_separator
5366 \protected_separator
5372 The inline assembler code can contain any valid code understood by the assembler
5373 (this includes any assembler directives and comment lines ) .
5374 The compiler does not do any validation of the code within the
5383 Inline assembler code cannot reference any C-Labels however it can reference
5384 labels defined by the inline assembler.
5402 \protected_separator
5404 \protected_separator
5406 \protected_separator
5407 ; some assembler code
5410 \protected_separator
5412 \protected_separator
5418 /* some more c code */
5421 \protected_separator
5422 /* inline assembler cannot reference this label */
5427 \protected_separator
5429 \protected_separator
5430 $0003: ;label (can be reference by inline assembler only)
5440 In other words inline assembly code can access labels defined in inline
5442 The same goes the other way, ie.
5443 labels defines in inline assembly CANNOT be accessed by C statements.
5446 int (16 bit) and long (32 bit ) support.
5447 \begin_inset LatexCommand \label{int and long}
5454 For signed & unsigned int (16 bit) and long (32 bit) variables, division,
5455 multiplication and modulus operations are implemented by support routines.
5456 These support routines are all developed in ANSI-C to facilitate porting
5458 The following files contain the described routine, all of them can be found
5459 in the directory SDCCDIR/sdcc51lib
5464 _mulsint.c - signed 16 bit multiplication (calls _muluint)
5469 _muluint.c - unsigned 16 bit multiplication
5474 _divsint.c - signed 16 bit division (calls _divuint)
5479 _divuint.c - unsigned 16 bit division.
5484 _modsint.c - signed 16 bit modulus (call _moduint)
5489 _moduint.c - unsigned 16 bit modulus.
5494 _mulslong.c - signed 32 bit multiplication (calls _mululong)
5499 _mululong.c - unsigned32 bit multiplication.
5504 _divslong.c - signed 32 division (calls _divulong)
5509 _divulong.c - unsigned 32 division.
5514 _modslong.c - signed 32 bit modulus (calls _modulong).
5519 _modulong.c - unsigned 32 bit modulus.
5522 All these routines are compiled as non-reentrant and small model.
5523 Since they are compiled as non-reentrant, interrupt service routines should
5524 not do any of the above operations, if this unavoidable then the above
5525 routines will need to ne compiled with the --stack-auto option, after which
5526 the source program will have to be compiled with --int-long-rent option.
5529 Floating point support
5530 \begin_inset LatexCommand \label{Float}
5537 SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
5538 point support routines are derived from gcc's floatlib.c and consists of
5539 the following routines.
5545 _fsadd.c - add floating point numbers.
5550 _fssub.c - subtract floating point numbers
5555 _fsdiv.c - divide floating point numbers
5560 _fsmul.c - multiply floating point numbers
5565 _fs2uchar.c - convert floating point to unsigned char
5570 _fs2char.c - convert floating point to signed char.
5575 _fs2uint.c - convert floating point to unsigned int.
5580 _fs2int.c - convert floating point to signed int.
5585 _fs2ulong.c - convert floating point to unsigned long.
5590 _fs2long.c - convert floating point to signed long.
5595 _uchar2fs.c - convert unsigned char to floating point
5600 _char2fs.c - convert char to floating point number
5605 _uint2fs.c - convert unsigned int to floating point
5610 _int2fs.c - convert int to floating point numbers
5615 _ulong2fs.c - convert unsigned long to floating point number
5620 _long2fs.c - convert long to floating point number.
5623 Note if all these routines are used simultaneously the data space might
5625 For serious floating point usage it is strongly recommended that the Large
5626 model be used (in which case the floating point routines mentioned above
5627 will need to recompiled with the --model-Large option)
5631 \begin_inset LatexCommand \label{Memory Models}
5638 SDCC allows two memory models, modules compiled with different memory models
5639 should be combined together, the results would be unpredictable.
5640 The support routines supplied with the compiler are compiled in small-model
5641 by default, and will need to be recompiled using the large model if the
5642 large model is used.
5643 In general the use of the large model is discouraged.
5646 When the large model is used all variables declared without a storage class
5647 will be allocated into the external ram, this includes all parameters and
5648 local variables (for non-reentrant functions).
5649 When the small model is used variables without storage class are allocated
5650 in the internal ram.
5653 Judicious usage of the processor specific storage classes and the 'reentrant'
5654 function type will yield much more efficient code, than using the large-model.
5655 Several optimizations are disabled when the program is compiled using the
5656 large model, it is therefore strongly recommdended that the small model
5657 be used unless absolutely required.
5660 Flat 24 bit addressing model.
5661 \begin_inset LatexCommand \label{--model-flat24}
5668 This option generates code for the 24 bit contiguous addressing mode of
5669 the Dallas DS80C390 part.
5670 In this mode, up to four meg of external RAM or code space can be directly
5672 See the data sheets at www.dalsemi.com for further information on this part.
5675 Note that the compiler does not generate any code to place the processor
5676 into this mode (it defaults to 8051 compatible mode).
5677 Boot loader or similar code must ensure that the processor is in 24 bit
5678 contiguous addressing mode before calling the SDCC startup code.
5681 Like the --model-large option, variables will by default be placed into
5683 However, a current limitation is that the compiler will spill variables
5684 into the DATA segment when it runs out of registers.
5685 This means that compiling complex code can rapidly fill up the DATA segment.
5686 This limitation is being worked on, and should be addressed in the next
5690 Segments may be placed anywhere in the 4 meg address space using the usual
5692 Note that if any segments are located above 64K, the -r flag must be passed
5693 to the linker to generate the proper segment relocations, and the Intel
5694 HEX output format must be used.
5695 The -r flag can be passed to the linker by using the option -Wl-r on the
5702 This option generates code for the 10 bit stack mode of the Dallas DS80C390
5704 In this mode, the stack is located in the lower 1K of the internal RAM,
5705 which is mapped to 0x400000.
5708 With this option, sdcc will generate the proper addressing for stack variables.
5711 Note that the support is incomplete, since it still uses a single byte as
5713 This means that only the lower 256 bytes of the potential 1K stack space
5714 can actually be used.
5715 However, this does allow you to reclaim the precious 256 bytes of low RAM
5716 for use for the DATA and IDATA segments.
5719 The compiler will not generate any code to put the processor into 10 bit
5721 It is important to ensure that the processor is in this mode before calling
5722 any re-entrant functions compiled with this option.
5725 In principle, this should work with the --stack-auto option, but that has
5727 It is incompatible with the --xstack option.
5728 It also only makes sense if the processor is in 24 bit contiguous addressing
5729 mode (see the --model-flat24 option).
5732 Defines created by the compiler.
5733 \begin_inset LatexCommand \label{Defines.}
5740 The compiler creates the following #defines .
5743 SDCC - this Symbol is always defined.
5746 SDCC_STACK_AUTO - this symbol is defined when --stack-auto option is used.
5749 SDCC_MODEL_SMALL - when small model is used.
5752 SDCC_MODEL_LARGE - when --model-large is used.
5755 SDCC_USE_XSTACK - when --xstack option is used.
5759 \begin_inset LatexCommand \label{Pragmaa}
5766 SDCC supports the following
5771 This directives are applicable only at a function level.
5779 \begin_inset LatexCommand \label{pragma save}
5783 - this will save all the current options .
5791 \begin_inset LatexCommand \label{pragma restore}
5795 - will restore the saved options from the last save.
5796 Note that SAVES & RESTOREs cannot be nested.
5797 SDCC uses the same buffer to save the options each time a SAVE is called.
5805 \begin_inset LatexCommand \label{pragma nogcse}
5809 - will stop global subexpression elimination.
5817 \begin_inset LatexCommand \label{pragma noinduction}
5821 - will stop loop induction optimizations .
5829 \begin_inset LatexCommand \label{pragma nojtbound}
5833 - will not generate code for boundary value checking , when switch statements
5834 are turned into jump-tables.
5842 \begin_inset LatexCommand \label{pragma nooverlay}
5846 - the compiler will not overlay the parameters and local variables of a
5855 \begin_inset LatexCommand \label{pragma noloopreverse}
5859 - Will not do loop reversal optimization
5864 EXCLUDE NONE | {acc[,b[,dpl[,dph]]]
5867 \begin_inset LatexCommand \label{pragma exclude}
5871 - The exclude pragma disables generation of pair of push/pop instruction
5872 in ISR function (using interrupt keyword).
5873 The directive should be placed immediately before the ISR function definition
5874 and it affects ALL ISR functions following it.
5875 To enable the normal register saving for ISR functions use
5876 \begin_inset Quotes eld
5879 #pragma EXCLUDE none
5880 \begin_inset Quotes erd
5888 CALLEE-SAVES function1[,function2[,function3...]]
5891 \begin_inset LatexCommand \label{pragma callee-saves}
5895 - The compiler by default uses a caller saves convention for register saving
5896 across function calls, however this can cause unneccessary register pushing
5897 & popping when calling small functions from larger functions.
5898 This option can be used to switch the register saving convention for the
5899 function names specified.
5900 The compiler will not save registers when calling these functions, extra
5901 code will be generated at the entry & exit for these functions to save
5902 & restore the registers used by these functions, this can SUBSTANTIALLY
5903 reduce code & improve run time performance of the generated code.
5904 In future the compiler (with interprocedural analysis) will be able to
5905 determine the appropriate scheme to use for each function call.
5907 \begin_inset LatexCommand \ref{--callee-saves}
5911 command line option is used, the function names specified in #pragma CALLEE-SAV
5912 ES is appended to the list of functions specified inthe command line.
5915 The pragma's are intended to be used to turn-off certain optimizations which
5916 might cause the compiler to generate extra stack / data space to store
5917 compiler generated temporary variables.
5918 This usually happens in large functions.
5919 Pragma directives should be used as shown in the following example, they
5920 are used to control options & optimizations for a given function; pragmas
5929 a function, placing pragma's inside a function body could have unpredictable
5941 \protected_separator
5942 /* save the current settings */
5944 #pragma NOGCSE /* turnoff global subexpression elimination */
5946 #pragma NOINDUCTION /* turn off induction optimizations */
5953 \protected_separator
5955 \protected_separator
5960 \protected_separator
5962 \protected_separator
5966 \protected_separator
5968 \protected_separator
5974 #pragma RESTORE /* turn the optimizations back on */
5977 The compiler will generate a warning message when extra space is allocated.
5978 It is strongly recommended that the SAVE and RESTORE pragma's be used when
5979 changing options for a function.
5983 \begin_inset LatexCommand \label{Library}
5990 The following library routines are provided for your convenience.
5999 - Contains the following functions printf & sprintf these routines are developed
6002 Martijn van Balen <balen@natlab.research.philips.com>.
6008 %[flags][width][b|B|l|L]type
6014 \protected_separator
6016 \protected_separator
6018 \protected_separator
6020 \protected_separator
6022 \protected_separator
6024 \protected_separator
6026 \protected_separator
6028 \protected_separator
6030 \protected_separator
6032 \protected_separator
6034 \protected_separator
6036 \protected_separator
6038 \protected_separator
6040 \protected_separator
6042 \protected_separator
6044 \protected_separator
6046 \protected_separator
6047 left justify output in specified field width
6050 \protected_separator
6052 \protected_separator
6054 \protected_separator
6056 \protected_separator
6058 \protected_separator
6060 \protected_separator
6062 \protected_separator
6064 \protected_separator
6066 \protected_separator
6068 \protected_separator
6070 \protected_separator
6072 \protected_separator
6074 \protected_separator
6076 \protected_separator
6078 \protected_separator
6080 \protected_separator
6082 \protected_separator
6084 \protected_separator
6086 \protected_separator
6088 \protected_separator
6090 \protected_separator
6092 \protected_separator
6094 \protected_separator
6095 prefix output with +/- sign if output is signed type
6098 \protected_separator
6100 \protected_separator
6102 \protected_separator
6104 \protected_separator
6106 \protected_separator
6108 \protected_separator
6110 \protected_separator
6112 \protected_separator
6114 \protected_separator
6116 \protected_separator
6118 \protected_separator
6120 \protected_separator
6122 \protected_separator
6124 \protected_separator
6126 \protected_separator
6128 \protected_separator
6130 \protected_separator
6132 \protected_separator
6134 \protected_separator
6135 prefix output with a blank if it's a signed positive value
6138 \protected_separator
6140 \protected_separator
6142 \protected_separator
6144 \protected_separator
6146 \protected_separator
6148 \protected_separator
6150 \protected_separator
6152 \protected_separator
6154 \protected_separator
6156 \protected_separator
6158 \protected_separator
6160 \protected_separator
6162 \protected_separator
6164 \protected_separator
6166 \protected_separator
6168 \protected_separator
6170 \protected_separator
6172 \protected_separator
6173 specifies minimum number of characters outputted for numbers
6176 \protected_separator
6178 \protected_separator
6180 \protected_separator
6182 \protected_separator
6184 \protected_separator
6186 \protected_separator
6188 \protected_separator
6190 \protected_separator
6192 \protected_separator
6194 \protected_separator
6196 \protected_separator
6198 \protected_separator
6200 \protected_separator
6202 \protected_separator
6204 \protected_separator
6206 \protected_separator
6208 \protected_separator
6210 \protected_separator
6212 \protected_separator
6214 \protected_separator
6216 \protected_separator
6218 \protected_separator
6220 \protected_separator
6222 \protected_separator
6224 \protected_separator
6229 \protected_separator
6231 \protected_separator
6233 \protected_separator
6235 \protected_separator
6237 \protected_separator
6239 \protected_separator
6241 \protected_separator
6243 \protected_separator
6245 \protected_separator
6247 \protected_separator
6249 \protected_separator
6251 \protected_separator
6253 \protected_separator
6255 \protected_separator
6257 \protected_separator
6259 \protected_separator
6261 \protected_separator
6263 \protected_separator
6265 \protected_separator
6267 \protected_separator
6269 \protected_separator
6271 \protected_separator
6273 \protected_separator
6275 \protected_separator
6277 \protected_separator
6278 - For numbers, spaces are added on the left when needed.
6282 \protected_separator
6284 \protected_separator
6286 \protected_separator
6288 \protected_separator
6290 \protected_separator
6292 \protected_separator
6294 \protected_separator
6296 \protected_separator
6298 \protected_separator
6300 \protected_separator
6302 \protected_separator
6304 \protected_separator
6306 \protected_separator
6308 \protected_separator
6310 \protected_separator
6312 \protected_separator
6314 \protected_separator
6316 \protected_separator
6318 \protected_separator
6320 \protected_separator
6322 \protected_separator
6324 \protected_separator
6326 \protected_separator
6328 \protected_separator
6330 \protected_separator
6332 \protected_separator
6334 \protected_separator
6335 If width starts with a zero character, zeroes and used
6338 \protected_separator
6340 \protected_separator
6342 \protected_separator
6344 \protected_separator
6346 \protected_separator
6348 \protected_separator
6350 \protected_separator
6352 \protected_separator
6354 \protected_separator
6356 \protected_separator
6358 \protected_separator
6360 \protected_separator
6362 \protected_separator
6364 \protected_separator
6366 \protected_separator
6368 \protected_separator
6370 \protected_separator
6372 \protected_separator
6374 \protected_separator
6376 \protected_separator
6378 \protected_separator
6380 \protected_separator
6382 \protected_separator
6384 \protected_separator
6386 \protected_separator
6388 \protected_separator
6390 \protected_separator
6395 \protected_separator
6397 \protected_separator
6399 \protected_separator
6401 \protected_separator
6403 \protected_separator
6405 \protected_separator
6407 \protected_separator
6409 \protected_separator
6411 \protected_separator
6413 \protected_separator
6415 \protected_separator
6417 \protected_separator
6419 \protected_separator
6421 \protected_separator
6423 \protected_separator
6425 \protected_separator
6427 \protected_separator
6429 \protected_separator
6431 \protected_separator
6433 \protected_separator
6435 \protected_separator
6437 \protected_separator
6439 \protected_separator
6441 \protected_separator
6443 \protected_separator
6444 - For strings, spaces are are added on the left or right (when
6447 \protected_separator
6449 \protected_separator
6451 \protected_separator
6453 \protected_separator
6455 \protected_separator
6457 \protected_separator
6459 \protected_separator
6461 \protected_separator
6463 \protected_separator
6465 \protected_separator
6467 \protected_separator
6469 \protected_separator
6471 \protected_separator
6473 \protected_separator
6475 \protected_separator
6477 \protected_separator
6479 \protected_separator
6481 \protected_separator
6483 \protected_separator
6485 \protected_separator
6487 \protected_separator
6489 \protected_separator
6491 \protected_separator
6493 \protected_separator
6495 \protected_separator
6497 \protected_separator
6499 \protected_separator
6500 flag '-' is used) when needed.
6504 \protected_separator
6506 \protected_separator
6508 \protected_separator
6510 \protected_separator
6512 \protected_separator
6514 \protected_separator
6516 \protected_separator
6518 \protected_separator
6520 \protected_separator
6522 \protected_separator
6524 \protected_separator
6526 \protected_separator
6528 \protected_separator
6530 \protected_separator
6532 \protected_separator
6534 \protected_separator
6536 \protected_separator
6538 \protected_separator
6540 \protected_separator
6542 \protected_separator
6544 \protected_separator
6546 \protected_separator
6548 \protected_separator
6550 \protected_separator
6552 \protected_separator
6556 \protected_separator
6558 \protected_separator
6560 \protected_separator
6562 \protected_separator
6564 \protected_separator
6566 \protected_separator
6568 \protected_separator
6570 \protected_separator
6572 \protected_separator
6574 \protected_separator
6576 \protected_separator
6578 \protected_separator
6580 \protected_separator
6582 \protected_separator
6584 \protected_separator
6586 \protected_separator
6588 \protected_separator
6590 \protected_separator
6592 \protected_separator
6594 \protected_separator
6595 byte argument (used by d, u, o, x, X)
6598 \protected_separator
6600 \protected_separator
6602 \protected_separator
6604 \protected_separator
6606 \protected_separator
6608 \protected_separator
6610 \protected_separator
6612 \protected_separator
6614 \protected_separator
6616 \protected_separator
6618 \protected_separator
6620 \protected_separator
6622 \protected_separator
6624 \protected_separator
6626 \protected_separator
6628 \protected_separator
6630 \protected_separator
6632 \protected_separator
6634 \protected_separator
6636 \protected_separator
6637 long argument (used by d, u, o, x, X)
6640 \protected_separator
6642 \protected_separator
6644 \protected_separator
6646 \protected_separator
6648 \protected_separator
6650 \protected_separator
6652 \protected_separator
6654 \protected_separator
6656 \protected_separator
6658 \protected_separator
6660 \protected_separator
6662 \protected_separator
6664 \protected_separator
6666 \protected_separator
6668 \protected_separator
6670 \protected_separator
6672 \protected_separator
6676 \protected_separator
6678 \protected_separator
6680 \protected_separator
6682 \protected_separator
6684 \protected_separator
6686 \protected_separator
6688 \protected_separator
6690 \protected_separator
6692 \protected_separator
6694 \protected_separator
6696 \protected_separator
6698 \protected_separator
6700 \protected_separator
6702 \protected_separator
6704 \protected_separator
6706 \protected_separator
6708 \protected_separator
6710 \protected_separator
6712 \protected_separator
6714 \protected_separator
6716 \protected_separator
6718 \protected_separator
6720 \protected_separator
6721 unsigned decimal number
6724 \protected_separator
6726 \protected_separator
6728 \protected_separator
6730 \protected_separator
6732 \protected_separator
6734 \protected_separator
6736 \protected_separator
6738 \protected_separator
6740 \protected_separator
6742 \protected_separator
6744 \protected_separator
6746 \protected_separator
6748 \protected_separator
6750 \protected_separator
6752 \protected_separator
6754 \protected_separator
6756 \protected_separator
6758 \protected_separator
6760 \protected_separator
6762 \protected_separator
6764 \protected_separator
6766 \protected_separator
6768 \protected_separator
6769 unsigned octal number
6772 \protected_separator
6774 \protected_separator
6776 \protected_separator
6778 \protected_separator
6780 \protected_separator
6782 \protected_separator
6784 \protected_separator
6786 \protected_separator
6788 \protected_separator
6790 \protected_separator
6792 \protected_separator
6794 \protected_separator
6796 \protected_separator
6798 \protected_separator
6800 \protected_separator
6802 \protected_separator
6804 \protected_separator
6806 \protected_separator
6808 \protected_separator
6810 \protected_separator
6812 \protected_separator
6814 \protected_separator
6816 \protected_separator
6817 unsigned hexadecimal number (0-9, a-f)
6820 \protected_separator
6822 \protected_separator
6824 \protected_separator
6826 \protected_separator
6828 \protected_separator
6830 \protected_separator
6832 \protected_separator
6834 \protected_separator
6836 \protected_separator
6838 \protected_separator
6840 \protected_separator
6842 \protected_separator
6844 \protected_separator
6846 \protected_separator
6848 \protected_separator
6850 \protected_separator
6852 \protected_separator
6854 \protected_separator
6856 \protected_separator
6858 \protected_separator
6860 \protected_separator
6862 \protected_separator
6864 \protected_separator
6865 unsigned hexadecimal number (0-9, A-F)
6868 \protected_separator
6870 \protected_separator
6872 \protected_separator
6874 \protected_separator
6876 \protected_separator
6878 \protected_separator
6880 \protected_separator
6882 \protected_separator
6884 \protected_separator
6886 \protected_separator
6888 \protected_separator
6890 \protected_separator
6892 \protected_separator
6894 \protected_separator
6896 \protected_separator
6898 \protected_separator
6900 \protected_separator
6902 \protected_separator
6904 \protected_separator
6906 \protected_separator
6908 \protected_separator
6910 \protected_separator
6912 \protected_separator
6916 \protected_separator
6918 \protected_separator
6920 \protected_separator
6922 \protected_separator
6924 \protected_separator
6926 \protected_separator
6928 \protected_separator
6930 \protected_separator
6932 \protected_separator
6934 \protected_separator
6936 \protected_separator
6938 \protected_separator
6940 \protected_separator
6942 \protected_separator
6944 \protected_separator
6946 \protected_separator
6948 \protected_separator
6950 \protected_separator
6952 \protected_separator
6954 \protected_separator
6956 \protected_separator
6958 \protected_separator
6960 \protected_separator
6961 string (generic pointer)
6964 \protected_separator
6966 \protected_separator
6968 \protected_separator
6970 \protected_separator
6972 \protected_separator
6974 \protected_separator
6976 \protected_separator
6978 \protected_separator
6980 \protected_separator
6982 \protected_separator
6984 \protected_separator
6986 \protected_separator
6988 \protected_separator
6990 \protected_separator
6992 \protected_separator
6994 \protected_separator
6996 \protected_separator
6998 \protected_separator
7000 \protected_separator
7002 \protected_separator
7004 \protected_separator
7006 \protected_separator
7008 \protected_separator
7009 generic pointer (I:data/idata, C:code, X:xdata, P:paged)
7012 \protected_separator
7014 \protected_separator
7016 \protected_separator
7018 \protected_separator
7020 \protected_separator
7022 \protected_separator
7024 \protected_separator
7026 \protected_separator
7028 \protected_separator
7030 \protected_separator
7032 \protected_separator
7034 \protected_separator
7036 \protected_separator
7038 \protected_separator
7040 \protected_separator
7042 \protected_separator
7044 \protected_separator
7046 \protected_separator
7048 \protected_separator
7050 \protected_separator
7052 \protected_separator
7054 \protected_separator
7056 \protected_separator
7057 float (still to be implemented)
7060 Also contains a very simple version of printf (
7065 This simplified version of printf supports only the following formats.
7072 \protected_separator
7074 \protected_separator
7076 \protected_separator
7078 \protected_separator
7080 \protected_separator
7082 \protected_separator
7084 \protected_separator
7086 \protected_separator
7088 \protected_separator
7090 \protected_separator
7092 \protected_separator
7104 \protected_separator
7106 \protected_separator
7108 \protected_separator
7110 \protected_separator
7112 \protected_separator
7114 \protected_separator
7116 \protected_separator
7118 \protected_separator
7120 \protected_separator
7122 \protected_separator
7124 \protected_separator
7126 \protected_separator
7128 \protected_separator
7132 \protected_separator
7134 \protected_separator
7136 \protected_separator
7138 \protected_separator
7140 \protected_separator
7142 \protected_separator
7144 \protected_separator
7146 \protected_separator
7148 \protected_separator
7150 \protected_separator
7152 \protected_separator
7154 \protected_separator
7156 \protected_separator
7158 \protected_separator
7160 \protected_separator
7164 \protected_separator
7166 \protected_separator
7168 \protected_separator
7170 \protected_separator
7172 \protected_separator
7174 \protected_separator
7176 \protected_separator
7178 \protected_separator
7180 \protected_separator
7182 \protected_separator
7184 \protected_separator
7186 \protected_separator
7188 \protected_separator
7190 \protected_separator
7192 \protected_separator
7196 \protected_separator
7198 \protected_separator
7200 \protected_separator
7202 \protected_separator
7204 \protected_separator
7206 \protected_separator
7208 \protected_separator
7210 \protected_separator
7212 \protected_separator
7214 \protected_separator
7216 \protected_separator
7218 \protected_separator
7222 \protected_separator
7224 \protected_separator
7226 \protected_separator
7228 \protected_separator
7230 \protected_separator
7232 \protected_separator
7234 \protected_separator
7236 \protected_separator
7238 \protected_separator
7240 \protected_separator
7242 \protected_separator
7246 \protected_separator
7248 \protected_separator
7250 \protected_separator
7252 \protected_separator
7254 \protected_separator
7256 \protected_separator
7258 \protected_separator
7260 \protected_separator
7262 \protected_separator
7264 \protected_separator
7266 \protected_separator
7270 \protected_separator
7272 \protected_separator
7274 \protected_separator
7276 \protected_separator
7278 \protected_separator
7280 \protected_separator
7282 \protected_separator
7284 \protected_separator
7286 \protected_separator
7288 \protected_separator
7290 \protected_separator
7292 \protected_separator
7294 \protected_separator
7296 \protected_separator
7298 \protected_separator
7300 \protected_separator
7302 \protected_separator
7304 \protected_separator
7308 \protected_separator
7310 \protected_separator
7312 \protected_separator
7314 \protected_separator
7316 \protected_separator
7318 \protected_separator
7320 \protected_separator
7322 \protected_separator
7324 \protected_separator
7326 \protected_separator
7328 \protected_separator
7330 \protected_separator
7332 \protected_separator
7334 \protected_separator
7336 \protected_separator
7338 \protected_separator
7340 \protected_separator
7344 \protected_separator
7346 \protected_separator
7348 \protected_separator
7350 \protected_separator
7352 \protected_separator
7354 \protected_separator
7356 \protected_separator
7358 \protected_separator
7360 \protected_separator
7362 \protected_separator
7364 \protected_separator
7366 \protected_separator
7368 \protected_separator
7370 \protected_separator
7372 \protected_separator
7374 \protected_separator
7376 \protected_separator
7380 \protected_separator
7382 \protected_separator
7384 \protected_separator
7386 \protected_separator
7388 \protected_separator
7390 \protected_separator
7392 \protected_separator
7394 \protected_separator
7396 \protected_separator
7398 \protected_separator
7400 \protected_separator
7402 \protected_separator
7404 \protected_separator
7406 \protected_separator
7410 \protected_separator
7412 \protected_separator
7414 \protected_separator
7416 \protected_separator
7418 \protected_separator
7420 \protected_separator
7422 \protected_separator
7424 \protected_separator
7426 \protected_separator
7428 \protected_separator
7430 \protected_separator
7432 \protected_separator
7434 \protected_separator
7443 , --stack-after-data parameter should be used when using this routine, the
7444 routine also takes about 1K of code space .It also expects an external function
7449 to be present (this can be changed).
7450 When using the %s format the string / pointer should be cast to a generic
7458 \begin_inset Quotes eld
7461 my str %s, my int %d
7464 \begin_inset Quotes erd
7467 ,(char _generic *)mystr,myint);
7477 - contains definition for the following macros to be used for variable parameter
7478 list, note that a function can have a variable parameter list if and only
7479 if it is 'reentrant'
7485 va_list, va_start, va_arg, va_end.
7495 - contains defintion for ANSI
7504 Note in this case setjmp & longjmp can be used between functions executing
7505 within the same register bank, if long jmp is executed from a function
7506 that is using a different register bank from the function issuing the setjmp
7507 function, the results may be unpredictable.
7508 The jump buffer requires 3 bytes of data (the stack pointer & a 16 byte
7509 return address), and can be placed in any address space.
7518 - contains the following functions.
7534 - contains the following functions.
7540 strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr, strspn,
7541 strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp, memset.
7551 - contains the following routines.
7557 iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
7558 isxdigit, isalnum, isalpha.
7568 - The malloc routines are developed by Dmitry S.
7569 Obukhov (dso@usa.net).
7570 These routines will allocate memory from the external ram.
7571 Here is a description on how to use them (as described by the author).
7580 \protected_separator
7582 \protected_separator
7584 \protected_separator
7586 \protected_separator
7588 \protected_separator
7590 \protected_separator
7592 \protected_separator
7594 \protected_separator
7595 #define DYNAMIC_MEMORY_SIZE 0x2000
7598 \protected_separator
7600 \protected_separator
7602 \protected_separator
7604 \protected_separator
7606 \protected_separator
7608 \protected_separator
7610 \protected_separator
7612 \protected_separator
7617 \protected_separator
7619 \protected_separator
7621 \protected_separator
7623 \protected_separator
7625 \protected_separator
7627 \protected_separator
7629 \protected_separator
7631 \protected_separator
7632 unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];
7635 \protected_separator
7637 \protected_separator
7639 \protected_separator
7641 \protected_separator
7643 \protected_separator
7645 \protected_separator
7647 \protected_separator
7649 \protected_separator
7650 unsigned char xdata * current_buffer;
7653 \protected_separator
7655 \protected_separator
7657 \protected_separator
7659 \protected_separator
7661 \protected_separator
7663 \protected_separator
7665 \protected_separator
7667 \protected_separator
7672 \protected_separator
7674 \protected_separator
7676 \protected_separator
7678 \protected_separator
7680 \protected_separator
7682 \protected_separator
7684 \protected_separator
7686 \protected_separator
7690 \protected_separator
7692 \protected_separator
7694 \protected_separator
7696 \protected_separator
7698 \protected_separator
7700 \protected_separator
7702 \protected_separator
7704 \protected_separator
7708 \protected_separator
7710 \protected_separator
7712 \protected_separator
7714 \protected_separator
7716 \protected_separator
7718 \protected_separator
7720 \protected_separator
7722 \protected_separator
7724 \protected_separator
7726 \protected_separator
7728 \protected_separator
7730 \protected_separator
7735 \protected_separator
7737 \protected_separator
7739 \protected_separator
7741 \protected_separator
7743 \protected_separator
7745 \protected_separator
7747 \protected_separator
7749 \protected_separator
7751 \protected_separator
7753 \protected_separator
7755 \protected_separator
7757 \protected_separator
7759 \protected_separator
7760 init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE);
7763 \protected_separator
7765 \protected_separator
7767 \protected_separator
7769 \protected_separator
7771 \protected_separator
7773 \protected_separator
7775 \protected_separator
7777 \protected_separator
7779 \protected_separator
7781 \protected_separator
7783 \protected_separator
7785 \protected_separator
7786 //Now it's possible to use malloc.
7790 \protected_separator
7792 \protected_separator
7794 \protected_separator
7796 \protected_separator
7798 \protected_separator
7800 \protected_separator
7802 \protected_separator
7804 \protected_separator
7806 \protected_separator
7808 \protected_separator
7810 \protected_separator
7812 \protected_separator
7817 \protected_separator
7819 \protected_separator
7821 \protected_separator
7823 \protected_separator
7825 \protected_separator
7827 \protected_separator
7829 \protected_separator
7831 \protected_separator
7833 \protected_separator
7835 \protected_separator
7837 \protected_separator
7839 \protected_separator
7840 current_buffer = malloc(0x100);
7843 \protected_separator
7845 \protected_separator
7847 \protected_separator
7849 \protected_separator
7860 - Serial IO routines are also developed by Dmitry S.
7861 Obukhov (dso@usa.net).
7862 These routines are interrupt driven with a 256 byte circular buffer, they
7863 also expect external ram to be present.
7864 Please see documentation in file SDCCDIR/sdcc51lib/serial.c .
7865 Note the header file
7866 \begin_inset Quotes eld
7870 \begin_inset Quotes erd
7873 MUST be included in the file containing the 'main' function.
7882 - Alternate serial routine provided by Wolfgang Esslinger <wolfgang@WiredMinds.co
7883 m> these routines are more compact and faster.
7884 Please see documentation in file SDCCDIR/sdcc51lib/ser.c
7893 - Another alternate set of serial routines provided by Josef Wolf <jw@raven.inka.d
7894 e> , these routines do not use the external ram.
7903 - contains register definitions for a standard 8051
7912 - contains register definitions for 80C552.
7921 - contains min, max and other floating point related stuff.
7924 All library routines are compiled as --model-small , they are all non-reentrant,
7925 if you plan to use the large model or want to make these routines reentrant,
7926 then they will have to be recompiled with the appropriate compiler option.
7929 Have not had time to do the more involved routines like printf, will get
7933 Interfacing with assembly routines.
7934 \begin_inset LatexCommand \label{Interface_asm}
7941 Global registers used for parameter passing.
7944 By default the compiler uses the global registers
7945 \begin_inset Quotes eld
7949 \begin_inset Quotes erd
7952 to pass the first parameter to a routine, the second parameter onwards
7953 is either allocated on the stack (for reentrant routines or --stack-auto
7954 is used) or in the internal / external ram (depending on the memory model).
7956 \layout Subsubsection
7958 Assembler routine non-reentrant
7961 In the following example the function
7965 calls an assembler routine
7969 , which takes two parameters.
7974 extern int asm_func( unsigned short, unsigned short);
7980 \protected_separator
7983 int c_func (unsigned short i, unsigned short j)
7988 \protected_separator
7990 \protected_separator
7992 \protected_separator
7994 \protected_separator
7996 \protected_separator
7998 \protected_separator
8000 \protected_separator
8001 return asm_func(i,j);
8014 \protected_separator
8016 \protected_separator
8018 \protected_separator
8019 return c_func(10,9);
8024 The corresponding assembler function is:-
8030 \protected_separator
8032 \protected_separator
8034 \protected_separator
8036 \protected_separator
8038 \protected_separator
8040 \protected_separator
8042 \protected_separator
8043 .globl _asm_func_PARM_2
8046 \protected_separator
8048 \protected_separator
8050 \protected_separator
8052 \protected_separator
8054 \protected_separator
8056 \protected_separator
8058 \protected_separator
8062 \protected_separator
8064 \protected_separator
8066 \protected_separator
8068 \protected_separator
8070 \protected_separator
8072 \protected_separator
8074 \protected_separator
8078 \protected_separator
8080 \protected_separator
8082 \protected_separator
8084 \protected_separator
8086 \protected_separator
8088 \protected_separator
8090 \protected_separator
8092 \protected_separator
8094 \protected_separator
8096 \protected_separator
8098 \protected_separator
8102 \protected_separator
8104 \protected_separator
8106 \protected_separator
8108 \protected_separator
8110 \protected_separator
8112 \protected_separator
8114 \protected_separator
8120 \protected_separator
8122 \protected_separator
8124 \protected_separator
8126 \protected_separator
8128 \protected_separator
8130 \protected_separator
8132 \protected_separator
8134 \protected_separator
8136 \protected_separator
8138 \protected_separator
8140 \protected_separator
8144 \protected_separator
8146 \protected_separator
8148 \protected_separator
8150 \protected_separator
8152 \protected_separator
8154 \protected_separator
8156 \protected_separator
8158 \protected_separator
8160 \protected_separator
8162 \protected_separator
8164 \protected_separator
8168 \protected_separator
8170 \protected_separator
8172 \protected_separator
8174 \protected_separator
8176 \protected_separator
8178 \protected_separator
8180 \protected_separator
8182 \protected_separator
8184 \protected_separator
8186 \protected_separator
8188 \protected_separator
8192 \protected_separator
8194 \protected_separator
8196 \protected_separator
8198 \protected_separator
8200 \protected_separator
8202 \protected_separator
8204 \protected_separator
8206 \protected_separator
8208 \protected_separator
8210 \protected_separator
8212 \protected_separator
8216 \protected_separator
8218 \protected_separator
8220 \protected_separator
8222 \protected_separator
8224 \protected_separator
8226 \protected_separator
8228 \protected_separator
8232 Note here that the return values are placed in 'dpl' - One byte return value,
8233 'dpl' LSB & 'dph' MSB for two byte values.
8234 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
8235 b' & 'acc' for four byte values.
8238 The parameter naming convention is
8240 _<function_name>_PARM_<n>,
8242 where n is the parameter number starting from 1, and counting from the
8244 The first parameter is passed in
8245 \begin_inset Quotes eld
8249 \begin_inset Quotes erd
8252 for One bye parameter,
8253 \begin_inset Quotes eld
8257 \begin_inset Quotes erd
8261 \begin_inset Quotes eld
8265 \begin_inset Quotes erd
8269 \begin_inset Quotes eld
8273 \begin_inset Quotes erd
8280 varaible name for the second parameter will be _<function_name>_PARM_2.
8283 Assemble the assembler routine with the following command.
8286 asx8051 -losg asmfunc.asm
8289 Then compile and link the assembler routine to the C source file with the
8293 sdcc cfunc.c asmfunc.rel
8294 \layout Subsubsection
8296 Assembler routine is reentrant
8299 In this case the second parameter onwards will be passed on the stack ,
8300 the parameters are pushed from right to left i.e.
8301 after the call the left most parameter will be on the top of the stack.
8307 extern int asm_func( unsigned short, unsigned short);
8313 \protected_separator
8319 int c_func (unsigned short i, unsigned short j) reentrant
8324 \protected_separator
8326 \protected_separator
8328 \protected_separator
8330 \protected_separator
8332 \protected_separator
8334 \protected_separator
8336 \protected_separator
8337 return asm_func(i,j);
8350 \protected_separator
8352 \protected_separator
8354 \protected_separator
8355 return c_func(10,9);
8360 The corresponding assembler routine is.
8366 \protected_separator
8368 \protected_separator
8370 \protected_separator
8372 \protected_separator
8374 \protected_separator
8376 \protected_separator
8378 \protected_separator
8384 \protected_separator
8386 \protected_separator
8388 \protected_separator
8390 \protected_separator
8392 \protected_separator
8394 \protected_separator
8396 \protected_separator
8398 \protected_separator
8402 \protected_separator
8404 \protected_separator
8406 \protected_separator
8408 \protected_separator
8410 \protected_separator
8412 \protected_separator
8414 \protected_separator
8416 \protected_separator
8420 \protected_separator
8422 \protected_separator
8424 \protected_separator
8426 \protected_separator
8428 \protected_separator
8430 \protected_separator
8432 \protected_separator
8434 \protected_separator
8436 \protected_separator
8440 \protected_separator
8442 \protected_separator
8444 \protected_separator
8446 \protected_separator
8448 \protected_separator
8450 \protected_separator
8452 \protected_separator
8454 \protected_separator
8458 \protected_separator
8460 \protected_separator
8462 \protected_separator
8464 \protected_separator
8466 \protected_separator
8468 \protected_separator
8470 \protected_separator
8472 \protected_separator
8476 \protected_separator
8478 \protected_separator
8480 \protected_separator
8482 \protected_separator
8484 \protected_separator
8486 \protected_separator
8488 \protected_separator
8490 \protected_separator
8494 \protected_separator
8496 \protected_separator
8498 \protected_separator
8500 \protected_separator
8502 \protected_separator
8504 \protected_separator
8506 \protected_separator
8508 \protected_separator
8512 \protected_separator
8514 \protected_separator
8516 \protected_separator
8518 \protected_separator
8520 \protected_separator
8522 \protected_separator
8524 \protected_separator
8526 \protected_separator
8530 \protected_separator
8532 \protected_separator
8534 \protected_separator
8536 \protected_separator
8538 \protected_separator
8540 \protected_separator
8542 \protected_separator
8544 \protected_separator
8548 \protected_separator
8550 \protected_separator
8552 \protected_separator
8554 \protected_separator
8556 \protected_separator
8558 \protected_separator
8560 \protected_separator
8562 \protected_separator
8566 \protected_separator
8568 \protected_separator
8570 \protected_separator
8572 \protected_separator
8574 \protected_separator
8576 \protected_separator
8578 \protected_separator
8580 \protected_separator
8584 \protected_separator
8586 \protected_separator
8588 \protected_separator
8590 \protected_separator
8592 \protected_separator
8594 \protected_separator
8596 \protected_separator
8598 \protected_separator
8602 \protected_separator
8604 \protected_separator
8606 \protected_separator
8608 \protected_separator
8610 \protected_separator
8612 \protected_separator
8614 \protected_separator
8616 \protected_separator
8620 \protected_separator
8622 \protected_separator
8624 \protected_separator
8626 \protected_separator
8628 \protected_separator
8630 \protected_separator
8632 \protected_separator
8634 \protected_separator
8638 \protected_separator
8640 \protected_separator
8642 \protected_separator
8644 \protected_separator
8646 \protected_separator
8648 \protected_separator
8650 \protected_separator
8652 \protected_separator
8656 \protected_separator
8658 \protected_separator
8660 \protected_separator
8662 \protected_separator
8664 \protected_separator
8666 \protected_separator
8668 \protected_separator
8672 The compiling and linking procedure remains the same, however note the extra
8673 entry & exit linkage required for the assembler code, _bp is the stack
8674 frame pointer and is used to compute the offset into the stack for parameters
8675 and local variables.
8678 With --noregparms option.
8681 When the source is compiled with --noregparms option , space is allocated
8682 for each of the parameters passed to a routine.
8683 \layout Subsubsection
8685 Assembler routine non-reentrant.
8688 In the following example the function
8692 calls an assembler routine
8696 , which takes two parameters.
8701 extern int asm_func( unsigned short, unsigned short);
8707 \protected_separator
8710 int c_func (unsigned short i, unsigned short j)
8715 \protected_separator
8717 \protected_separator
8719 \protected_separator
8721 \protected_separator
8723 \protected_separator
8725 \protected_separator
8727 \protected_separator
8728 return asm_func(i,j);
8741 \protected_separator
8743 \protected_separator
8745 \protected_separator
8746 return c_func(10,9);
8751 The corresponding assembler function is:-
8757 \protected_separator
8759 \protected_separator
8761 \protected_separator
8763 \protected_separator
8765 \protected_separator
8767 \protected_separator
8769 \protected_separator
8770 .globl _asm_func_PARM_1
8773 \protected_separator
8775 \protected_separator
8777 \protected_separator
8779 \protected_separator
8781 \protected_separator
8783 \protected_separator
8785 \protected_separator
8786 .globl _asm_func_PARM_2
8789 \protected_separator
8791 \protected_separator
8793 \protected_separator
8795 \protected_separator
8797 \protected_separator
8799 \protected_separator
8801 \protected_separator
8805 \protected_separator
8807 \protected_separator
8809 \protected_separator
8811 \protected_separator
8813 \protected_separator
8815 \protected_separator
8817 \protected_separator
8821 \protected_separator
8823 \protected_separator
8825 \protected_separator
8827 \protected_separator
8829 \protected_separator
8831 \protected_separator
8833 \protected_separator
8835 \protected_separator
8837 \protected_separator
8839 \protected_separator
8843 \protected_separator
8845 \protected_separator
8847 \protected_separator
8849 \protected_separator
8851 \protected_separator
8853 \protected_separator
8855 \protected_separator
8857 \protected_separator
8859 \protected_separator
8861 \protected_separator
8863 \protected_separator
8867 \protected_separator
8869 \protected_separator
8871 \protected_separator
8873 \protected_separator
8875 \protected_separator
8877 \protected_separator
8879 \protected_separator
8885 \protected_separator
8887 \protected_separator
8889 \protected_separator
8891 \protected_separator
8893 \protected_separator
8895 \protected_separator
8897 \protected_separator
8899 \protected_separator
8901 \protected_separator
8903 \protected_separator
8905 \protected_separator
8909 \protected_separator
8911 \protected_separator
8913 \protected_separator
8915 \protected_separator
8917 \protected_separator
8919 \protected_separator
8921 \protected_separator
8923 \protected_separator
8925 \protected_separator
8927 \protected_separator
8929 \protected_separator
8933 \protected_separator
8935 \protected_separator
8937 \protected_separator
8939 \protected_separator
8941 \protected_separator
8943 \protected_separator
8945 \protected_separator
8947 \protected_separator
8949 \protected_separator
8951 \protected_separator
8953 \protected_separator
8957 \protected_separator
8959 \protected_separator
8961 \protected_separator
8963 \protected_separator
8965 \protected_separator
8967 \protected_separator
8969 \protected_separator
8971 \protected_separator
8973 \protected_separator
8975 \protected_separator
8977 \protected_separator
8981 \protected_separator
8983 \protected_separator
8985 \protected_separator
8987 \protected_separator
8989 \protected_separator
8991 \protected_separator
8993 \protected_separator
8997 Note here that the return values are placed in 'dpl' - One byte return value,
8998 'dpl' LSB & 'dph' MSB for two byte values.
8999 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
9000 b' & 'acc' for four byte values.
9003 The parameter naming convention is
9005 _<function_name>_PARM_<n>,
9007 where n is the parameter number starting from 1, and counting from the
9014 left-most parameter name will be _<function_name>_PARM_1.
9017 Assemble the assembler routine with the following command.
9020 asx8051 -losg asmfunc.asm
9023 Then compile and link the assembler routine to the C source file with the
9027 sdcc cfunc.c asmfunc.rel
9028 \layout Subsubsection
9030 Assembler routine is reentrant.
9033 In this case the parameters will be passed on the stack , the parameters
9034 are pushed from right to left i.e.
9035 after the call the left most parameter will be on the top of the stack.
9041 extern int asm_func( unsigned short, unsigned short);
9047 \protected_separator
9053 int c_func (unsigned short i, unsigned short j) reentrant
9058 \protected_separator
9060 \protected_separator
9062 \protected_separator
9064 \protected_separator
9066 \protected_separator
9068 \protected_separator
9070 \protected_separator
9071 return asm_func(i,j);
9084 \protected_separator
9086 \protected_separator
9088 \protected_separator
9089 return c_func(10,9);
9094 The corresponding assembler routine is.
9100 \protected_separator
9102 \protected_separator
9104 \protected_separator
9106 \protected_separator
9108 \protected_separator
9110 \protected_separator
9112 \protected_separator
9118 \protected_separator
9120 \protected_separator
9122 \protected_separator
9124 \protected_separator
9126 \protected_separator
9128 \protected_separator
9130 \protected_separator
9132 \protected_separator
9136 \protected_separator
9138 \protected_separator
9140 \protected_separator
9142 \protected_separator
9144 \protected_separator
9146 \protected_separator
9148 \protected_separator
9150 \protected_separator
9154 \protected_separator
9156 \protected_separator
9158 \protected_separator
9160 \protected_separator
9162 \protected_separator
9164 \protected_separator
9166 \protected_separator
9168 \protected_separator
9172 \protected_separator
9174 \protected_separator
9176 \protected_separator
9178 \protected_separator
9180 \protected_separator
9182 \protected_separator
9184 \protected_separator
9186 \protected_separator
9190 \protected_separator
9192 \protected_separator
9194 \protected_separator
9196 \protected_separator
9198 \protected_separator
9200 \protected_separator
9202 \protected_separator
9204 \protected_separator
9208 \protected_separator
9210 \protected_separator
9212 \protected_separator
9214 \protected_separator
9216 \protected_separator
9218 \protected_separator
9220 \protected_separator
9222 \protected_separator
9226 \protected_separator
9228 \protected_separator
9230 \protected_separator
9232 \protected_separator
9234 \protected_separator
9236 \protected_separator
9238 \protected_separator
9240 \protected_separator
9244 \protected_separator
9246 \protected_separator
9248 \protected_separator
9250 \protected_separator
9252 \protected_separator
9254 \protected_separator
9256 \protected_separator
9258 \protected_separator
9262 \protected_separator
9264 \protected_separator
9266 \protected_separator
9268 \protected_separator
9270 \protected_separator
9272 \protected_separator
9274 \protected_separator
9276 \protected_separator
9280 \protected_separator
9282 \protected_separator
9284 \protected_separator
9286 \protected_separator
9288 \protected_separator
9290 \protected_separator
9292 \protected_separator
9294 \protected_separator
9298 \protected_separator
9300 \protected_separator
9302 \protected_separator
9304 \protected_separator
9306 \protected_separator
9308 \protected_separator
9310 \protected_separator
9312 \protected_separator
9316 \protected_separator
9318 \protected_separator
9320 \protected_separator
9322 \protected_separator
9324 \protected_separator
9326 \protected_separator
9328 \protected_separator
9330 \protected_separator
9334 \protected_separator
9336 \protected_separator
9338 \protected_separator
9340 \protected_separator
9342 \protected_separator
9344 \protected_separator
9346 \protected_separator
9348 \protected_separator
9352 \protected_separator
9354 \protected_separator
9356 \protected_separator
9358 \protected_separator
9360 \protected_separator
9362 \protected_separator
9364 \protected_separator
9366 \protected_separator
9370 \protected_separator
9372 \protected_separator
9374 \protected_separator
9376 \protected_separator
9378 \protected_separator
9380 \protected_separator
9382 \protected_separator
9384 \protected_separator
9388 \protected_separator
9390 \protected_separator
9392 \protected_separator
9394 \protected_separator
9396 \protected_separator
9398 \protected_separator
9400 \protected_separator
9402 \protected_separator
9406 \protected_separator
9408 \protected_separator
9410 \protected_separator
9412 \protected_separator
9414 \protected_separator
9416 \protected_separator
9418 \protected_separator
9422 The compiling and linking procedure remains the same, however note the extra
9423 entry & exit linkage required for the assembler code, _bp is the stack
9424 frame pointer and is used to compute the offset into the stack for parameters
9425 and local variables.
9429 \begin_inset LatexCommand \label{xstack}
9436 The external stack is located at the start of the external ram segment ,
9437 and is 256 bytes in size.
9438 When --xstack option is used to compile the program , the parameters and
9439 local variables of all reentrant functions are allocated in this area.
9440 This option is provided for programs with large stack space requirements.
9441 When used with the --stack-auto option, all parameters and local variables
9442 are allocated on the external stack (note support libraries will need to
9443 be recompiled with the same options).
9446 The compiler outputs the higher order address byte of the external ram segment
9447 into PORT P2, therefore when using the External Stack option, this port
9448 MAY NOT be used by the application program.
9452 \begin_inset LatexCommand \label{ANSI_Compliance}
9459 Deviations from the compliancy.
9462 functions are not always reentrant.
9465 structures cannot be assigned values directly, cannot be passed as function
9466 parameters or assigned to each other and cannot be a return value from
9491 s1 = s2 ; /* is invalid in SDCC although allowed in ANSI */
9501 struct s foo1 (struct s parms) /* is invalid in SDCC although allowed in
9511 return rets;/* is invalid in SDCC although allowed in ANSI */
9516 'long long' (64 bit integers) not supported.
9519 'double' precision floating point not supported.
9522 integral promotions are suppressed.
9523 What does this mean ? The compiler will not implicitly promote an integer
9524 expression to a higher order integer, exception is an assignment or parameter
9540 Old K&R style function declarations are NOT allowed.
9545 foo( i,j) /* this old style of function declarations */
9547 int i,j; /* are valid in ANSI ..
9548 not valid in SDCC */
9558 functions declared as pointers must be dereferenced during the call.
9571 \protected_separator
9573 \protected_separator
9578 \protected_separator
9580 \protected_separator
9581 /* has to be called like this */
9584 \protected_separator
9586 \protected_separator
9587 (*foo)();/* ansi standard allows calls to be made like 'foo()' */
9590 Cyclomatic Complexity
9591 \begin_inset LatexCommand \label{Cyclomatic}
9598 Cyclomatic complexity of a function is defined as the number of independent
9599 paths the program can take during execution of the function.
9600 This is an important number since it defines the number test cases you
9601 have to generate to validate the function .
9602 The accepted industry standard for complexity number is 10, if the cyclomatic
9603 complexity reported by SDCC exceeds 10 you should think about simplification
9604 of the function logic.
9607 Note that the complexity level is not related to the number of lines of
9609 Large functions can have low complexity, and small functions can have large
9611 SDCC uses the following formula to compute the complexity.
9616 complexity = (number of edges in control flow graph) -
9619 \protected_separator
9621 \protected_separator
9623 \protected_separator
9625 \protected_separator
9627 \protected_separator
9629 \protected_separator
9631 \protected_separator
9632 (number of nodes in control flow graph) + 2;
9635 Having said that the industry standard is 10, you should be aware that in
9636 some cases it may unavoidable to have a complexity level of less than 10.
9637 For example if you have switch statement with more than 10 case labels,
9638 each case label adds one to the complexity level.
9639 The complexity level is by no means an absolute measure of the algorithmic
9640 complexity of the function, it does however provide a good starting point
9641 for which functions you might look at for further optimization.
9645 \begin_inset LatexCommand \label{Tips}
9652 Here are a few guide-lines that will help the compiler generate more efficient
9653 code, some of the tips are specific to this compiler others are generally
9654 good programming practice.
9657 Use the smallest data type to represent your data-value.
9658 If it is known in advance that the value is going to be less than 256 then
9659 use a 'short' or 'char' instead of an 'int'.
9662 Use unsigned when it is known in advance that the value is not going to
9664 This helps especially if you are doing division or multiplication.
9667 NEVER jump into a LOOP.
9670 Declare the variables to be local whenever possible, especially loop control
9671 variables (induction).
9674 Since the compiler does not do implicit integral promotion, the programmer
9675 should do an explicit cast when integral promotion is required.
9678 Reducing the size of division , multiplication & modulus operations can
9679 reduce code size substantially.
9680 Take the following code for example.
9686 foobar( unsigned int p1, unsigned char ch)
9691 \protected_separator
9693 \protected_separator
9695 \protected_separator
9697 \protected_separator
9698 unsigned char ch1 = p1 % ch ;
9701 \protected_separator
9703 \protected_separator
9705 \protected_separator
9707 \protected_separator
9709 \protected_separator
9711 \protected_separator
9713 \protected_separator
9715 \protected_separator
9721 For the modulus operation the variable ch will be promoted to unsigned int
9722 first then the modulus operation will be performed (this will lead to a
9723 call to a support routine).
9724 If the code is changed to
9729 foobar( unsigned int p1, unsigned char ch)
9734 \protected_separator
9736 \protected_separator
9738 \protected_separator
9740 \protected_separator
9741 unsigned char ch1 = (unsigned char)p1 % ch ;
9744 \protected_separator
9746 \protected_separator
9748 \protected_separator
9750 \protected_separator
9752 \protected_separator
9754 \protected_separator
9756 \protected_separator
9758 \protected_separator
9764 It would substantially reduce the code generated (future versions of the
9765 compiler will be smart enough to detect such optimization oppurtunities).
9771 Notes from an USER ( Trefor@magera.freeserve.co.uk )
9774 The 8051 family of micro controller have a minimum of 128 bytes of internal
9775 memory which is structured as follows
9778 - Bytes 00-1F - 32 bytes to hold up to 4 banks of the registers R7 to R7
9782 - Bytes 20-2F - 16 bytes to hold 128 bit variables and
9785 - Bytes 30-7F - 60 bytes for general purpose use.
9788 Normally the SDCC compiler will only utilise the first bank of registers,
9789 but it is possible to specify that other banks of registers should be used
9790 in interrupt routines.
9791 By default, the compiler will place the stack after the last bank of used
9793 if the first 2 banks of registers are used, it will position the base of
9794 the internal stack at address 16 (0X10).
9795 This implies that as the stack grows, it will use up the remaining register
9796 banks, and the 16 bytes used by the 128 bit variables, and 60 bytes for
9797 general purpose use.
9800 By default, the compiler uses the 60 general purpose bytes to hold "near
9802 The compiler/optimiser may also declare some Local Variables in this area
9807 If any of the 128 bit variables are used, or near data is being used then
9808 care needs to be taken to ensure that the stack does not grow so much that
9809 it starts to over write either your bit variables or "near data".
9810 There is no runtime checking to prevent this from happening.
9813 The amount of stack being used is affected by the use of the "internal stack"
9814 to save registers before a subroutine call is made, - --stack-auto will
9815 declare parameters and local variables on the stack - the number of nested
9819 If you detect that the stack is over writing you data, then the following
9821 --xstack will cause an external stack to be used for saving registers and
9822 (if --stack-auto is being used) storing parameters and local variables.
9823 However this will produce more and code which will be slower to execute.
9827 --stack-loc will allow you specify the start of the stack, i.e.
9828 you could start it after any data in the general purpose area.
9829 However this may waste the memory not used by the register banks and if
9830 the size of the "near data" increases, it may creep into the bottom of
9834 --stack-after-data, similar to the --stack-loc, but it automatically places
9835 the stack after the end of the "near data".
9836 Again this could waste any spare register space.
9839 --data-loc allows you to specify the start address of the near data.
9840 This could be used to move the "near data" further away from the stack
9841 giving it more room to grow.
9842 This will only work if no bit variables are being used and the stack can
9843 grow to use the bit variable space.
9849 If you find that the stack is over writing your bit variables or "near data"
9850 then the approach which best utilised the internal memory is to position
9851 the "near data" after the last bank of used registers or, if you use bit
9852 variables, after the last bit variable by using the --data-loc, e.g.
9853 if two register banks are being used and no data variables, --data-loc
9854 16, and - use the --stack-after-data option.
9857 If bit variables are being used, another method would be to try and squeeze
9858 the data area in the unused register banks if it will fit, and start the
9859 stack after the last bit variable.
9862 Retargetting for other MCUs.
9863 \begin_inset LatexCommand \label{Retargetting}
9870 The issues for retargetting the compiler are far too numerous to be covered
9872 What follows is a brief description of each of the seven phases of the
9873 compiler and its MCU dependency.
9876 Parsing the source and building the annotated parse tree.
9877 This phase is largely MCU independent (except for the language extensions).
9878 Syntax & semantic checks are also done in this phase , along with some
9879 initial optimizations like back patching labels and the pattern matching
9880 optimizations like bit-rotation etc.
9883 The second phase involves generating an intermediate code which can be easy
9884 manipulated during the later phases.
9885 This phase is entirely MCU independent.
9886 The intermediate code generation assumes the target machine has unlimited
9887 number of registers, and designates them with the name iTemp.
9888 The compiler can be made to dump a human readable form of the code generated
9889 by using the --dumpraw option.
9892 This phase does the bulk of the standard optimizations and is also MCU independe
9894 This phase can be broken down into several sub-phases.
9898 Break down intermediate code (iCode) into basic blocks.
9901 Do control flow & data flow analysis on the basic blocks.
9904 Do local common subexpression elimination, then global subexpression elimination
9907 dead code elimination
9913 if loop optimizations caused any changes then do 'global subexpression eliminati
9914 on' and 'dead code elimination' again.
9918 This phase determines the live-ranges; by live range I mean those iTemp
9919 variables defined by the compiler that still survive after all the optimization
9921 Live range analysis is essential for register allocation, since these computati
9922 on determines which of these iTemps will be assigned to registers, and for
9926 Phase five is register allocation.
9927 There are two parts to this process .
9931 The first part I call 'register packing' (for lack of a better term) .
9932 In this case several MCU specific expression folding is done to reduce
9936 The second part is more MCU independent and deals with allocating registers
9937 to the remaining live ranges.
9938 A lot of MCU specific code does creep into this phase because of the limited
9939 number of index registers available in the 8051.
9943 The Code generation phase is (unhappily), entirely MCU dependent and very
9944 little (if any at all) of this code can be reused for other MCU.
9945 However the scheme for allocating a homogenized assembler operand for each
9946 iCode operand may be reused.
9949 As mentioned in the optimization section the peep-hole optimizer is rule
9950 based system, which can reprogrammed for other MCUs.
9954 \begin_inset LatexCommand \label{Bugs}
9961 Shoot of an email to 'sandeep.dutta@usa.net', as a matter of principle I always
9962 reply to all email's sent to me.
9963 Bugs will be fixed ASAP.
9964 When reporting a bug , it is useful to include a small snippet of code
9965 that is causing the problem, if possible compile your program with the
9966 --dumpall option and send the dump files along with the bug report.
9969 SDCDB - Source level debugger.
9972 SDCC is distributed with a source level debugger.
9973 The debugger uses a command line interface, the command repertoire of the
9974 debugger has been kept as close to gdb ( the GNU debugger) as possible.
9975 The configuration and build process of the compiler see Installation
9976 \begin_inset LatexCommand \ref{Installation}
9980 also builds and installs the debugger in the target directory specified
9981 during configuration.
9982 The debugger allows you debug BOTH at the C source and at the ASM source
9986 Compiling for debugging.
9993 option must be specified for all files for which debug information is to
9995 The complier generates a
9999 file for each of these files.
10000 The linker updates the
10004 file with the address information.
10005 This .cdb is used by the debugger .
10008 How the debugger works.
10015 option is specified the compiler generates extra symbol information some
10016 of which are put into the the assembler source and some are put into the
10017 .cdb file, the linker updates the .cdb file with the address information
10019 The debugger reads the symbolic information generated by the compiler &
10020 the address information generated by the linker.
10021 It uses the SIMULATOR (Daniel's S51) to execute the program, the program
10022 execution is controlled by the debugger.
10023 When a command is issued for the debugger, it translates it into appropriate
10024 commands for the simulator .
10027 Starting the debugger.
10030 The debugger can be started using the following command line.
10031 (Assume the file you are debugging has
10034 the file name foo).
10040 The debugger will look for the following files.
10043 foo.c - the source file.
10046 foo.cdb - the debugger symbol information file.
10049 foo.ihx - the intel hex format object file.
10052 Command line options.
10055 --directory=<source file directory> this option can used to specify the
10056 directory search list.
10057 The debugger will look into the directory list specified for source , cdb
10059 The items in the directory list must be separated by ':' , e.g.
10060 if the source files can be in the directories /home/src1 and /home/src2,
10061 the --directory option should be --directory=/home/src1:/home/src2 .
10062 Note there can be no spaces in the option.
10066 -cd <directory> - change to the <directory>.
10069 -fullname - used by GUI front ends.
10072 -cpu <cpu-type> - this argument is passed to the simulator please see the
10073 simulator docs for details.
10076 -X <Clock frequency > this options is passed to the simulator please see
10077 simulator docs for details.
10080 -s <serial port file> passed to simulator see simulator docs for details.
10083 -S <serial in,out> passed to simulator see simulator docs for details.
10089 As mention earlier the command interface for the debugger has been deliberately
10090 kept as close the GNU debugger gdb , as possible, this will help int integratio
10091 n with existing graphical user interfaces (like ddd, xxgdb or xemacs) existing
10092 for the GNU debugger.
10093 \layout Subsubsection
10095 break [line | file:line | function | file:function]
10098 Set breakpoint at specified line or function.
10103 sdcdb>break foo.c:100
10105 sdcdb>break funcfoo
10107 sdcdb>break foo.c:funcfoo
10108 \layout Subsubsection
10110 clear [line | file:line | function | file:function ]
10113 Clear breakpoint at specified line or function.
10118 sdcdb>clear foo.c:100
10120 sdcdb>clear funcfoo
10122 sdcdb>clear foo.c:funcfoo
10123 \layout Subsubsection
10128 Continue program being debugged, after breakpoint.
10129 \layout Subsubsection
10134 Execute till the end of the current function.
10135 \layout Subsubsection
10140 Delete breakpoint number 'n'.
10141 If used without any option clear ALL user defined break points.
10142 \layout Subsubsection
10144 info [break | stack | frame | registers ]
10147 info break - list all breakpoints
10150 info stack - show the function call stack.
10153 info frame - show information about the current execution frame.
10156 info registers - show content of all registers.
10157 \layout Subsubsection
10162 Step program until it reaches a different source line.
10163 \layout Subsubsection
10168 Step program, proceeding through subroutine calls.
10169 \layout Subsubsection
10174 Start debugged program.
10175 \layout Subsubsection
10180 Print type information of the variable.
10181 \layout Subsubsection
10186 print value of variable.
10187 \layout Subsubsection
10192 load the given file name.
10193 Note this is an alternate method of loading file for debugging.
10194 \layout Subsubsection
10199 print information about current frame.
10200 \layout Subsubsection
10205 Toggle between C source & assembly source.
10206 \layout Subsubsection
10208 ! simulator command
10211 Send the string following '!' to the simulator, the simulator response is
10213 Note the debugger does not interpret the command being sent to the simulator,
10214 so if a command like 'go' is sent the debugger can loose its execution
10215 context and may display incorrect values.
10216 \layout Subsubsection
10223 My name is Bobby Brown"
10226 Interfacing with XEmacs.
10229 Two files are (in emacs lisp) are provided for the interfacing with XEmacs,
10238 These two files can be found in the $(prefix)/bin directory after the installat
10240 These files need to be loaded into XEmacs for the interface to work, this
10241 can be done at XEmacs startup time by inserting the following into your
10246 file (which can be found in your HOME directory)
10248 (load-file sdcdbsrc.el)
10250 [ .xemacs is a lisp file so the () around the command is REQUIRED), the files
10251 can also be loaded dynamically while XEmacs is running, set the environment
10256 to the installation bin directory [$(prefix)/bin], then enter the following
10259 ESC-x load-file sdcdbsrc .
10262 To start the interface enter the following command
10266 , you will prompted to enter the file name to be debugged.
10270 The command line options that are passed to the simulator directly are bound
10271 to default values in the file
10275 the variables are listed below these values maybe changed as required.
10278 sdcdbsrc-cpu-type '51
10281 sdcdbsrc-frequency '11059200
10284 sdcdbsrc-serial nil
10287 The following is a list of key mapping for the debugger interface.
10291 \protected_separator
10296 ;; Current Listing ::
10299 \protected_separator
10301 \protected_separator
10303 \protected_separator
10305 \protected_separator
10307 \protected_separator
10309 \protected_separator
10311 \protected_separator
10313 \protected_separator
10315 \protected_separator
10317 \protected_separator
10319 \protected_separator
10321 \protected_separator
10323 \protected_separator
10325 \protected_separator
10327 \protected_separator
10329 \protected_separator
10331 \protected_separator
10333 \protected_separator
10335 \protected_separator
10337 \protected_separator
10339 \protected_separator
10341 \protected_separator
10343 \protected_separator
10345 \protected_separator
10347 \protected_separator
10349 \protected_separator
10351 \protected_separator
10353 \protected_separator
10355 \protected_separator
10357 \protected_separator
10359 \protected_separator
10361 \protected_separator
10363 \protected_separator
10365 \protected_separator
10367 \protected_separator
10369 \protected_separator
10371 \protected_separator
10375 \protected_separator
10377 \protected_separator
10379 \protected_separator
10381 \protected_separator
10383 \protected_separator
10385 \protected_separator
10387 \protected_separator
10389 \protected_separator
10391 \protected_separator
10393 \protected_separator
10395 \protected_separator
10397 \protected_separator
10399 \protected_separator
10401 \protected_separator
10403 \protected_separator
10405 \protected_separator
10407 \protected_separator
10409 \protected_separator
10411 \protected_separator
10413 \protected_separator
10415 \protected_separator
10417 \protected_separator
10419 \protected_separator
10421 \protected_separator
10423 \protected_separator
10425 \protected_separator
10427 \protected_separator
10429 \protected_separator
10431 \protected_separator
10433 \protected_separator
10435 \protected_separator
10437 \protected_separator
10439 \protected_separator
10441 \protected_separator
10443 \protected_separator
10445 \protected_separator
10447 \protected_separator
10453 \protected_separator
10455 \protected_separator
10457 \protected_separator
10459 \protected_separator
10461 \protected_separator
10463 \protected_separator
10465 \protected_separator
10467 \protected_separator
10469 \protected_separator
10471 \protected_separator
10473 \protected_separator
10475 \protected_separator
10477 \protected_separator
10479 \protected_separator
10480 sdcdb-next-from-src
10481 \protected_separator
10483 \protected_separator
10485 \protected_separator
10487 \protected_separator
10489 \protected_separator
10491 \protected_separator
10493 \protected_separator
10495 \protected_separator
10497 \protected_separator
10499 \protected_separator
10503 \protected_separator
10505 \protected_separator
10507 \protected_separator
10509 \protected_separator
10511 \protected_separator
10513 \protected_separator
10515 \protected_separator
10517 \protected_separator
10519 \protected_separator
10521 \protected_separator
10523 \protected_separator
10525 \protected_separator
10527 \protected_separator
10529 \protected_separator
10530 sdcdb-back-from-src
10531 \protected_separator
10533 \protected_separator
10535 \protected_separator
10537 \protected_separator
10539 \protected_separator
10541 \protected_separator
10543 \protected_separator
10545 \protected_separator
10547 \protected_separator
10549 \protected_separator
10553 \protected_separator
10555 \protected_separator
10557 \protected_separator
10559 \protected_separator
10561 \protected_separator
10563 \protected_separator
10565 \protected_separator
10567 \protected_separator
10569 \protected_separator
10571 \protected_separator
10573 \protected_separator
10575 \protected_separator
10577 \protected_separator
10579 \protected_separator
10580 sdcdb-cont-from-src
10581 \protected_separator
10583 \protected_separator
10585 \protected_separator
10587 \protected_separator
10589 \protected_separator
10591 \protected_separator
10593 \protected_separator
10595 \protected_separator
10597 \protected_separator
10599 \protected_separator
10600 SDCDB continue command
10603 \protected_separator
10605 \protected_separator
10607 \protected_separator
10609 \protected_separator
10611 \protected_separator
10613 \protected_separator
10615 \protected_separator
10617 \protected_separator
10619 \protected_separator
10621 \protected_separator
10623 \protected_separator
10625 \protected_separator
10627 \protected_separator
10629 \protected_separator
10630 sdcdb-step-from-src
10631 \protected_separator
10633 \protected_separator
10635 \protected_separator
10637 \protected_separator
10639 \protected_separator
10641 \protected_separator
10643 \protected_separator
10645 \protected_separator
10647 \protected_separator
10649 \protected_separator
10653 \protected_separator
10655 \protected_separator
10657 \protected_separator
10659 \protected_separator
10661 \protected_separator
10663 \protected_separator
10665 \protected_separator
10667 \protected_separator
10669 \protected_separator
10671 \protected_separator
10673 \protected_separator
10675 \protected_separator
10677 \protected_separator
10679 \protected_separator
10680 sdcdb-whatis-c-sexp
10681 \protected_separator
10683 \protected_separator
10685 \protected_separator
10687 \protected_separator
10689 \protected_separator
10691 \protected_separator
10693 \protected_separator
10695 \protected_separator
10697 \protected_separator
10699 \protected_separator
10700 SDCDB ptypecommand for data at
10703 \protected_separator
10705 \protected_separator
10707 \protected_separator
10709 \protected_separator
10711 \protected_separator
10713 \protected_separator
10715 \protected_separator
10717 \protected_separator
10719 \protected_separator
10721 \protected_separator
10723 \protected_separator
10725 \protected_separator
10727 \protected_separator
10729 \protected_separator
10731 \protected_separator
10733 \protected_separator
10735 \protected_separator
10737 \protected_separator
10739 \protected_separator
10741 \protected_separator
10743 \protected_separator
10745 \protected_separator
10747 \protected_separator
10749 \protected_separator
10751 \protected_separator
10753 \protected_separator
10755 \protected_separator
10757 \protected_separator
10759 \protected_separator
10761 \protected_separator
10763 \protected_separator
10765 \protected_separator
10767 \protected_separator
10769 \protected_separator
10771 \protected_separator
10773 \protected_separator
10775 \protected_separator
10777 \protected_separator
10779 \protected_separator
10781 \protected_separator
10783 \protected_separator
10785 \protected_separator
10789 \protected_separator
10791 \protected_separator
10793 \protected_separator
10795 \protected_separator
10797 \protected_separator
10799 \protected_separator
10801 \protected_separator
10803 \protected_separator
10805 \protected_separator
10807 \protected_separator
10809 \protected_separator
10811 \protected_separator
10813 \protected_separator
10815 \protected_separator
10817 \protected_separator
10819 \protected_separator
10821 \protected_separator
10823 \protected_separator
10825 \protected_separator
10827 \protected_separator
10829 \protected_separator
10831 \protected_separator
10833 \protected_separator
10835 \protected_separator
10837 \protected_separator
10839 \protected_separator
10841 \protected_separator
10843 \protected_separator
10844 SDCDB Delete all breakpoints if no arg
10847 \protected_separator
10849 \protected_separator
10851 \protected_separator
10853 \protected_separator
10855 \protected_separator
10857 \protected_separator
10859 \protected_separator
10861 \protected_separator
10863 \protected_separator
10865 \protected_separator
10867 \protected_separator
10869 \protected_separator
10871 \protected_separator
10873 \protected_separator
10875 \protected_separator
10877 \protected_separator
10879 \protected_separator
10881 \protected_separator
10883 \protected_separator
10885 \protected_separator
10887 \protected_separator
10889 \protected_separator
10891 \protected_separator
10893 \protected_separator
10895 \protected_separator
10897 \protected_separator
10899 \protected_separator
10901 \protected_separator
10903 \protected_separator
10905 \protected_separator
10907 \protected_separator
10909 \protected_separator
10911 \protected_separator
10913 \protected_separator
10915 \protected_separator
10917 \protected_separator
10919 \protected_separator
10921 \protected_separator
10923 \protected_separator
10925 \protected_separator
10927 \protected_separator
10929 \protected_separator
10931 \protected_separator
10933 \protected_separator
10935 \protected_separator
10937 \protected_separator
10938 given or delete arg (C-u arg x)
10941 \protected_separator
10943 \protected_separator
10945 \protected_separator
10947 \protected_separator
10949 \protected_separator
10951 \protected_separator
10953 \protected_separator
10955 \protected_separator
10957 \protected_separator
10959 \protected_separator
10961 \protected_separator
10963 \protected_separator
10965 \protected_separator
10967 \protected_separator
10969 \protected_separator
10971 \protected_separator
10973 \protected_separator
10975 \protected_separator
10977 \protected_separator
10979 \protected_separator
10981 \protected_separator
10983 \protected_separator
10985 \protected_separator
10987 \protected_separator
10989 \protected_separator
10991 \protected_separator
10993 \protected_separator
10995 \protected_separator
10997 \protected_separator
10998 SDCDB Display current frame if no arg,
11001 \protected_separator
11003 \protected_separator
11005 \protected_separator
11007 \protected_separator
11009 \protected_separator
11011 \protected_separator
11013 \protected_separator
11015 \protected_separator
11017 \protected_separator
11019 \protected_separator
11021 \protected_separator
11023 \protected_separator
11025 \protected_separator
11027 \protected_separator
11029 \protected_separator
11031 \protected_separator
11033 \protected_separator
11035 \protected_separator
11037 \protected_separator
11039 \protected_separator
11041 \protected_separator
11043 \protected_separator
11045 \protected_separator
11047 \protected_separator
11049 \protected_separator
11051 \protected_separator
11053 \protected_separator
11055 \protected_separator
11057 \protected_separator
11059 \protected_separator
11061 \protected_separator
11063 \protected_separator
11065 \protected_separator
11067 \protected_separator
11069 \protected_separator
11071 \protected_separator
11073 \protected_separator
11075 \protected_separator
11077 \protected_separator
11079 \protected_separator
11081 \protected_separator
11083 \protected_separator
11085 \protected_separator
11087 \protected_separator
11089 \protected_separator
11091 \protected_separator
11092 given or display frame arg
11095 \protected_separator
11097 \protected_separator
11099 \protected_separator
11101 \protected_separator
11103 \protected_separator
11105 \protected_separator
11107 \protected_separator
11109 \protected_separator
11111 \protected_separator
11113 \protected_separator
11115 \protected_separator
11117 \protected_separator
11119 \protected_separator
11121 \protected_separator
11123 \protected_separator
11125 \protected_separator
11127 \protected_separator
11129 \protected_separator
11131 \protected_separator
11133 \protected_separator
11135 \protected_separator
11137 \protected_separator
11139 \protected_separator
11141 \protected_separator
11143 \protected_separator
11145 \protected_separator
11147 \protected_separator
11149 \protected_separator
11151 \protected_separator
11153 \protected_separator
11155 \protected_separator
11157 \protected_separator
11159 \protected_separator
11161 \protected_separator
11163 \protected_separator
11165 \protected_separator
11167 \protected_separator
11169 \protected_separator
11171 \protected_separator
11173 \protected_separator
11175 \protected_separator
11177 \protected_separator
11179 \protected_separator
11181 \protected_separator
11183 \protected_separator
11187 \protected_separator
11189 \protected_separator
11191 \protected_separator
11193 \protected_separator
11195 \protected_separator
11197 \protected_separator
11199 \protected_separator
11201 \protected_separator
11203 \protected_separator
11205 \protected_separator
11207 \protected_separator
11209 \protected_separator
11211 \protected_separator
11213 \protected_separator
11214 sdcdbsrc-goto-sdcdb
11215 \protected_separator
11217 \protected_separator
11219 \protected_separator
11221 \protected_separator
11223 \protected_separator
11225 \protected_separator
11227 \protected_separator
11229 \protected_separator
11231 \protected_separator
11233 \protected_separator
11234 Goto the SDCDB output buffer
11237 \protected_separator
11239 \protected_separator
11241 \protected_separator
11243 \protected_separator
11245 \protected_separator
11247 \protected_separator
11249 \protected_separator
11251 \protected_separator
11253 \protected_separator
11255 \protected_separator
11257 \protected_separator
11259 \protected_separator
11261 \protected_separator
11263 \protected_separator
11265 \protected_separator
11267 \protected_separator
11269 \protected_separator
11271 \protected_separator
11273 \protected_separator
11275 \protected_separator
11277 \protected_separator
11279 \protected_separator
11281 \protected_separator
11283 \protected_separator
11285 \protected_separator
11286 SDCDB print command for data at
11289 \protected_separator
11291 \protected_separator
11293 \protected_separator
11295 \protected_separator
11297 \protected_separator
11299 \protected_separator
11301 \protected_separator
11303 \protected_separator
11305 \protected_separator
11307 \protected_separator
11309 \protected_separator
11311 \protected_separator
11313 \protected_separator
11315 \protected_separator
11317 \protected_separator
11319 \protected_separator
11321 \protected_separator
11323 \protected_separator
11325 \protected_separator
11327 \protected_separator
11329 \protected_separator
11331 \protected_separator
11333 \protected_separator
11335 \protected_separator
11337 \protected_separator
11339 \protected_separator
11341 \protected_separator
11343 \protected_separator
11345 \protected_separator
11347 \protected_separator
11349 \protected_separator
11351 \protected_separator
11353 \protected_separator
11355 \protected_separator
11357 \protected_separator
11359 \protected_separator
11361 \protected_separator
11363 \protected_separator
11365 \protected_separator
11367 \protected_separator
11369 \protected_separator
11371 \protected_separator
11375 \protected_separator
11377 \protected_separator
11379 \protected_separator
11381 \protected_separator
11383 \protected_separator
11385 \protected_separator
11387 \protected_separator
11389 \protected_separator
11391 \protected_separator
11393 \protected_separator
11395 \protected_separator
11397 \protected_separator
11399 \protected_separator
11401 \protected_separator
11402 sdcdbsrc-goto-sdcdb
11403 \protected_separator
11405 \protected_separator
11407 \protected_separator
11409 \protected_separator
11411 \protected_separator
11413 \protected_separator
11415 \protected_separator
11417 \protected_separator
11419 \protected_separator
11421 \protected_separator
11422 Goto the SDCDB output buffer
11425 \protected_separator
11427 \protected_separator
11429 \protected_separator
11431 \protected_separator
11433 \protected_separator
11435 \protected_separator
11437 \protected_separator
11439 \protected_separator
11441 \protected_separator
11443 \protected_separator
11445 \protected_separator
11447 \protected_separator
11449 \protected_separator
11451 \protected_separator
11453 \protected_separator
11455 \protected_separator
11457 \protected_separator
11459 \protected_separator
11461 \protected_separator
11463 \protected_separator
11465 \protected_separator
11467 \protected_separator
11469 \protected_separator
11471 \protected_separator
11473 \protected_separator
11475 \protected_separator
11477 \protected_separator
11479 \protected_separator
11481 \protected_separator
11483 \protected_separator
11484 Toggles Sdcdbsrc mode (turns it off)
11489 \protected_separator
11491 \protected_separator
11493 \protected_separator
11495 \protected_separator
11497 \protected_separator
11499 \protected_separator
11501 \protected_separator
11503 \protected_separator
11504 sdcdb-finish-from-src
11505 \protected_separator
11507 \protected_separator
11509 \protected_separator
11511 \protected_separator
11513 \protected_separator
11515 \protected_separator
11517 \protected_separator
11519 \protected_separator
11520 SDCDB finish command
11525 \protected_separator
11527 \protected_separator
11529 \protected_separator
11531 \protected_separator
11533 \protected_separator
11535 \protected_separator
11537 \protected_separator
11539 \protected_separator
11541 \protected_separator
11543 \protected_separator
11545 \protected_separator
11547 \protected_separator
11549 \protected_separator
11551 \protected_separator
11553 \protected_separator
11555 \protected_separator
11557 \protected_separator
11559 \protected_separator
11561 \protected_separator
11563 \protected_separator
11565 \protected_separator
11567 \protected_separator
11569 \protected_separator
11571 \protected_separator
11573 \protected_separator
11575 \protected_separator
11576 Set break for line with point
11579 \protected_separator
11581 \protected_separator
11583 \protected_separator
11585 \protected_separator
11587 \protected_separator
11589 \protected_separator
11591 \protected_separator
11593 \protected_separator
11595 \protected_separator
11597 \protected_separator
11599 \protected_separator
11601 \protected_separator
11603 \protected_separator
11605 \protected_separator
11607 \protected_separator
11609 \protected_separator
11611 \protected_separator
11613 \protected_separator
11615 \protected_separator
11617 \protected_separator
11619 \protected_separator
11621 \protected_separator
11623 \protected_separator
11625 \protected_separator
11627 \protected_separator
11629 \protected_separator
11630 Toggle Sdcdbsrc mode
11633 \protected_separator
11635 \protected_separator
11637 \protected_separator
11639 \protected_separator
11641 \protected_separator
11643 \protected_separator
11645 \protected_separator
11647 \protected_separator
11649 \protected_separator
11651 \protected_separator
11653 \protected_separator
11655 \protected_separator
11657 \protected_separator
11659 \protected_separator
11661 \protected_separator
11663 \protected_separator
11665 \protected_separator
11667 \protected_separator
11669 \protected_separator
11671 \protected_separator
11673 \protected_separator
11675 \protected_separator
11684 \begin_inset LatexCommand \label{Conclusion}
11691 SDCC is a large project , the compiler alone (without the Assembler Package
11692 , Preprocessor & garbage collector) is about 40,000 lines of code (blank
11694 As with any project of this size there are bound to be bugs, I am more
11695 than willing to work to fix these bugs , of course all the source code
11696 is included with the package.
11700 Where does it go from here ? I am planning to target the Atmel AVR 8-bit
11701 MCUs which seems to have a lot of users.
11702 I am also planning to include an alias analysis system with this compiler
11703 (it does not currently have one).
11707 \begin_inset LatexCommand \label{Acknowledgements}
11714 Alan Baldwin (baldwin@shop-pdp.kent.edu) - Initial version of ASXXXX & ASLINK.
11718 John Hartman (jhartman@compuserve.com) - Porting ASXXX & ASLINK for 8051
11722 Obukhov (dso@usa.net) - malloc & serial i/o routines.
11726 Daniel Drotos <drdani@mazsola.iit.uni-miskolc.hu> - for his Freeware simulator
11729 Jans J Boehm(boehm@sgi.com) and Alan J Demers - Conservative garbage collector
11733 Malini Dutta(malini_dutta@hotmail.com) - my wife for her patience and support.
11736 Unknown - for the GNU C - preprocessor.
11739 Appendix A: The Z80 and gbz80 port
11742 2.2.0 can target both the Zilog Z80 and the Nintendo Gameboy's Z80-like gbz80.
11743 The port is incomplete - long support is incomplete (mul, div and mod are
11744 unimplimented), and both float and bitfield support is missing, but apart
11745 from that the code generated is correct.
11748 As always, the code is the authoritave reference - see z80/ralloc.c and z80/gen.c.
11749 The stack frame is similar to that generated by the IAR Z80 compiler.
11750 IX is used as the base pointer, HL is used as a temporary register, and
11751 BC and DE are available for holding varibles.
11752 IY is currently unusued.
11753 Return values are stored in HL.
11754 One bad side effect of using IX as the base pointer is that a functions
11755 stack frame is limited to 127 bytes - this will be fixed in a later version.bc
11762 \begin_inset LatexCommand \index