-
-\protected_separator
-
-\protected_separator
- cp * /usr/local/bin
-\layout Standard
-
-
-\protected_separator
-
-\layout Standard
-
-
-\protected_separator
- 11.
- Make sure /usr/local/bin is in Your PATH
-\layout Standard
-
-
-\protected_separator
- You may add c:
-\backslash
-usr
-\backslash
-local
-\backslash
-bin to your path however your Win32 system allows.
-\protected_separator
- For
-\layout Standard
-
-
-\protected_separator
- example you may add it to the PATH statement in autoexec.bat.
-
-\layout Standard
-
-
-\protected_separator
-
-\layout Standard
-
-
-\protected_separator
- Good luck.
-\protected_separator
- If you have any questions send them to me or post them
-\layout Standard
-
-
-\protected_separator
- to the list.
-\layout Subsubsection
-
-FreeBSD and other non-GNU unixes
-\layout Standard
-
-Note that the SDCC build environment uses Gnu make.
- If this is not the default 'make' on your system, you may need to install
- it.
- On many systems, Gnu make is installed as 'gmake'.
-\layout Section
-
-Compiling.
-\begin_inset LatexCommand \label{Compiling}
-
-\end_inset
-
-
-\layout Subsection
-
-Single Source file projects.
-\begin_inset LatexCommand \label{One Source File}
-
-\end_inset
-
-
-\layout Standard
-
-For single source file projects the process is very simple.
- Compile your programs with the following command
-\layout Standard
-
-
-\size footnotesize
-sdcc sourcefile.c
-\layout Standard
-
-The above command will compile ,assemble and link your source file.
- Output files are as follows.
-\layout Itemize
-
-
-\size footnotesize
-sourcefile.asm - Assembler source file created by the compiler
-\layout Itemize
-
-
-\size footnotesize
-sourcefile.lst - Assembler listing file created by the Assembler
-\layout Itemize
-
-
-\size footnotesize
-sourcefile.rst - Assembler listing file updated with linkedit information
- , created by linkage editor
-\layout Itemize
-
-
-\size footnotesize
-sourcefile.sym - symbol listing for the sourcefile, created by the assembler.
-\layout Itemize
-
-
-\size footnotesize
-sourcefile.rel - Object file created by the assembler, input to Linkage editor.
-\layout Itemize
-
-
-\size footnotesize
-sourcefile.map - The memory map for the load module, created by the Linker.
-\layout Itemize
-
-
-\size footnotesize
-sourcefile.<ihx | s19> - The load module : ihx - Intel hex format (default
- ), s19 - Motorola S19 format when compiler option --out-fmt-s19 is used.
-\layout Subsection
-
-Projects with multiple source files.
-\layout Standard
-
-SDCC can compile only ONE file at a time.
- Let us for example assume that you have a project containing the following
- files.
-\layout Standard
-
-
-\size footnotesize
-foo1.c ( contains some functions )
-\layout Standard
-
-
-\size footnotesize
-foo2.c (contains some more functions)
-\layout Standard
-
-
-\size footnotesize
-foomain.c (contains more functions and the function main)
-\layout Standard
-
-The first two files will need to be compiled separately with the commands
-\layout Standard
-
-
-\size footnotesize
-sdcc -c foo1.c
-\layout Standard
-
-
-\size footnotesize
-sdcc -c foo2.c
-\layout Standard
-
-Then compile the source file containing main and link the other files together
- with the following command.
-\layout Standard
-
-
-\size footnotesize
-sdcc foomain.c foo1.rel foo2.rel
-\layout Standard
-
-Alternatively
-\emph on
-foomain.c
-\emph default
- can be separately compiled as well
-\layout Standard
-
-
-\size footnotesize
-sdcc -c foomain.c
-\layout Standard
-
-
-\size footnotesize
-sdcc foomain.rel foo1.rel foo2.rel
-\layout Standard
-
-The file containing the main function MUST be the FIRST file specified in
- the command line , since the linkage editor processes file in the order
- they are presented to it.
-\layout Subsection
-
-Projects with additional libraries.
-\layout Standard
-
-Some reusable routines may be compiled into a library, see the documentation
- for the assembler and linkage editor in the directory
-\emph on
-SDCCDIR/asxxxx/asxhtm.htm
-\emph default
-this describes how to create a
-\emph on
-.lib
-\emph default
- library file, the libraries created in this manner may be included using
- the command line, make sure you include the -L <library-path> option to
- tell the linker where to look for these files.
- Here is an example, assuming you have the source file
-\emph on
-'foomain.c
-\emph default
-' and a library
-\emph on
- 'foolib.lib'
-\emph default
- in the directory
-\emph on
-'mylib'
-\emph default
-.
-\layout Standard
-
-
-\size footnotesize
-sdcc foomain.c foolib.lib -L mylib
-\layout Standard
-
-Note here that
-\emph on
-'mylib
-\emph default
-' must be an absolute path name.
-\layout Standard
-
-The view of the way the linkage editor processes the library files, it is
- recommended that you put each source routine in a separate file and combine
- them using the .lib file.
- For an example see the standard library file 'libsdcc.lib' in the directory
- SDCCDIR/sdcc51lib.
-\layout Section
-
-Command Line options
-\begin_inset LatexCommand \label{Command Line Options}
-
-\end_inset
-
-
-\layout Itemize
-
--mmcs51
-\begin_inset LatexCommand \label{-mmcs51}
-
-\end_inset
-
-Generate code for the MCS51 (8051) family of processors.
- This is the default processor target.
-\layout Itemize
-
--mz80
-\begin_inset LatexCommand \label{-mz80}
-
-\end_inset
-
-Generate code for the Z80 family of processors.
- Various other options may not be applicable in this mode.
-
-\layout Itemize
-
-
-\series bold
--mds390
-\series default
-
-\begin_inset LatexCommand \label{-mds390}
-
-\end_inset
-
-Generate code for the DS80C390 processor.
- Various other options may not be applicable in this mode.
-\layout Itemize
-
-
-\series bold
-\size large
---model-large
-\emph on
-
-\begin_inset LatexCommand \label{--model-large}
-
-\end_inset
-
-
-\series default
-\size default
-\emph default
- Generate code for Large model programs see section Memory Models for more
- details.
- If this option is used all source files in the project should be compiled
- with this option.
- In addition the standard library routines are compiled with small model
- , they will need to be recompiled.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---model-small
-\series default
-\emph on
-\bar default
-
-\size default
-\emph default
-
-\begin_inset LatexCommand \label{--model-small}
-
-\end_inset
-
-Generate code for Small Model programs see section Memory Models for more
- details.
- This is the default model.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---model-flat24
-\series default
-\emph on
-\bar default
-
-\size default
-\emph default
-
-\begin_inset LatexCommand \ref[--model-flat24]{--model-flat24}
-
-\end_inset
-
-Generate code forDS80C390 24-bit flat mode.
- See section Memory Models for more details.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---stack-
-\emph on
-auto
-\series default
-\bar default
-
-\size default
-\emph default
-
-\begin_inset LatexCommand \label{--stack-auto}
-
-\end_inset
-
-All functions in the source file will be compiled as
-\emph on
-reentrant
-\emph default
-, i.e.
- the parameters and local variables will be allocated on the stack.
- see section Parameters and Local Variables for more details.
- If this option is used all source files in the project should be compiled
- with this option.
-
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---xstack
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--xstack}
-
-\end_inset
-
- Uses a pseudo stack in the first 256 bytes in the external ram for allocating
- variables and passing parameters.
- See section on external stack for more details.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---nogcse
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--nogcse}
-
-\end_inset
-
- Will not do global subexpression elimination, this option may be used when
- the compiler creates undesirably large stack/data spaces to store compiler
- temporaries.
- A warning message will be generated when this happens and the compiler
- will indicate the number of extra bytes it allocated.
- It recommended that this option NOT be used , #pragma NOGCSE can be used
- to turn off global subexpression elimination for a given function only.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---noinvariant
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--noinvariant}
-
-\end_inset
-
- Will not do loop invariant optimizations, this may be turned off for reasons
- explained for the previous option .
- For more details of loop optimizations performed see section Loop Invariants.It
- recommended that this option NOT be used , #pragma NOINVARIANT can be used
- to turn off invariant optimizations for a given function only.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---noinduction
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--noinduction}
-
-\end_inset
-
- Will not do loop induction optimizations, see section Strength reduction
- for more details.It recommended that this option NOT be used , #pragma NOINDUCTI
-ON can be used to turn off induction optimizations for given function only.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---nojtbound
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--nojtbound}
-
-\end_inset
-
- Will not generate boundary condition check when switch statements are implement
-ed using jump-tables.
- See section Switch Statements for more details.It recommended that this
- option NOT be used , #pragma NOJTBOUND can be used to turn off boundary
- checking for jump tables for a given function only.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---noloopreverse
-\series default
-\bar default
-
-\size default
-
-\begin_inset LatexCommand \label{--noloopreverse}
-
-\end_inset
-
-Will not do loop reversal optimization
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---noregparms
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--noregparms}
-
-\end_inset
-
- By default the first parameter is passed using global registers (DPL,DPH,B,ACC).
- This option will disable parameter passing using registers.
- NOTE: if your program uses the 16/32 bit support routines (for multiplication/d
-ivision) these library routines will need to be recompiled with the --noregparms
- option as well.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---callee-saves function1[,function2][,function3]....
-
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--callee-saves}
-
-\end_inset
-
-The compiler by default uses a caller saves convention for register saving
- across function calls, however this can cause unneccessary register pushing
- & popping when calling small functions from larger functions.
- This option can be used to switch the register saving convention for the
- function names specified.
- The compiler will not save registers when calling these functions, extra
- code will be generated at the entry & exit for these functions to save
- & restore the registers used by these functions, this can SUBSTANTIALLY
- reduce code & improve run time performance of the generated code.
- In future the compiler (with interprocedural analysis) will be able to
- determine the appropriate scheme to use for each function call.
- DO NOT use this option for built-in functions such as _muluint..., if this
- option is used for a library function the appropriate library function
- needs to be recompiled with the same option.
- If the project consists of multiple source files then all the source file
- should be compiled with the same --callee-saves option string.
- Also see Pragma Directive
-\begin_inset LatexCommand \ref{Pragmaa}
-
-\end_inset
-
- CALLEE-SAVES.
-\begin_inset LatexCommand \ref{pragma callee-saves}
-
-\end_inset
-
- .
-\layout Itemize
-
-
-\series bold
-\bar under
---debug
-\series default
-\bar default
-
-\begin_inset LatexCommand \label{--debug}
-
-\end_inset
-
-When this option is used the compiler will generate debug information ,
- that can be used with the SDCDB.
- The debug information is collected in a file with .cdb extension.
- For more information see documentation for SDCDB.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---regextend
-\size default
-
-\series default
-\bar default
-
-\begin_inset LatexCommand \label{--regextend}
-
-\end_inset
-
- This option will cause the compiler to define pseudo registers , if this
- option is used, all source files in the project should be compiled with
- this option.
- See section Register Extension for more details.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---compile-only
-\series default
-\bar default
-(-c)
-\size default
-
-\begin_inset LatexCommand \label{--compile-only}
-
-\end_inset
-
- will compile and assemble the source only, will not call the linkage editor.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---xram-loc
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--xram-loc}
-
-\end_inset
-
-<Value> The start location of the external ram, default value is 0.
- The value entered can be in Hexadecimal or Decimal format .eg.
- --xram-loc 0x8000 or --xram-loc 32768.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---code-loc
-\size default
-
-\series default
-\bar default
-
-\begin_inset LatexCommand \label{--code-loc}
-
-\end_inset
-
-<Value> The start location of the code segment , default value 0.
- Note when this option is used the interrupt vector table is also relocated
- to the given address.
- The value entered can be in Hexadecimal or Decimal format .eg.
- --code-loc 0x8000 or --code-loc 32768.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---stack-loc
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--stack-loc}
-
-\end_inset
-
-<Value> The initial value of the stack pointer.
- The default value of the stack pointer is 0x07 if only register bank 0
- is used, if other register banks are used then the stack pointer is initialized
- to the location above the highest register bank used.
- eg.
- if register banks 1 & 2 are used the stack pointer will default to location
- 0x18.
- The value entered can be in Hexadecimal or Decimal format .eg.
- --stack-loc 0x20 or --stack-loc 32.
- If all four register banks are used the stack will be placed after the
- data segment (equivalent to --stack-after-data)
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---stack-after-data
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--stack-after-data}
-
-\end_inset
-
-This option will cause the stack to be located in the internal ram after
- the data segment.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---data-loc
-\series default
-\bar default
-
-\size default
-
-\begin_inset LatexCommand \label{--data-loc}
-
-\end_inset
-
-<Value> The start location of the internal ram data segment, the default
- value is 0x30.The value entered can be in Hexadecimal or Decimal format
- .eg.
- --data-loc 0x20 or --data-loc 32.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---idata-loc
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--idata-loc}
-
-\end_inset
-
-<Value> The start location of the indirectly addressable internal ram, default
- value is 0x80.
- The value entered can be in Hexadecimal or Decimal format .eg.
- --idata-loc 0x88 or --idata-loc 136.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---peep-file
-\size default
-
-\begin_inset LatexCommand \label{--peep-file}
-
-\end_inset
-
-
-\series default
-\bar default
-<filename> This option can be used to use additional rules to be used by
- the peep hole optimizer.
- See section Peep Hole optimizations for details on how to write these rules.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---lib-path (-L)
-\size default
-
-\series default
-\bar default
-
-\begin_inset LatexCommand \label{--lib-path}
-
-\end_inset
-
-<absolute path to additional libraries> This option is passed to the linkage
- editor, additional libraries search path.
- The path name must be absolute.
- Additional library files may be specified in the command line .
- See section Compiling programs for more details.
-\layout Itemize
-
-
-\series bold
-\bar under
--I <path>
-\begin_inset LatexCommand \label{-I}
-
-\end_inset
-
-
-\series default
-\bar default
- The additional location where the pre processor will look for <..h> or
-\begin_inset Quotes eld
-\end_inset
-
-..h
-\begin_inset Quotes erd
-\end_inset
-
- files.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--D<macro[=value]>
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-D}
-
-\end_inset
-
-Command line definition of macros.
- Passed to the pre processor.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--E
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-E}
-
-\end_inset
-
- Run only the C preprocessor.
- Preprocess all the C source files specified and output the results to standard
- output.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--M
-\bar default
-
-\begin_inset LatexCommand \label{-M}
-
-\end_inset
-
-
-\series default
-\size default
- Tell the preprocessor to output a rule suitable for make describing the
- dependencies of each object file.
- For each source file, the preprocessor outputs one make-rule whose target
- is the object file name for that source file and whose dependencies are
- all the files `#include'd in it.
- This rule may be a single line or may be continued with `
-\backslash
-'-newline if it is long.
- The list of rules is printed on standard output instead of the preprocessed
- C program.
- `-M' implies `-E'.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--C
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-C}
-
-\end_inset
-
-Tell the preprocessor not to discard comments.
- Used with the `-E' option.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--MM
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-MM}
-
-\end_inset
-
-Like `-M' but the output mentions only the user header files included with
- `#include file"'.
- System header files included with `#include <file>' are omitted.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--Aquestion(answer)
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-Aquestion(answer)}
-
-\end_inset
-
- Assert the answer answer for question, in case it is tested with a preprocessor
- conditional such as `#if #question(answer)'.
- `-A-' disables the standard asser- tions that normally describe the target
- machine.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--Aquestion
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-Aquestion}
-
-\end_inset
-
- (answer) Assert the answer answer for question, in case it is tested with
- a preprocessor conditional such as `#if #question(answer)'.
- `-A-' disables the standard assertions that normally describe the target
- machine.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--Umacro
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-Umacro}
-
-\end_inset
-
- Undefine macro macro.
- `-U' options are evaluated after all `-D' options, but before any `-include'
- and `-imac- ros' options.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--dM
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-dM}
-
-\end_inset
-
- Tell the preprocessor to output only a list of the mac- ro definitions
- that are in effect at the end of prepro- cessing.
- Used with the `-E' option.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--dD
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-dD}
-
-\end_inset
-
-Tell the preprocessor to pass all macro definitions into the output, in
- their proper sequence in the rest of the output.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--dN
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-dN}
-
-\end_inset
-
-Like `-dD' except that the macro arguments and contents are omitted.
- Only `#define name' is included in the output.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
--S
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{-S}
-
-\end_inset
-
-Stop after the stage of compilation proper; do not as- semble.
- The output is an assembler code file for the input file specified.
-\layout Itemize
-
-
-\series bold
-\bar under
--Wa asmOption[,asmOption]
-\series default
-\bar default
-...
- Pass the asmOption to the assembler
-\layout Itemize
-
-
-\series bold
-\bar under
--Wl linkOption[,linkOption]
-\series default
-\bar default
- ..
- Pass the linkOption to the linker.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---int-long-reent
-\series default
-\bar default
-
-\size default
-
-\begin_inset LatexCommand \label{--int-long-rent}
-
-\end_inset
-
- Integer (16 bit) and long (32 bit) libraries have been compiled as reentrant.
- Note by default these libraries are compiled as non-reentrant.
- See section Installation for more details.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---cyclomatic
-\size default
-
-\series default
-\bar default
-
-\begin_inset LatexCommand \label{--cyclomatic}
-
-\end_inset
-
-This option will cause the compiler to generate an information message for
- each function in the source file.
- The message contains some
-\emph on
-important
-\emph default
- information about the function.
- The number of edges and nodes the compiler detected in the control flow
- graph of the function, and most importantly the
-\emph on
-cyclomatic complexity
-\emph default
- see section on Cyclomatic Complexity for more details.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---float-reent
-\size default
-
-\series default
-\bar default
-
-\begin_inset LatexCommand \label{--float-reent}
-
-\end_inset
-
- Floating point library is compiled as reentrant.See section Installation
- for more details.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---out-fmt-ihx
-\size default
-
-\begin_inset LatexCommand \label{--out-fmt-ihx}
-
-\end_inset
-
-
-\series default
-\bar default
-The linker output (final object code) is in Intel Hex format.
- (This is the default option).
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---out-fmt-s19
-\size default
-
-\series default
-\bar default
-
-\begin_inset LatexCommand \label{--out-fmt-s19}
-
-\end_inset
-
-The linker output (final object code) is in Motorola S19 format.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---nooverlay
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--nooverlay}
-
-\end_inset
-
- The compiler will not overlay parameters and local variables of any function,
- see section Parameters and local variables for more details.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---main-return
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--main-return}
-
-\end_inset
-
- This option can be used when the code generated is called by a monitor
- program.
- The compiler will generate a 'ret' upon return from the 'main' function.
- The default option is to lock up i.e.
- generate a 'ljmp .' .
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---no-peep
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--no-peep}
-
-\end_inset
-
- Disable peep-hole optimization.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---peep-asm
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--peep-asm}
-
-\end_inset
-
- Pass the inline assembler code through the peep hole optimizer.
- Can cause unexpected changes to inline assembler code , please go through
- the peephole optimizer rules defnied in file 'SDCCpeeph.def' before using
- this option.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---iram-size
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--iram-size}
-
-\end_inset
-
- <Value> Causes the linker to check if the interal ram usage is within limits
- of the given value.
-\layout Standard
-
-The following options are provided for the purpose of retargetting and debugging
- the compiler .
- These provided a means to dump the intermediate code (iCode) generated
- by the compiler in human readable form at various stages of the compilation
- process.
-
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---dumpraw
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--dumpraw}
-
-\end_inset
-
-.
- This option will cause the compiler to dump the intermediate code into
- a file of named
-\emph on
-<source filename>.dumpraw
-\emph default
- just after the intermediate code has been generated for a function , i.e.
- before any optimizations are done.
- The basic blocks at this stage ordered in the depth first number, so they
- may not be in sequence of execution.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---dumpgcse
-\series default
-\bar default
-.
-\size default
-
-\begin_inset LatexCommand \label{--dumpgcse}
-
-\end_inset
-
- Will create a dump if iCode, after global subexpression elimination, into
- a file named
-\emph on
-<source filename>.dumpgcse.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---dumpdeadcode
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--dumpdeadcode}
-
-\end_inset
-
-.Will create a dump if iCode, after deadcode elimination, into a file named
-
-\emph on
-<source filename>.dumpdeadcode.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---dumploop.
-
-\series default
-\bar default
-
-\size default
-
-\begin_inset LatexCommand \label{--dumploop}
-
-\end_inset
-
-Will create a dump if iCode, after loop optimizations, into a file named
-
-\emph on
-<source filename>.dumploop.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---dumprange.
-
-\series default
-\bar default
-
-\size default
-
-\begin_inset LatexCommand \label{--dump-range}
-
-\end_inset
-
-Will create a dump if iCode, after live range analysis, into a file named
-
-\emph on
-<source filename>.dumprange.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---dumpregassign.
-
-\size default
-
-\series default
-\bar default
-
-\begin_inset LatexCommand \label{--dumpregassign}
-
-\end_inset
-
-Will create a dump if iCode, after register assignment , into a file named
-
-\emph on
-<source filename>.dumprassgn.
-\layout Itemize
-
-
-\series bold
-\size large
-\bar under
---dumpall.
-
-\series default
-\size default
-\bar default
-
-\begin_inset LatexCommand \label{--dumpall}
-
-\end_inset
-
-Will cause all the above mentioned dumps to be created.
-\layout Standard
-
-Note that the files created for the dump are appended to each time.
- So the files should be deleted manually , before each dump is created.
-
-\layout Standard
-
-When reporting bugs, it will be very helpful if you could include these
- dumps along with the portion of the code that is causing the problem.
-\layout Section
-
-Language Extensions
-\begin_inset LatexCommand \label{Language Extension}
-
-\end_inset
-
-
-\layout Subsection
-
-Storage Classes.
-\begin_inset LatexCommand \label{Storage Classes}
-
-\end_inset
-
-
-\layout Standard
-
-In addition to the ANSI storage classes SDCC allows the following 8051 specific
- storage classes.
-\layout Subsubsection
-
-xdata.
-\begin_inset LatexCommand \label{xdata}
-
-\end_inset
-
-
-\layout Standard
-
-Variables declared with this storage class will be placed in the extern
- RAM.
- This is the
-\series bold
-default
-\series default
- storage class for Large Memory model .
-\layout Standard
-
-
-\size footnotesize
-eg.
-
-\emph on
-xdata unsigned char xduc;
-\layout Subsubsection
-
-data
-\begin_inset LatexCommand \label{data}
-
-\end_inset
-
-
-\layout Standard
-
-This is the
-\series bold
-default
-\series default
- storage class for Small Memory model.
- Variables declared with this storage class will be allocated in the internal
- RAM.
-\layout Standard
-
-
-\size footnotesize
-eg.
-
-\emph on
- data int iramdata;
-\layout Subsubsection
-
-idata
-\begin_inset LatexCommand \label{idata}
-
-\end_inset
-
-
-\layout Standard
-
-Variables declared with this storage class will be allocated into the indirectly
- addressable portion of the internal ram of a 8051 .
-\layout Standard
-
-
-\size footnotesize
-eg.
-\emph on
-idata int idi;
-\layout Subsubsection
-
-bit
-\begin_inset LatexCommand \label{bit}
-
-\end_inset
-
-
-\layout Standard
-
-This is a data-type and a storage class specifier.
- When a variable is declared as a bit , it is allocated into the bit addressable
- memory of 8051.
-\layout Standard
-
-eg.
-\emph on
-bit iFlag;
-\layout Subsubsection
-
-sfr / sbit
-\begin_inset LatexCommand \label{sfr / sbit}
-
-\end_inset
-
-
-\layout Standard
-
-Like the bit keyword,
-\emph on
-sfr / sbit
-\emph default
-signifies both a data-type and storage class, they are used to describe
- the special function registers and special bit variables of a 8051.
-
-\layout Standard
-
-eg.
-
-\emph on
-
-\layout Standard
-
-
-\emph on
-sfr at 0x80 P0;
-\emph default
-\noun on
-/* special function register P0 at location 0x80 */
-\layout Standard
-
-
-\emph on
-sbit at 0xd7 CY; /*
-\noun on
-CY (Carry Flag) */
-\layout Section
-
-Optimizations
-\begin_inset LatexCommand \label{Optimizations}
-
-\end_inset
-
-
-\layout Standard
-
-SDCC performs a a host of standard optimizations in addition to some MCU
- specific optimizations.
-
-\layout Subsection
-
-Sub-expression elimination
-\begin_inset LatexCommand \label{Sub-expression Elimination}
-
-\end_inset
-
-
-\layout Standard
-
-The compiler does
-\emph on
-local and global
-\emph default
-common subexpression elimination.
-\layout Standard
-
-
-\family typewriter
-\size scriptsize
-eg.
-
-\layout Standard
-
-
-\size small
-i = x + y + 1;
-\size default
-
-\newline
-j
-\size small
-= x + y;
-\layout Standard
-
-will be translated to
-\layout Standard
-
-
-\size small
-iTemp = x + y
-\newline
-i = iTemp + 1
-\newline
-j = iTemp
-\layout Standard
-
-Some subexpressions are not as obvious as the above example.
-\layout Standard
-
-eg.
-\layout Standard
-
-
-\size small
-a->b[i].c = 10;
-\newline
-a->b[i].d = 11;
-\layout Standard
-
-In this case the address arithmetic
-\emph on
-a->b[i]
-\emph default
-will be computed only once; the equivalent code in C would be.
-\layout Standard
-
-
-\size small
-iTemp = a->b[i];
-\newline
-iTemp.c = 10;
-\newline
-iTemp.d = 11;
-\layout Standard
-
-The compiler will try to keep these temporary variables in registers.
-\layout Subsection
-
-Dead-Code elimination.
-\begin_inset LatexCommand \label{Dead-code elimination}
-
-\end_inset
-
-
-\layout Standard
-
-eg.
-\layout Standard
-
-
-\size small
-int global;
-\newline
-void f () {
-\newline
-
-\protected_separator
-
-\protected_separator
-int i;
-\newline
-
-\protected_separator
-
-\protected_separator
-i = 1;
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-/* dead store */
-\newline
-
-\protected_separator
-
-\protected_separator
-global = 1; /* dead store */
-\newline
-
-\protected_separator
-
-\protected_separator
-global = 2;
-\newline
-
-\protected_separator
-
-\protected_separator
-return;
-\newline
-
-\protected_separator
-
-\protected_separator
-global = 3; /* unreachable */
-\newline
-}
-\layout Standard
-
-will be changed to
-\layout Standard
-
-
-\size footnotesize
-int global; void f ()
-\newline
-{
-\protected_separator
-
-\protected_separator
-
-\newline
-
-\protected_separator
-global = 2;
-\protected_separator
-
-\protected_separator
-
-\newline
-
-\protected_separator
-return;
-\newline
-}
-\layout Subsection
-
-Copy-Propagation:
-\begin_inset LatexCommand \label{Copy-Propagation}
-
-\end_inset
-
-
-\layout Standard
-
-eg.
-\layout Standard
-
-
-\size footnotesize
-int f() {
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-int i, j;
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-i = 10;
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-j = i;
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-return j;
-\newline
-}
-\layout Standard
-
-will be changed to
-\layout Standard
-
-
-\size small
-int f() {
-\newline
-
-\protected_separator
-
-\protected_separator
- int i,j;
-\newline
-
-\protected_separator
-
-\protected_separator
- i = 10;
-\newline
-
-\protected_separator
-
-\protected_separator
- j = 10;
-\newline
-
-\protected_separator
-
-\protected_separator
- return 10;
-\newline
-}
-\layout Standard
-
-Note: the dead stores created by this copy propagation will be eliminated
- by dead-code elimination .
-\layout Subsection
-
-Loop optimizations
-\begin_inset LatexCommand \label{Loop Optimizations}
-
-\end_inset
-
-
-\layout Standard
-
-Two types of loop optimizations are done by SDCC loop invariant lifting
- and strength reduction of loop induction variables.In addition to the strength
- reduction the optimizer marks the induction variables and the register
- allocator tries to keep the induction variables in registers for the duration
- of the loop.
- Because of this preference of the register allocator , loop induction optimizat
-ion causes an increase in register pressure, which may cause unwanted spilling
- of other temporary variables into the stack / data space .
- The compiler will generate a warning message when it is forced to allocate
- extra space either on the stack or data space.
- If this extra space allocation is undesirable then induction optimization
- can be eliminated either for the entire source file ( with --noinduction
- option) or for a given function only (#pragma NOINDUCTION).
-\layout Subsubsection
-
-Loop Invariant:
-\begin_inset LatexCommand \label{Loop Invariant}
-
-\end_inset
-
-
-\layout Standard
-
-eg
-\layout Standard
-
-
-\size small
-for (i = 0 ; i < 100 ; i ++)
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-f += k + l;
-\layout Standard
-
-changed to
-\layout Standard
-
-
-\size small
-itemp = k + l;
-\newline
-for ( i = 0; i < 100; i++ ) f += itemp;
-\layout Standard
-
-As mentioned previously some loop invariants are not as apparent, all static
- address computations are also moved out of the loop.
-\layout Subsubsection
-
-Strength reduction :
-\begin_inset LatexCommand \label{Strength Reduction}
-
-\end_inset
-
-
-\layout Standard
-
-This optimization substitutes an expression by a cheaper expression.
-\layout Standard
-
-eg.
-\layout Standard
-
-
-\size small
-for (i=0;i < 100; i++) ar[i*5] = i*3;
-\layout Standard
-
-changed to
-\layout Standard
-
-
-\size small
-itemp1 = 0;
-\newline
-itemp2 = 0;
-\newline
-for (i=0;i< 100;i++) {
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-ar[itemp1] = itemp2;
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-itemp1 += 5;
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-itemp2 += 3;
-\newline
-}
-\layout Standard
-
-The more expensive multiplication is changed to a less expensive addition.
-\layout Subsubsection
-
-Loop reversing:
-\begin_inset LatexCommand \label{Loop reversing}
-
-\end_inset
-
-
-\layout Standard
-
-This optimization is done to reduce the overhead of checking loop boundaries
- for every iteration.
- Some simple loops can be reversed and implemented using a
-\begin_inset Quotes eld
-\end_inset
-
-decrement and jump if not zero
-\begin_inset Quotes erd
-\end_inset
-
- instruction.
- SDCC checks for the following criterion to determine if a loop is reversible
- (note: more sophisticated compiers use data-dependency analysis to make
- this determination, SDCC uses a more simple minded analysis).
-\layout Itemize
-
-The 'for' loop is of the form
-\newline
-
-\begin_inset Quotes eld
-\end_inset
-
-for ( <symbol> = <expression> ; <sym> [< | <=] <expression> ; [<sym>++ |
- <sym> += 1])
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-<for body>
-\begin_inset Quotes erd
-\end_inset
-
-
-\layout Itemize
-
-The <for body> does not contain
-\begin_inset Quotes eld
-\end_inset
-
-continue
-\begin_inset Quotes erd
-\end_inset
-
- or 'break
-\begin_inset Quotes erd
-\end_inset
-
-.
-\layout Itemize
-
-All goto's are contained within the loop.
-\layout Itemize
-
-No function calls within the loop.
-\layout Itemize
-
-The loop control variable <sym> is not assigned any value within the loop
-\layout Itemize
-
-The loop control variable does NOT participate in any arithmetic operation
- within the loop.
-\layout Itemize
-
-There are NO switch statements in the loop.
-\layout Standard
-
-Note djnz instruction can be used for 8-bit values ONLY, therefore it is
- advantageous to declare loop control symbols as either 'char' or 'short',
- ofcourse this may not be possible on all situations.
-\layout Subsection
-
-Algebraic simplifications:
-\begin_inset LatexCommand \label{Algebraic Simplifications}
-
-\end_inset
-
-
-\layout Standard
-
-SDCC does numerous algebraic simplifications, the following is a small sub-set
- of these optimizations.
-\layout Standard
-
-
-\size small
-eg
-\emph on
-
-\emph default
-
-\newline
-i = j + 0 ; /* changed to */ i = j;
-\newline
-i /= 2; /* changed to */ i >>= 1;
-\newline
-i = j - j ; /* changed to */ i = 0;
-\newline
-i = j / 1 ; /* changed to */ i = j;
-\layout Standard
-
-Note the subexpressions given above are generally introduced by macro expansions
- or as a result of copy/constant propagation.
-\layout Subsection
-
-'switch' statements.
-\begin_inset LatexCommand \label{Switch Statement}
-
-\end_inset
-
-
-\layout Standard
-
-SDCC changes switch statements to jump tables when the following conditions
- are true.
-
-\layout Itemize
-
-The case labels are in numerical sequence , the labels need not be in order,
- and the starting number need not be one or zero.
-\layout Standard
-
-eg
-\layout Standard
-
-
-\size small
-switch(i) {
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-switch (i) {
-\newline
-case 4:...
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-case 1: ...
-
-\newline
-case 5:...
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-case 2: ...
-
-\newline
-case 3:...
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-case 3: ...
-
-\newline
-case 6:...
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-case 4: ...
-
-\newline
-}
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-}
-\layout Standard
-
-Both the above switch statements will be implemented using a jump-table.
-\layout Itemize
-
-The number of case labels is at least three, since it takes two conditional
- statements to handle the boundary conditions.
-\layout Itemize
-
-The number of case labels is less than 84, since each label takes 3 bytes
- and a jump-table can be utmost 256 bytes long.
-
-\layout Standard
-
-Switch statements which have gaps in the numeric sequence or those that
- have more that 84 case labels can be split into more than one switch statement
- for efficient code generation.
-\layout Standard
-
-eg
-\layout Standard
-
-
-\size small
-switch (i) {
-\newline
-case 1: ...
-
-\newline
-case 2: ...
-
-\newline
-case 3: ...
-
-\newline
-case 4: ...
-
-\newline
-case 9: ...
-
-\newline
-case 10: ...
-
-\newline
-case 11: ...
-
-\newline
-case 12: ...
-
-\newline
-}
-\layout Standard
-
-If the above switch statement is broken down into two switch statements
-\layout Standard
-
-
-\size small
-switch (i) {
-\newline
-case 1: ...
-
-\newline
-case 2: ...
-
-\newline
-case 3: ...
-
-\newline
-case 4: ...
-
-\newline
-}
-\layout Standard
-
-
-\size small
-switch (i) {
-\newline
-case 9: ...
-
-\newline
-case 10: ...
-
-\newline
-case 11: ...
-
-\newline
-case 12:...
-
-\newline
-}
-\layout Standard
-
-then both the switch statements will be implemented using jump-tables whereas
- the unmodified switch statement will not be .
-\layout Subsection
-
-bit-shifting operations.
-\begin_inset LatexCommand \label{bit shifting}
-
-\end_inset
-
-
-\layout Standard
-
-Bit shifting is one of the most frequently used operation in embedded programmin
-g .
- SDCC tries to implement bit-shift operations in the most efficient way
- possible.
-\layout Standard
-
-eg.
-\layout Standard
-
-
-\size small
-unsigned short i;
-\layout Standard
-
-
-\size small
-...
-
-\newline
-i>>= 4;
-\newline
-..
-\layout Standard
-
-generates the following code.
-\layout Standard
-
-
-\size small
-mov a,_i
-\newline
-swap a
-\newline
-anl a,#0x0f
-\newline
-mov _i,a
-\layout Standard
-
-In general SDCC will never setup a loop if the shift count is known.
- Another example
-\layout Standard
-
-
-\size small
-unsigned int i;
-\newline
-...
-
-\newline
-i >>= 9;
-\newline
-...
-\layout Standard
-
-will generate
-\layout Standard
-
-
-\size small
-mov a,(_i + 1)
-\newline
-mov (_i + 1),#0x00
-\newline
-clr c
-\newline
-rrc a
-\newline
-mov _i,a
-\layout Standard
-
-Note that SDCC stores numbers in
-\noun on
-little-endian
-\noun default
-format (i.e.
- lowest order first)
-\layout Subsubsection
-
-Bit-rotation:
-\begin_inset LatexCommand \label{bit rotation}
-
-\end_inset
-
-
-\layout Standard
-
-A special case of the bit-shift operation is bit rotation, SDCC recognizes
- the following expression to be a left bit-rotation.
-\layout Standard
-
-
-\size small
-unsigned char i;
-\newline
-...
-
-\newline
-i = ( ( i << 1) | ( i >> 7));
-\newline
-...
-\layout Standard
-
-will generate the following code.
-\layout Standard
-
-
-\size small
-mov a,_i
-\newline
-rl a
-\newline
-mov _i,a
-\layout Standard
-
-SDCC uses pattern matching on the parse tree to determine this operation
- .Variations of this case will also be recognized as bit-rotation i.e
-\emph on
- i = ((i >> 7) | (i << 1));
-\emph default
-/* left-bit rotation */
-\layout Subsection
-
-Highest Order Bit.
-\begin_inset LatexCommand \label{Highest Order Bit}
-
-\end_inset
-
-
-\layout Standard
-
-It is frequently required to obtain the highest order bit of an integral
- type (int,long,short or char types).
- SDCC recognizes the following expression to yield the highest order bit
- and generates optimized code for it.
-\layout Standard
-
-
-\size small
-eg
-\newline
-unsigned int gint;
-\newline
-foo () {
-\newline
-unsigned char hob;
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-...
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-hob = (gint >> 15) & 1;
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-..
-
-\newline
-}
-\layout Standard
-
-Will generate the following code.
-\layout Standard
-
-
-\size small
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- 61 ;
-\protected_separator
- hob.c 7
-\newline
-
-\protected_separator
-
-\protected_separator
- 000A E5*01
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- 62
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- a,(_gint + 1)
-\newline
-
-\protected_separator
-
-\protected_separator
- 000C 33
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- 63
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- rlc
-\protected_separator
- a
-\newline
-
-\protected_separator
-
-\protected_separator
- 000D E4
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- 64
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- clr
-\protected_separator
- a
-\newline
-
-\protected_separator
-
-\protected_separator
- 000E 13
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- 65
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- rrc
-\protected_separator
- a
-\newline
-
-\protected_separator
-
-\protected_separator
- 000F F5*02
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- 66
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- _foo_hob_1_1,a
-\layout Standard
-
-Variations of this case however will NOT be recognized .
- It is a standard C expression , so I heartily recommend this be the only
- way to get the highest order bit, (it is portable).
- Of course it will be recognized even if it is embedded in other expressions.
-\layout Standard
-
-
-\size small
-eg.
-\layout Standard
-
-
-\size small
-xyz = gint + ((gint >> 15) & 1);
-\layout Standard
-
-will still be recognized.
-\layout Subsection
-
-Peep-hole optimizer.
-\begin_inset LatexCommand \label{Peep-Hole}
-
-\end_inset
-
-
-\layout Standard
-
-The compiler uses a rule based , pattern matching and re-writing mechanism
- for peep-hole optimization .
- It is inspired by '
-\emph on
-copt'
-\emph default
- a peep-hole optimizer by Christopher W.
- Fraser (cwfraser@microsoft.com).
- A default set of rules are compiled into the compiler, additional rules
- may be added with the --peep-file <filename> option.
- The rule language is best illustrated with examples.
-\layout Standard
-
-
-\size small
-replace {
-\newline
-mov %1,a
-\newline
-mov a,%1 } by { mov %1,a }
-\layout Standard
-
-The above rule will the following assembly sequence
-\layout Standard
-
-
-\size small
-mov r1,a
-\newline
-mov a,r1
-\layout Standard
-
-to
-\layout Standard
-
-
-\size small
-mov r1,a
-\layout Standard
-
-Note: All occurrences of a '%n' ( pattern variable ) must denote the same
- string.
- With the above rule, the assembly sequence
-\layout Standard
-
-
-\size small
-mov r1,a
-\newline
-mov a,r2
-\layout Standard
-
-will remain unmodified.
- Other special case optimizations may be added by the user (via --peep-file
- option), eg.
- some variants of the 8051 MCU allow only 'AJMP' and 'ACALL' , the following
- two rules will change all 'LJMP' & 'LCALL' to 'AJMP' & 'ACALL'.
-\layout Standard
-
-
-\size small
-replace { lcall %1 } by { acall %1 }
-\newline
-replace { ljmp %1 } by { ajmp %1 }
-\layout Standard
-
-The inline-assembler' code is also passed through the peep hole optimizer,
- thus the peephole optimizer can also be used as an assembly level macro
- expander.
- The rules themselves are MCU dependent whereas the rule language infra-structur
-e is MCU independent.
- Peephole optimization rules for other MCU can be easily programmed using
- the rule language.
-\layout Standard
-
-The syntax for a rule is as follows ,
-\layout Standard
-
-
-\size small
-rule := replace [ restart ] '{' <assembly sequence> '
-\backslash
-n'
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- '}' by '{' '
-\backslash
-n'
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- <assembly sequence> '
-\backslash
-n'
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- '}' [if <functionName> ] '
-\backslash
-n'
-\newline
-<assembly sequence> := assembly instruction (each instruction including
- labels must be on a separate line).
-\protected_separator
-
-\protected_separator
-
-\layout Standard
-
-The optimizer will apply to the rules one by one from the top in the sequence
- of their appearance, it will terminate when all rules are exhausted.
- If the '
-\emph on
-restart
-\emph default
-' option is specified, then the optimizer will start matching the rules
- again from the top, this option for a rule is expensive (performance),
- it is intended to be used in situations where a transformation will trigger
- the same rule again.
- A good example of this the following rule.
-\layout Standard
-
-
-\size small
-replace restart {
-\newline
-pop %1
-\newline
-push %1 } by {
-\newline
-; nop
-\newline
-}
-\layout Standard
-
-Note that the replace pattern cannot be a blank, but can be a comment line.
- Without the '
-\emph on
-restart
-\emph default
-' option only the inner most 'pop' 'push' pair would be eliminated.
- i.e.
-\layout Standard
-
-
-\size small
-pop ar1
-\newline
-pop ar2
-\newline
-push ar2
-\newline
-push ar1
-\layout Standard
-
-would result in
-\layout Standard
-
-
-\size small
-pop ar1
-\newline
-; nop
-\newline
-push ar1
-\layout Standard
-
-with the '
-\emph on
-restart
-\emph default
-' option the rule will be applied again to the resulting code and the all
- the '
-\emph on
-pop' 'push'
-\emph default
- pairs will be eliminated to yield
-\layout Standard
-
-
-\size small
-; nop
-\newline
-; nop
-\layout Standard
-
-A conditional function can be attached to a rule.
- Attaching rules are somewhat more involved, let me illustrate this with
- an example.
-\layout Standard
-
-
-\size small
-replace {
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-ljmp %5
-\newline
-%2:} by {
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-sjmp %5
-\newline
-%2:} if labelInRange
-\layout Standard
-
-The optimizer does a look-up of a function name table defined in function
- '
-\emph on
-callFuncByName'
-\emph default
- in the source file
-\emph on
-SDCCpeeph.c
-\emph default
- , with the name
-\emph on
-'labelInRange
-\emph default
-', if it finds a corresponding entry the function is called.
- Note there can be no parameters specified for these functions, in this
- case the use of
-\emph on
-'%5
-\emph default
-' is crucial, since the function
-\emph on
-labelInRange
-\emph default
- expects to find the label in that particular variable (the hash table containin
-g the variable bindings is passed as a parameter).
- If you want to code more such functions , take a close look at the function
-
-\emph on
-labelInRange
-\emph default
- and the calling mechanism in source file
-\emph on
-SDCCpeeph.c
-\emph default
-.
- I know this whole thing is a little kludgey , may be some day we will have
- some better means.
- If you are looking at this file, you will also see the default rules that
- are compiled into the compiler, you can your own rules in the default set
- there if you get tired of specifying the
-\emph on
---peep-file
-\emph default
- option.
-\layout Section
-
-Pointers
-\begin_inset LatexCommand \label{Pointers}
-
-\end_inset
-
-
-\layout Standard
-
-SDCC allows (via language extensions) pointers to explicitly point to any
- of the memory spaces of the 8051.
- In addition to the explicit pointers, the compiler also allows a
-\emph on
-_generic
-\emph default
- class of pointers which can be used to point to any of the memory spaces.
-
-\layout Standard
-
-Pointer declaration examples.
-\layout Standard
-
-
-\size small
-/* pointer physically in xternal ram pointing to object in internal ram
- */
-\newline
-data unsigned char * xdata p;
-\newline
-
-\layout Standard
-
-
-\size small
-/* pointer physically in code rom pointing to data in xdata space */
-\newline
-xdata unsigned char * code p;
-\newline
-
-\layout Standard
-
-
-\size small
-/* pointer physically in code space pointing to data in code space */
-\newline
-code unsigned char * code p;
-\newline
-
-\newline
-/* the folowing is a generic pointer physically located in xdata space */
-\newline
-char * xdata p;
-\layout Standard
-
-Well you get the idea.
- For compatibility with the previous version of the compiler, the following
- syntax for pointer declaration is also supported.
- Note the above examples will be portable to other commercially available
- compilers.
-\layout Standard
-
-
-\size small
-unsigned char _xdata *ucxdp; /* pointer to data in external ram */
-\newline
-unsigned char _data
-\protected_separator
-*ucdp ; /* pointer to data in internal ram */
-\newline
-unsigned char _code
-\protected_separator
-*uccp ; /* pointer to data in R/O code space */
-\newline
-unsigned char _idata *uccp;
-\protected_separator
-/* pointer to upper 128 bytes of ram */
-\layout Standard
-
-All unqualified pointers are treated as 3 - byte '_generic' pointers.
- These type of pointers can also to be explicitly declared.
-\layout Standard
-
-
-\size small
-unsigned char _generic *ucgp;
-\layout Standard
-
-The highest order byte of the generic pointers contains the data space informati
-on.
- Assembler support routines are called whenever data is stored or retrieved
- using _generic pointers.
- These are useful for developing reusable library routines.
- Explicitly specifying the pointer type will generate the most efficient
- code.
- Pointers declared using a mixture of OLD/NEW style could have unpredictable
- results.
-\layout Section
-
-Parameters & Local Variables
-\begin_inset LatexCommand \label{Auto Variables}
-
-\end_inset
-
-
-\layout Standard
-
-Automatic (local) variables and parameters to functions can either be placed
- on the stack or in data-space.
- The default action of the compiler is to place these variables in the internal
- RAM ( for small model) or external RAM (for Large model).
- They can be placed on the stack either by using the
-\emph on
- --stack-auto
-\emph default
- compiler option or by using the 'reentrant' keyword in the function declaration.
-\layout Standard
-
-
-\family typewriter
-\size scriptsize
-eg
-\layout Standard
-
-
-\size small
-unsigned short foo( short i) reentrant {
-\newline
-...
-
-\newline
-}
-\layout Standard
-
-Note that when the parameters & local variables are declared in the internal/ext
-ernal ram the functions are non-reentrant.
- Since stack space on 8051 is limited the
-\emph on
-'reentrant'
-\emph default
-keyword or the
-\emph on
- --stack-auto
-\emph default
- option should be used sparingly.
- Note the reentrant keyword just means that the parameters & local variables
- will be allocated to the stack, it DOES NOT mean that the function is register
- bank independent.
-\layout Standard
-
-When compiled with the default option (i.e.
- non-reentrant ), local variables can be assigned storage classes and absolute
- addresses.
-
-\layout Standard
-
-
-\family typewriter
-\size scriptsize
-eg
-\layout Standard
-
-
-\size small
-unsigned short foo() {
-\newline
-
-\protected_separator
-
-\protected_separator
-xdata unsigned short i;
-\newline
-
-\protected_separator
-
-\protected_separator
-bit bvar;
-\newline
-
-\protected_separator
-
-\protected_separator
-data at 0x31 unsiged short j;
-\newline
-...
-
-\newline
-}
-\layout Standard
-
-In the above example the variable
-\emph on
-i
-\emph default
- will be allocated in the external ram,
-\emph on
-bvar
-\emph default
- in bit addressable space and
-\emph on
- j
-\emph default
- in internal ram.
- When compiled with the
-\emph on
---stack-auto
-\emph default
- or when a function is declared as
-\emph on
-'reentrant'
-\emph default
- local variables cannot be assigned storage classes or absolute addresses.
-\layout Standard
-
-Parameters however are not allowed any storage class, (storage classes for
- parameters will be ignored), their allocation is governed by the memory
- model in use , and the reentrancy options.
-\layout Subsection
-
-Overlaying
-\begin_inset LatexCommand \label{Overlaying}
-
-\end_inset
-
-
-\layout Standard
-
-For non-reentrant functions SDCC will try to reduce internal ram space usage
- by overlaying parameters and local variables of a function (if possible).
- Parameters and local variables of a function will be allocated to an overlayabl
-e segment if the function has
-\emph on
-no other function calls and the function is non-reentrant and the memory
- model is small.
-
-\emph default
- If an explicit storage class is specified for a local variable , it will
- NOT be overplayed.
-\layout Standard
-
-Note that the compiler (not the linkage editor) makes the decision for overlayin
-g the data items.
- Functions that are called from an interrupt service routine should be preceded
- by a #pragma NOOVERLAY if they are not reentrant Along the same lines the
- compiler does not do any processing with the inline assembler code so the
- compiler might incorrectly assign local variables and parameters of a function
- into the overlay segment if the only function call from a function is from
- inline assembler code, it is safe to use the #pragma NOOVERLAY for functions
- which call other functions using inline assembler code.
-\layout Standard
-
-Parameters and Local variables of functions that contain 16 or 32 bit multiplica
-tion or division will NOT be overlayed since these are implemented using
- external functions.
-\layout Standard
-
-eg.
-\layout Standard
-
-
-\size small
-#pragma SAVE
-\newline
-#pragma NOOVERLAY
-\newline
-void set_error( unsigned short errcd)
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
- P3 = errcd;
-\newline
-}
-\newline
-#pragma RESTORE
-\newline
-void some_isr () interrupt 2 using 1
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
- ...
-
-\newline
-
-\protected_separator
-
-\protected_separator
- set_error(10);
-\newline
-
-\protected_separator
-
-\protected_separator
- ...
-
-\newline
-}
-\layout Standard
-
-In the above example the parameter
-\emph on
-errcd
-\emph default
- for the function
-\emph on
-set_error
-\emph default
- would be assigned to the overlayable segment (if the #pragma NOOVERLAY
- was not present) , this could cause unpredictable runtime behavior.
- The pragma NOOVERLAY ensures that the parameters and local variables for
- the function are NOT overlayed.
-\layout Section
-
-critical Functions.
-\begin_inset LatexCommand \label{Critical}
-
-\end_inset
-
-
-\layout Standard
-
-A special keyword may be associated with a function declaring it as '
-\emph on
-critical
-\emph default
-'.
- SDCC will generate code to disable all interrupts upon entry to a critical
- function and enable them back before returning .
- Note that nesting critical functions may cause unpredictable results.
-\layout Standard
-
-eg
-\layout Standard
-
-
-\size small
-int foo () critical
-\newline
-{
-\newline
-...
-
-\newline
-...
-
-\newline
-}
-\layout Standard
-
-The critical attribute maybe used with other attributes like
-\emph on
-reentrant.
-\layout Section
-
-Absolute addressing.
-\begin_inset LatexCommand \label{Absolute Addressing}
-
-\end_inset
-
-
-\layout Standard
-
-Data items can be assigned an absolute address with the
-\emph on
-at <address>
-\emph default
- keyword, in addition to a storage class.
-\layout Standard
-
-eg.
-
-\layout Standard
-
-
-\size small
-xdata at 0x8000 unsigned char PORTA_8255 ;
-\layout Standard
-
-In the above example the
-\emph on
-PORTA_8255
-\emph default
- will be allocated to the location 0x8000 of the external ram.
-
-\layout Standard
-
-Note that is this feature is provided to give the programmer access to
-\emph on
-memory mapped
-\emph default
- devices attached to the controller.
- The compiler does not actually reserve any space for variables declared
- in this way (they are implemented with an equate in the assembler), thus
- it is left to the programmer to make sure there are no overlaps with other
- variables that are declared without the absolute address, the assembler
- listing file (.lst) and the linker output files (<filename>.rst) and (<filename>.m
-ap) are a good places to look for such overlaps.
-\layout Standard
-
-Absolute address can be specified for variables in all storage classes.
-\layout Standard
-
-
-\size small
-eg.
-\layout Standard
-
-
-\size small
-bit at 0x02 bvar;
-\layout Standard
-
-The above example will allocate the variable at offset 0x02 in the bit-addressab
-le space.
- There is no real advantage to assigning absolute addresses to variables
- in this manner , unless you want strict control over all the variables
- allocated.
-\layout Section
-
-Interrupt Service Routines
-\begin_inset LatexCommand \label{Interrupt Service Rouines}
-
-\end_inset
-
-
-\layout Standard
-
-SDCC allows interrupt service routines to be coded in C, with some extended
- keywords.
-\layout Standard
-
-
-\size small
-void timer_isr (void) interrupt 2 using 1
-\newline
-{
-\newline
-..
-
-\newline
-}
-\layout Standard
-
-The number following the 'interrupt' keyword is the interrupt number this
- routine will service.
- The compiler will insert a call to this routine in the interrupt vector
- table for the interrupt number specified.
- The 'using' keyword is used to tell the compiler to use the specified register
- bank (8051 specific) when generating code for this function.
- Note that when some function is called from an interrupt service routine
- it should be preceded by a #pragma NOOVERLAY (if it is not reentrant) .
- A special note here, int (16 bit) and long (32 bit) integer division, multiplic
-ation & modulus operations are implemented using external support routines
- developed in ANSI-C, if an interrupt service routine needs to do any of
- these operations then the support routines (as mentioned in a following
- section) will have to recompiled using the --stack-auto option and the
- source file will need to be compiled using the --int-long-rent compiler
- option.
-\layout Standard
-
-If you have multiple source files in your project, interrupt service routines
- can be present in any of them, but a prototype of the isr MUST be present
- in the file that contains the function
-\emph on
-'main'
-\emph default
-.
-\layout Standard
-
-Interrupt Numbers and the corresponding address & descriptions for the Standard
- 8051 are listed below.
- SDCC will automatically adjust the interrupt vector table to the maximum
- interrupt number specified.
-\layout Standard
-
-Interrupt #
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-Description
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-Vector Address
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-0
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-External 0
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-0x0003
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-1
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-Timer 0
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-0x000B
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-2
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-External 1
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-0x0013
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-3
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-Timer 1
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-0x001B
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-4
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-Serial
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-0x0023
-\layout Standard
-
-If the interrupt service routine is defined without a register bank or with
- register bank 0 (using 0), the compiler will save the registers used by
- itself on the stack (upon entry and restore them at exit), however if such
- an interrupt service routine calls another function then the entire register
- bank will be saved on the stack.
- This scheme may be advantageous for small interrupt service routines which
- have low register usage.
-\layout Standard
-
-If the interrupt service routine is defined to be using a specific register
- bank then only
-\begin_inset Quotes eld
-\end_inset
-
-a
-\begin_inset Quotes erd
-\end_inset
-
-,
-\begin_inset Quotes erd
-\end_inset
-
-b
-\begin_inset Quotes erd
-\end_inset
-
- &
-\begin_inset Quotes eld
-\end_inset
-
-dptr
-\begin_inset Quotes erd
-\end_inset
-
- are save and restored, if such an interrupt service routine calls another
- function (using another register bank) then the entire register bank of
- the called function will be saved on the stack.
- This scheme is recommended for larger interrupt service routines.
-\layout Standard
-
-Calling other functions from an interrupt service routine is not recommended
- avoid it if possible.
-\layout Section
-
-Startup Code
-\begin_inset LatexCommand \label{Startup}
-
-\end_inset
-
-
-\layout Standard
-
-The compiler inserts a jump to the C routine
-\series bold
-_sdcc__external__startup()
-\series default
-at the start of the CODE area.
- This routine can be found in the file
-\series bold
-SDCCDIR/sdcc51lib/_startup.c
-\series default
- , by default this routine returns 0, if this routine returns a non-zero
- value , the static & global variable initialization will be skipped and
- the function main will be invoked, other wise static & global variables
- will be initialized before the function main is invoked.
-\layout Section
-
-Inline assembler code.
-\begin_inset LatexCommand \label{Inline}
-
-\end_inset
-
-
-\layout Standard
-
-SDCC allows the use of in-line assembler with a few restriction as regards
- labels.
- All labels defined within inline assembler code HAS TO BE of the
-\emph on
-form nnnnn$
-\emph default
- where nnnn is a number less than 100 (which implies a limit of utmost 100
- inline assembler labels
-\noun on
-per function)
-\noun default
-.
- It is strongly recommended that each assembly instruction (including labels)
- be placed in a separate line ( as the example shows).
- When the
-\series bold
-\bar under
---peep-asm
-\series default
-\bar default
- command line option is used, the inline assembler code will be passed through
- the peephole optimizer, this might cause some unexpected changes in the
- inline assembler code, please go throught the peephole optimizer rules
- defined in file 'SDCCpeeph.def' carefully before using this option.
-\layout Standard
-
-
-\size small
-eg
-\layout Standard
-
-
-\size small
-_asm
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-mov b,#10
-\newline
-00001$:
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-djnz b,00001$
-\newline
-_endasm ;
-\layout Standard
-
-The inline assembler code can contain any valid code understood by the assembler
- (this includes any assembler directives and comment lines ) .
- The compiler does not do any validation of the code within the
-\emph on
-_asm ...
- _endasm;
-\emph default
- keyword pair.
-
-\layout Standard
-
-Inline assembler code cannot reference any C-Labels however it can reference
- labels defined by the inline assembler.
-\layout Standard
-
-
-\size small
-eg
-\layout Standard
-
-
-\size small
-foo() {
-\newline
-...
- /* some c code */
-\newline
-_asm
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-; some assembler code
-\newline
-
-\protected_separator
-
-\protected_separator
- ljmp $0003
-\newline
-_endasm ;
-\newline
-...
- /* some more c code */
-\newline
-clabel:
-\protected_separator
- /* inline assembler cannot reference this label */
-\newline
-_asm
-\newline
-
-\protected_separator
-
-\protected_separator
-$0003: ;label (can be reference by inline assembler only)
-\newline
-_endasm ;
-\newline
-...
-
-\newline
-}
-\layout Standard
-
-In other words inline assembly code can access labels defined in inline
- assembly.
- The same goes the other way, ie.
- labels defines in inline assembly CANNOT be accessed by C statements.
-\layout Section
-
-int (16 bit) and long (32 bit ) support.
-\begin_inset LatexCommand \label{int and long}
-
-\end_inset
-
-
-\layout Standard
-
-For signed & unsigned int (16 bit) and long (32 bit) variables, division,
- multiplication and modulus operations are implemented by support routines.
- These support routines are all developed in ANSI-C to facilitate porting
- to other MCUs.
- The following files contain the described routine, all of them can be found
- in the directory SDCCDIR/sdcc51lib
-\layout Itemize
-
-
-\size footnotesize
-_mulsint.c - signed 16 bit multiplication (calls _muluint)
-\layout Itemize
-
-
-\size footnotesize
-_muluint.c - unsigned 16 bit multiplication
-\layout Itemize
-
-
-\size footnotesize
-_divsint.c - signed 16 bit division (calls _divuint)
-\layout Itemize
-
-
-\size footnotesize
-_divuint.c - unsigned 16 bit division.
-\layout Itemize
-
-
-\size footnotesize
-_modsint.c - signed 16 bit modulus (call _moduint)
-\layout Itemize
-
-
-\size footnotesize
-_moduint.c - unsigned 16 bit modulus.
-\layout Itemize
-
-
-\size footnotesize
-_mulslong.c - signed 32 bit multiplication (calls _mululong)
-\layout Itemize
-
-
-\size footnotesize
-_mululong.c - unsigned32 bit multiplication.
-\layout Itemize
-
-
-\size footnotesize
-_divslong.c - signed 32 division (calls _divulong)
-\layout Itemize
-
-
-\size footnotesize
-_divulong.c - unsigned 32 division.
-\layout Itemize
-
-
-\size footnotesize
-_modslong.c - signed 32 bit modulus (calls _modulong).
-\layout Itemize
-
-
-\size footnotesize
-_modulong.c - unsigned 32 bit modulus.
-\layout Standard
-
-All these routines are compiled as non-reentrant and small model.
- Since they are compiled as non-reentrant, interrupt service routines should
- not do any of the above operations, if this unavoidable then the above
- routines will need to ne compiled with the --stack-auto option, after which
- the source program will have to be compiled with --int-long-rent option.
-\layout Section
-
-Floating point support
-\begin_inset LatexCommand \label{Float}
-
-\end_inset
-
-
-\layout Standard
-
-SDCC supports IEEE (single precision 4bytes) floating point numbers.The floating
- point support routines are derived from gcc's floatlib.c and consists of
- the following routines.
-
-\layout Itemize
-
-
-\size footnotesize
-_fsadd.c - add floating point numbers.
-\layout Itemize
-
-
-\size footnotesize
-_fssub.c - subtract floating point numbers
-\layout Itemize
-
-
-\size footnotesize
-_fsdiv.c - divide floating point numbers
-\layout Itemize
-
-
-\size footnotesize
-_fsmul.c - multiply floating point numbers
-\layout Itemize
-
-
-\size footnotesize
-_fs2uchar.c - convert floating point to unsigned char
-\layout Itemize
-
-
-\size footnotesize
-_fs2char.c - convert floating point to signed char.
-\layout Itemize
-
-
-\size footnotesize
-_fs2uint.c - convert floating point to unsigned int.
-\layout Itemize
-
-
-\size footnotesize
-_fs2int.c - convert floating point to signed int.
-\layout Itemize
-
-
-\size footnotesize
-_fs2ulong.c - convert floating point to unsigned long.
-\layout Itemize
-
-
-\size footnotesize
-_fs2long.c - convert floating point to signed long.
-\layout Itemize
-
-
-\size footnotesize
-_uchar2fs.c - convert unsigned char to floating point
-\layout Itemize
-
-
-\size footnotesize
-_char2fs.c - convert char to floating point number
-\layout Itemize
-
-
-\size footnotesize
-_uint2fs.c - convert unsigned int to floating point
-\layout Itemize
-
-
-\size footnotesize
-_int2fs.c - convert int to floating point numbers
-\layout Itemize
-
-
-\size footnotesize
-_ulong2fs.c - convert unsigned long to floating point number
-\layout Itemize
-
-
-\size footnotesize
-_long2fs.c - convert long to floating point number.
-\layout Standard
-
-Note if all these routines are used simultaneously the data space might
- overflow.
- For serious floating point usage it is strongly recommended that the Large
- model be used (in which case the floating point routines mentioned above
- will need to recompiled with the --model-Large option)
-\layout Section
-
-Memory Models
-\begin_inset LatexCommand \label{Memory Models}
-
-\end_inset
-
-
-\layout Standard
-
-SDCC allows two memory models for MCS51 code.
- Modules compiled with different memory models should be combined together,
- the results would be unpredictable.
- The support routines supplied with the compiler are compiled in small-model
- by default, and will need to be recompiled using the large model if the
- large model is used.
- In general the use of the large model is discouraged.
-\layout Standard
-
-When the large model is used all variables declared without a storage class
- will be allocated into the external ram, this includes all parameters and
- local variables (for non-reentrant functions).
- When the small model is used variables without storage class are allocated
- in the internal ram.
-\layout Standard
-
-Judicious usage of the processor specific storage classes and the 'reentrant'
- function type will yield much more efficient code, than using the large-model.
- Several optimizations are disabled when the program is compiled using the
- large model, it is therefore strongly recommdended that the small model
- be used unless absolutely required.
-\layout Section
-
-Flat 24 bit addressing model.
-\begin_inset LatexCommand \label{--model-flat24}
-
-\end_inset
-
-
-\layout Standard
-
-This option generates code for the 24 bit contiguous addressing mode of
- the Dallas DS80C390 part.
- In this mode, up to four meg of external RAM or code space can be directly
- addressed.
- See the data sheets at www.dalsemi.com for further information on this part.
-\layout Standard
-
-In older versions of the compiler, this option was used with the MCS51 code
- generator (-mmcs51).
- Now, however, the '390 has it's own code generator, selected by the -mds390
- switch.
- This code generator currently supports only the flat24 model, but the --model-f
-lat24 switch is still required, in case later versions of the code generator
- support other models (such as the paged mode of the '390).
- The combination of -mmcs51 and --model-flat24 is now depracated.
-\layout Standard
-
-Note that the compiler does not generate any code to place the processor
- into24 bitmode (it defaults to 8051 compatible mode).
- Boot loader or similar code must ensure that the processor is in 24 bit
- contiguous addressing mode before calling the SDCC startup code.
-\layout Standard
-
-Like the --model-large option, variables will by default be placed into
- the XDATA segment.
-
-\layout Standard
-
-Segments may be placed anywhere in the 4 meg address space using the usual
- --*-loc options.
- Note that if any segments are located above 64K, the -r flag must be passed
- to the linker to generate the proper segment relocations, and the Intel
- HEX output format must be used.
- The -r flag can be passed to the linker by using the option -Wl-r on the
- sdcc command line.
-\layout Standard
-
---stack-10bit:
-\layout Standard
-
-This option generates code for the 10 bit stack mode of the Dallas DS80C390
- part.
- In this mode, the stack is located in the lower 1K of the internal RAM,
- which is mapped to 0x400000.
-\layout Standard
-
-With this option, sdcc will generate the proper addressing for stack variables.
-\layout Standard
-
-Note that the support is incomplete, since it still uses a single byte as
- the stack pointer.
- This means that only the lower 256 bytes of the potential 1K stack space
- can actually be used.
- However, this does allow you to reclaim the precious 256 bytes of low RAM
- for use for the DATA and IDATA segments.
-\layout Standard
-
-The compiler will not generate any code to put the processor into 10 bit
- stack mode.
- It is important to ensure that the processor is in this mode before calling
- any re-entrant functions compiled with this option.
-\layout Standard
-
-In principle, this should work with the --stack-auto option, but that has
- not been tested.
- It is incompatible with the --xstack option.
- It also only makes sense if the processor is in 24 bit contiguous addressing
- mode (see the --model-flat24 option).
-\layout Section
-
-Defines created by the compiler.
-\begin_inset LatexCommand \label{Defines.}
-
-\end_inset
-
-
-\layout Standard
-
-The compiler creates the following #defines .
-\layout Itemize
-
-SDCC - this Symbol is always defined.
-\layout Itemize
-
-SDCC_STACK_AUTO - this symbol is defined when --stack-auto option is used.
-\layout Itemize
-
-SDCC_MODEL_SMALL - when small model is used.
-\layout Itemize
-
-SDCC_MODEL_LARGE - when --model-large is used.
-\layout Itemize
-
-SDCC_USE_XSTACK - when --xstack option is used.
-\layout Section
-
-Pragmas
-\begin_inset LatexCommand \label{Pragmaa}
-
-\end_inset
-
-
-\layout Standard
-
-SDCC supports the following
-\emph on
-#pragma
-\emph default
-directives.
- This directives are applicable only at a function level.
-\layout Itemize
-
-
-\series bold
-SAVE
-\series default
-
-\begin_inset LatexCommand \label{pragma save}
-
-\end_inset
-
- - this will save all the current options .
-\layout Itemize
-
-
-\series bold
-RESTORE
-\series default
-
-\begin_inset LatexCommand \label{pragma restore}
-
-\end_inset
-
-- will restore the saved options from the last save.
- Note that SAVES & RESTOREs cannot be nested.
- SDCC uses the same buffer to save the options each time a SAVE is called.
-\layout Itemize
-
-
-\series bold
-NOGCSE
-\series default
-
-\begin_inset LatexCommand \label{pragma nogcse}
-
-\end_inset
-
- - will stop global subexpression elimination.
-\layout Itemize
-
-
-\series bold
-NOINDUCTION
-\series default
-
-\begin_inset LatexCommand \label{pragma noinduction}
-
-\end_inset
-
-- will stop loop induction optimizations .
-\layout Itemize
-
-
-\series bold
-NOJTBOUND
-\series default
-
-\begin_inset LatexCommand \label{pragma nojtbound}
-
-\end_inset
-
-- will not generate code for boundary value checking , when switch statements
- are turned into jump-tables.
-\layout Itemize
-
-
-\series bold
-NOOVERLAY
-\series default
-
-\begin_inset LatexCommand \label{pragma nooverlay}
-
-\end_inset
-
-- the compiler will not overlay the parameters and local variables of a
- function.
-\layout Itemize
-
-
-\series bold
-NOLOOPREVERSE
-\series default
-
-\begin_inset LatexCommand \label{pragma noloopreverse}
-
-\end_inset
-
-- Will not do loop reversal optimization
-\layout Itemize
-
-
-\series bold
-EXCLUDE NONE | {acc[,b[,dpl[,dph]]]
-\series default
-
-\begin_inset LatexCommand \label{pragma exclude}
-
-\end_inset
-
- - The exclude pragma disables generation of pair of push/pop instruction
- in ISR function (using interrupt keyword).
- The directive should be placed immediately before the ISR function definition
- and it affects ALL ISR functions following it.
- To enable the normal register saving for ISR functions use
-\begin_inset Quotes eld
-\end_inset
-
-#pragma EXCLUDE none
-\begin_inset Quotes erd
-\end_inset
-
-
-\layout Itemize
-
-
-\series bold
-CALLEE-SAVES function1[,function2[,function3...]]
-\series default
-
-\begin_inset LatexCommand \label{pragma callee-saves}
-
-\end_inset
-
- - The compiler by default uses a caller saves convention for register saving
- across function calls, however this can cause unneccessary register pushing
- & popping when calling small functions from larger functions.
- This option can be used to switch the register saving convention for the
- function names specified.
- The compiler will not save registers when calling these functions, extra
- code will be generated at the entry & exit for these functions to save
- & restore the registers used by these functions, this can SUBSTANTIALLY
- reduce code & improve run time performance of the generated code.
- In future the compiler (with interprocedural analysis) will be able to
- determine the appropriate scheme to use for each function call.
- If --callee-saves
-\begin_inset LatexCommand \ref{--callee-saves}
-
-\end_inset
-
- command line option is used, the function names specified in #pragma CALLEE-SAV
-ES is appended to the list of functions specified inthe command line.
-\layout Standard
-
-The pragma's are intended to be used to turn-off certain optimizations which
- might cause the compiler to generate extra stack / data space to store
- compiler generated temporary variables.
- This usually happens in large functions.
- Pragma directives should be used as shown in the following example, they
- are used to control options & optimizations for a given function; pragmas
- should be placed
-\noun on
-before
-\noun default
- and/or
-\noun on
-after
-\noun default
- a function, placing pragma's inside a function body could have unpredictable
- results.
-\layout Standard
-
-
-\size scriptsize
-eg
-\layout Standard
-
-
-\size scriptsize
-#pragma SAVE
-\protected_separator
- /* save the current settings */
-\newline
-#pragma NOGCSE /* turnoff global subexpression elimination */
-\newline
-#pragma NOINDUCTION /* turn off induction optimizations */
-\newline
-int foo ()
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
- ...
-
-\newline
-
-\protected_separator
-
-\protected_separator
- /* large code */
-\newline
-
-\protected_separator
-
-\protected_separator
- ...
-
-\newline
-}
-\newline
-#pragma RESTORE /* turn the optimizations back on */
-\layout Standard
-
-The compiler will generate a warning message when extra space is allocated.
- It is strongly recommended that the SAVE and RESTORE pragma's be used when
- changing options for a function.
-\layout Section
-
-Library routines.
-\begin_inset LatexCommand \label{Library}
-
-\end_inset
-
-
-\layout Standard
-
-The following library routines are provided for your convenience.
-\layout Standard
-
-
-\series bold
-\size large
-stdio.h
-\series default
-\size default
-- Contains the following functions printf & sprintf these routines are developed
- by
-\emph on
-Martijn van Balen <balen@natlab.research.philips.com>.
-
-\layout Standard
-
-
-\size scriptsize
-%[flags][width][b|B|l|L]type
-\layout Standard
-
-
-\size scriptsize
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- flags: -
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- left justify output in specified field width
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- +
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- prefix output with +/- sign if output is signed type
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- space
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- prefix output with a blank if it's a signed positive value
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- width:
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- specifies minimum number of characters outputted for numbers
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- or strings.
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- - For numbers, spaces are added on the left when needed.
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- If width starts with a zero character, zeroes and used
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- instead of spaces.
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- - For strings, spaces are are added on the left or right (when
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- flag '-' is used) when needed.
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- b/B:
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- byte argument (used by d, u, o, x, X)
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- l/L:
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- long argument (used by d, u, o, x, X)
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- type:
-\protected_separator
- d
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- decimal number
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- u
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- unsigned decimal number
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- o
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- unsigned octal number
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- x
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- unsigned hexadecimal number (0-9, a-f)
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- X
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- unsigned hexadecimal number (0-9, A-F)
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- c
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- character
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- s
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- string (generic pointer)
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- p
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- generic pointer (I:data/idata, C:code, X:xdata, P:paged)
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- f
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- float (still to be implemented)
-\layout Standard
-
-Also contains a very simple version of printf (
-\series bold
-printf_small
-\series default
-).
- This simplified version of printf supports only the following formats.
-\layout Standard
-
-
-\size scriptsize
-\bar under
-format
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-output
-\protected_separator
-type
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-argument-type
-\bar default
-
-\series bold
-\size default
-
-\newline
-
-\series default
-\size scriptsize
-%d
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-decimal
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- int
-\newline
-%ld
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-decimal
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-long
-\newline
-%hd
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-decimal
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-short/char
-\newline
-%x
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-hexadecimal
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-int
-\newline
-%lx
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-hexadecimal
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-long
-\newline
-%hx
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-hexadecimal
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-short/char
-\newline
-%o
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-octal
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-int
-\newline
-%lo
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-octal
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-long
-\newline
-%ho
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-octal
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-short/char
-\newline
-%c
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-character
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-char/short
-\newline
-%s
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-character
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-_generic pointer
-\layout Standard
-
-The routine is
-\series bold
-very stack intesive
-\series default
-, --stack-after-data parameter should be used when using this routine, the
- routine also takes about 1K of code space .It also expects an external function
- named
-\emph on
-putchar(char )
-\emph default
- to be present (this can be changed).
- When using the %s format the string / pointer should be cast to a generic
- pointer.
- eg.
-\layout Standard
-
-
-\size scriptsize
-printf_small(
-\begin_inset Quotes eld
-\end_inset
-
-my str %s, my int %d
-\backslash
-n
-\begin_inset Quotes erd
-\end_inset
-
-,(char _generic *)mystr,myint);
-\layout Itemize
-
-
-\series bold
-\size large
-stdarg.h
-\series default
-\size default
-- contains definition for the following macros to be used for variable parameter
- list, note that a function can have a variable parameter list if and only
- if it is 'reentrant'
-\begin_deeper
-\layout Standard
-
-
-\size small
-va_list, va_start, va_arg, va_end.
-\end_deeper
-\layout Itemize
-
-
-\series bold
-\size large
-setjmp.h
-\series default
-\size default
-- contains defintion for ANSI
-\series bold
- setjmp
-\series default
-&
-\series bold
-longjmp
-\series default
- routines.
- Note in this case setjmp & longjmp can be used between functions executing
- within the same register bank, if long jmp is executed from a function
- that is using a different register bank from the function issuing the setjmp
- function, the results may be unpredictable.
- The jump buffer requires 3 bytes of data (the stack pointer & a 16 byte
- return address), and can be placed in any address space.
-\layout Itemize
-
-
-\series bold
-\size large
-stdlib.h
-\series default
-\size default
- - contains the following functions.
-\begin_deeper
-\layout Standard
-
-
-\size footnotesize
-atoi, atol.
-\end_deeper
-\layout Itemize
-
-
-\series bold
-\size large
-string.h
-\series default
-\size default
-- contains the following functions.
-\begin_deeper
-\layout Standard
-
-
-\size footnotesize
-strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr, strspn,
- strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp, memset.
-\end_deeper
-\layout Itemize
-
-
-\series bold
-\size large
-ctype.h
-\series default
-\size default
- - contains the following routines.
-\begin_deeper
-\layout Standard
-
-
-\size footnotesize
-iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace,
- isxdigit, isalnum, isalpha.
-\end_deeper
-\layout Itemize
-
-
-\series bold
-\size large
-malloc.h
-\series default
-\size default
- - The malloc routines are developed by Dmitry S.
- Obukhov (dso@usa.net).
- These routines will allocate memory from the external ram.
- Here is a description on how to use them (as described by the author).
-\begin_deeper
-\layout Standard
-
-
-\size scriptsize
-//Example:
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- #define DYNAMIC_MEMORY_SIZE 0x2000
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .....
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- unsigned char xdata * current_buffer;
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .....
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- void main(void)
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- {
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- ...
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-//
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE);
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //Now it's possible to use malloc.
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- ...
-
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- current_buffer = malloc(0x100);
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- //
-\end_deeper
-\layout Itemize
-
-
-\series bold
-\size large
-serial.h
-\series default
-\size default
- - Serial IO routines are also developed by Dmitry S.
- Obukhov (dso@usa.net).
- These routines are interrupt driven with a 256 byte circular buffer, they
- also expect external ram to be present.
- Please see documentation in file SDCCDIR/sdcc51lib/serial.c .
- Note the header file
-\begin_inset Quotes eld
-\end_inset
-
-serial.h
-\begin_inset Quotes erd
-\end_inset
-
- MUST be included in the file containing the 'main' function.
-\layout Itemize
-
-
-\series bold
-\size large
-ser.h
-\series default
-\size default
-- Alternate serial routine provided by Wolfgang Esslinger <wolfgang@WiredMinds.co
-m> these routines are more compact and faster.
- Please see documentation in file SDCCDIR/sdcc51lib/ser.c
-\layout Itemize
-
-
-\series bold
-\size large
-ser_ir.h
-\series default
-\size default
-- Another alternate set of serial routines provided by Josef Wolf <jw@raven.inka.d
-e> , these routines do not use the external ram.
-\layout Itemize
-
-
-\series bold
-\size large
-reg51.h
-\series default
-\size default
- - contains register definitions for a standard 8051
-\layout Itemize
-
-
-\series bold
-\size large
-reg552.h
-\series default
-\size default
-- contains register definitions for 80C552.
-\layout Itemize
-
-
-\series bold
-\size large
-float.h
-\series default
-\size default
- - contains min, max and other floating point related stuff.
-\layout Standard
-
-All library routines are compiled as --model-small , they are all non-reentrant,
- if you plan to use the large model or want to make these routines reentrant,
- then they will have to be recompiled with the appropriate compiler option.
-\layout Standard
-
-Have not had time to do the more involved routines like printf, will get
- to them shortly.
-\layout Section
-
-Interfacing with assembly routines.
-\begin_inset LatexCommand \label{Interface_asm}
-
-\end_inset
-
-
-\layout Subsection
-
-Global registers used for parameter passing.
-\layout Standard
-
-By default the compiler uses the global registers
-\begin_inset Quotes eld
-\end_inset
-
-DPL,DPH,B,ACC
-\begin_inset Quotes erd
-\end_inset
-
- to pass the first parameter to a routine, the second parameter onwards
- is either allocated on the stack (for reentrant routines or --stack-auto
- is used) or in the internal / external ram (depending on the memory model).
-
-\layout Subsubsection
-
-Assembler routine non-reentrant
-\layout Standard
-
-In the following example the function
-\series bold
- cfunc
-\series default
- calls an assembler routine
-\series bold
-asm_func
-\series default
-, which takes two parameters.
-\layout Standard
-
-
-\size footnotesize
-extern int asm_func( unsigned short, unsigned short);
-\layout Standard
-
-
-\size footnotesize
-
-\protected_separator
-
-\newline
-int c_func (unsigned short i, unsigned short j)
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- return asm_func(i,j);
-\newline
-}
-\size default
-
-\size scriptsize
-
-\newline
-int main()
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-return c_func(10,9);
-\newline
-}
-\layout Standard
-
-The corresponding assembler function is:-
-\layout Standard
-
-
-\size scriptsize
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .globl _asm_func_PARM_2
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .globl _asm_func
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .area OSEG
-\newline
-_asm_func_PARM_2:
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .ds
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- 1
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .area CSEG
-\newline
-_asm_func:
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- a,dpl
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- add
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- a,_asm_func_PARM_2
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- dpl,a
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- dpl,#0x00
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- ret
-\layout Standard
-
-Note here that the return values are placed in 'dpl' - One byte return value,
- 'dpl' LSB & 'dph' MSB for two byte values.
- 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
-b' & 'acc' for four byte values.
-\layout Standard
-
-The parameter naming convention is
-\series bold
-_<function_name>_PARM_<n>,
-\series default
- where n is the parameter number starting from 1, and counting from the
- left.
- The first parameter is passed in
-\begin_inset Quotes eld
-\end_inset
-
-dpl
-\begin_inset Quotes erd
-\end_inset
-
- for One bye parameter,
-\begin_inset Quotes eld
-\end_inset
-
-dptr
-\begin_inset Quotes erd
-\end_inset
-
- if two bytes,
-\begin_inset Quotes eld
-\end_inset
-
-b,dptr
-\begin_inset Quotes erd
-\end_inset
-
- for three bytes and
-\begin_inset Quotes eld
-\end_inset
-
-acc,b,dptr
-\begin_inset Quotes erd
-\end_inset
-
- for four bytes, the
-\family typewriter
-\series bold
-\size footnotesize
-varaible name for the second parameter will be _<function_name>_PARM_2.
-\layout Standard
-
-Assemble the assembler routine with the following command.
-\layout Standard
-
-asx8051 -losg asmfunc.asm
-\layout Standard
-
-Then compile and link the assembler routine to the C source file with the
- following command,
-\layout Standard
-
-sdcc cfunc.c asmfunc.rel
-\layout Subsubsection
-
-Assembler routine is reentrant
-\layout Standard
-
-In this case the second parameter onwards will be passed on the stack ,
- the parameters are pushed from right to left i.e.
- after the call the left most parameter will be on the top of the stack.
- Here is an example.
-\layout Standard
-
-
-\size footnotesize
-extern int asm_func( unsigned short, unsigned short);
-\layout Standard
-
-
-\size footnotesize
-
-\protected_separator
-
-\layout Standard
-
-
-\size footnotesize
-int c_func (unsigned short i, unsigned short j) reentrant
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- return asm_func(i,j);
-\newline
-}
-\size default
-
-\size scriptsize
-
-\newline
-int main()
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-return c_func(10,9);
-\newline
-}
-\layout Standard
-
-The corresponding assembler routine is.
-\layout Standard
-
-
-\size scriptsize
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .globl _asm_func
-\newline
-_asm_func:
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- push
-\protected_separator
- _bp
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- _bp,sp
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-mov
-\protected_separator
- r2,dpl
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- a,_bp
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- clr
-\protected_separator
- c
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- add
-\protected_separator
- a,#0xfd
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- r0,a
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- add
-\protected_separator
- a,#0xfc
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- r1,a
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- a,@r0
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- add
-\protected_separator
- a,r2
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- dpl,a
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- dph,#0x00
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
- sp,_bp
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- pop
-\protected_separator
- _bp
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- ret
-\layout Standard
-
-The compiling and linking procedure remains the same, however note the extra
- entry & exit linkage required for the assembler code, _bp is the stack
- frame pointer and is used to compute the offset into the stack for parameters
- and local variables.
-\layout Subsection
-
-With --noregparms option.
-\layout Standard
-
-When the source is compiled with --noregparms option , space is allocated
- for each of the parameters passed to a routine.
-\layout Subsubsection
-
-Assembler routine non-reentrant.
-\layout Standard
-
-In the following example the function
-\series bold
- cfunc
-\series default
- calls an assembler routine
-\series bold
-asm_func
-\series default
-, which takes two parameters.
-\layout Standard
-
-
-\size footnotesize
-extern int asm_func( unsigned short, unsigned short);
-\layout Standard
-
-
-\size footnotesize
-
-\protected_separator
-
-\newline
-int c_func (unsigned short i, unsigned short j)
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- return asm_func(i,j);
-\newline
-}
-\size default
-
-\size scriptsize
-
-\newline
-int main()
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-return c_func(10,9);
-\newline
-}
-\layout Standard
-
-The corresponding assembler function is:-
-\layout Standard
-
-
-\size scriptsize
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .globl _asm_func_PARM_1
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .globl _asm_func_PARM_2
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .globl _asm_func
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .area OSEG
-\newline
-_asm_func_PARM_1:
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .ds
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- 1
-\newline
-_asm_func_PARM_2:
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .ds
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- 1
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- .area CSEG
-\newline
-_asm_func:
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- a,_asm_func_PARM_1
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- add
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- a,_asm_func_PARM_2
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- dpl,a
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- mov
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- dpl,#0x00
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- ret
-\layout Standard
-
-Note here that the return values are placed in 'dpl' - One byte return value,
- 'dpl' LSB & 'dph' MSB for two byte values.
- 'dpl', 'dph' and 'b' for three byte values (generic pointers) and 'dpl','dph','
-b' & 'acc' for four byte values.
-\layout Standard
-
-The parameter naming convention is
-\series bold
-_<function_name>_PARM_<n>,
-\series default
- where n is the parameter number starting from 1, and counting from the
- left.
- i.e.
- the
-\family typewriter
-\series bold
-\size footnotesize
-left-most parameter name will be _<function_name>_PARM_1.
-\layout Standard
-
-Assemble the assembler routine with the following command.
-\layout Standard
-
-asx8051 -losg asmfunc.asm
-\layout Standard
-
-Then compile and link the assembler routine to the C source file with the
- following command,
-\layout Standard
-
-sdcc cfunc.c asmfunc.rel
-\layout Subsubsection
-
-Assembler routine is reentrant.
-\layout Standard
-
-In this case the parameters will be passed on the stack , the parameters
- are pushed from right to left i.e.
- after the call the left most parameter will be on the top of the stack.
- Here is an example.
-\layout Standard
-
-
-\size footnotesize
-extern int asm_func( unsigned short, unsigned short);
-\layout Standard
-
-
-\size footnotesize
-
-\protected_separator
-
-\layout Standard
-
-
-\size footnotesize
-int c_func (unsigned short i, unsigned short j) reentrant
-\newline
-{
-\newline
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
-
-\protected_separator
- return asm_func(i,j);
-\newline
-}