X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=doc%2Fsdccman.lyx;h=22df670dd1190325b5c300d7db82f1ac34e9d581;hb=5be90381bf67a833edd640da0d67400b3bb0f111;hp=5de6d9ab25cc0c37dede40373f0a09f402626e9c;hpb=b82a3d6dd4652d636f800bbc6d65c8497c75b49b;p=fw%2Fsdcc diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index 5de6d9ab..22df670d 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -82,7 +82,7 @@ SDCC Compiler User Guide \size normal -SDCC 2.5.1 +SDCC 2.5.4 \size footnotesize \newline @@ -245,6 +245,7 @@ status Collapsed \newline SDCC also comes with a companion source level debugger SDCDB, the debugger currently uses ucSim a freeware simulator for 8051 and other micro-controllers. + SDCDB and ucSim are currently not available on Win32 platforms. \newline @@ -557,8 +558,8 @@ char KernelFunction3(char p) at 0x340; \family typewriter -code banking -\begin_inset LatexCommand \index{code banking (not supported)} +better code banking +\begin_inset LatexCommand \index{code banking (limited support)} \end_inset @@ -3268,8 +3269,10 @@ bin before running SDCC. \newline WARNING: Visual studio is very picky with line terminations; it expects the 0x0d, 0x0a DOS style line endings, not the 0x0a Unix style line endings. - If you are getting a message such as "This makefile was not generated by - Developer Studio etc. + When using the CVS repository it's easiest to configure the cvs client + to convert automatically for you. + If however you are getting a message such as "This makefile was not generated + by Developer Studio etc. etc. \begin_inset Quotes srd \end_inset @@ -4118,9 +4121,11 @@ link-gbz80 - The Z80 and GameBoy Z80 linkers. \layout Itemize s51 - The ucSim 8051 simulator. + Not available on Win32 platforms. \layout Itemize sdcdb - The source debugger. + Not available on Win32 platforms. \layout Itemize packihx - A tool to pack (compress) Intel hex files. @@ -4204,6 +4209,7 @@ S51 . It currently supports the core mcs51, the Dallas DS80C390 and the Phillips XA51 family. + S51 is currently not available on Win32 platfors. \layout Subsection sdcdb - Source Level Debugger @@ -4227,7 +4233,7 @@ Sdcdb \end_inset , but can be easily changed to use other simulators. - + Sdcdb is currently not available on Win32 platfors. \layout Chapter Using SDCC @@ -6043,6 +6049,33 @@ Generate code for Small Model programs, see section Memory Models for more \labelwidthstring 00.00.0000 +\series bold +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-model-medium +\begin_inset LatexCommand \index{-\/-model-medium} + +\end_inset + + +\series default + Generate code for Medium model programs, see section Memory Models for + more details. + If this option is used all source files in the project have to be compiled + with this option. + It must also be used when invoking the linker. +\layout List +\labelwidthstring 00.00.0000 + + \series bold - \begin_inset ERT @@ -6065,6 +6098,7 @@ status Collapsed details. If this option is used all source files in the project have to be compiled with this option. + It must also be used when invoking the linker. \layout List \labelwidthstring 00.00.0000 @@ -7796,6 +7830,74 @@ status Collapsed \labelwidthstring 00.00.0000 +\series bold +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-codeseg +\series default + +\begin_inset LatexCommand \index{-\/-codeseg } + +\end_inset + +\SpecialChar ~ + The name to be used for the code +\begin_inset LatexCommand \index{code} + +\end_inset + + segment, default CSEG. + This is useful if you need to tell the compiler to put the code in a special + segment so you can later on tell the linker to put this segment in a special + place in memory. + Can be used for instance when using bank switching to put the code in a + bank. +\layout List +\labelwidthstring 00.00.0000 + + +\series bold +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-constseg +\series default + +\begin_inset LatexCommand \index{-\/-constseg } + +\end_inset + +\SpecialChar ~ + The name to be used for the const +\begin_inset LatexCommand \index{code} + +\end_inset + + segment, default CONST. + This is useful if you need to tell the compiler to put the const data in + a special segment so you can later on tell the linker to put this segment + in a special place in memory. + Can be used for instance when using bank switching to put the const data + in a bank. +\layout List +\labelwidthstring 00.00.0000 + + \series bold more-pedantic \series default @@ -8699,6 +8801,11 @@ Paged xdata access is just as straightforward as using the other addressing \end_inset ). + This is the +\series bold +default +\series default + storage class for the Medium Memory model, e.g.: \layout Verse @@ -10331,6 +10438,13 @@ Parameters , (storage classes for parameters will be ignored), their allocation is governed by the memory model in use, and the reentrancy options. +\layout Standard + +It is however allowed to use bit parameters in reentrant functions and also + non-static local bit variables are supported. + Efficient use is limited to 8 semi-bitregisters in bit space. + They are pushed and popped to stack as a single byte just like the normal + registers. \layout Section Overlaying @@ -14653,12 +14767,12 @@ MCS51 Memory Models \layout Subsubsection -Small and Large +Small, Medium and Large \layout Standard -SDCC allows two memory models for MCS51 code, +SDCC allows three memory models for MCS51 code, \shape slanted -small +small, medium \shape default and \shape slanted @@ -14670,16 +14784,15 @@ large never \emph default be combined together or the results would be unpredictable. - The library routines supplied with the compiler are compiled as both small - and large. - The compiled library modules are contained in separate directories as small - and large so that you can link to either set. - + The library routines supplied with the compiler are compiled as small, + medium and large. + The compiled library modules are contained in separate directories as small, + medium and large so that you can link to the appropriate set. \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 +When the medium or 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 \begin_inset LatexCommand \index{reentrant} \end_inset @@ -15217,6 +15330,24 @@ std_c99 - Follow the C99 standard and disable SDCC features that conflict with the standard (incomplete support). +\layout Itemize + +codeseg +\begin_inset LatexCommand \index{\#pragma codeseg} + +\end_inset + +- Use this name (max. + 8 characters) for the code segment. +\layout Itemize + +constseg +\begin_inset LatexCommand \index{\#pragma constseg} + +\end_inset + +- Use this name (max. + 8 characters) for the const segment. \layout Standard SDCPP supports the following #pragma directives: @@ -15329,7 +15460,7 @@ The compiler creates the following #defines \begin_inset Tabular - + @@ -15530,6 +15661,43 @@ status Collapsed \layout Standard +SDCC_MODEL_MEDIUM +\begin_inset LatexCommand \index{SDCC\_MODEL\_MEDIUM} + +\end_inset + + +\end_inset + + +\begin_inset Text + +\layout Standard + +when +\emph on +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-model-medium +\emph default + is used +\end_inset + + + + +\begin_inset Text + +\layout Standard + SDCC_MODEL_LARGE \begin_inset LatexCommand \index{SDCC\_MODEL\_LARGE} @@ -16007,7 +16175,7 @@ $(PRJ).hex: $(OBJS) \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) +gplink -m -s $(PRJ).lkr -o $(PRJ).hex $(OBJS) libsdcc.lib \layout Standard Here is a @@ -16053,7 +16221,7 @@ $(PRJ).hex: $(OBJS) \SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) +mplink /v $(PRJ).lkr /m $(PRJ).map /o $(PRJ).hex $(OBJS) libsdcc.lib \layout Standard Please note that indentations within a @@ -16061,6 +16229,131 @@ Please note that indentations within a Makefile \family default have to be done with a tabulator character. +\layout Subsection + +Command-line options +\layout Standard + +Besides the switches common to all SDCC backends, the PIC14 port accepts + the following options (for an updated list see sdcc - +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-help): +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-debug-extra emit debug info in assembly output +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-no-pcode-opt disable (slightly faulty) optimization on pCode +\layout Subsection + +The library +\layout Subsubsection + +error: missing definition for symbol +\begin_inset Quotes sld +\end_inset + +__gptrget1 +\begin_inset Quotes srd +\end_inset + + +\layout Standard + +The PIC14 port uses library routines to provide more complex operations + like multiplication, division/modulus and (generic) pointer dereferencing. + In order to add these routines to your project, you must link with PIC14's + +\family typewriter +libsdcc.lib +\family default +. + For single source file projects this is done automatically, more complex + projects must add +\family typewriter +libsdcc.lib +\family default + to the linker's arguments. + Make sure you also add an include path for the library (using the -I switch + to the linker)! +\layout Subsubsection + +Processor mismatch in file +\begin_inset Quotes sld +\end_inset + +XXX +\begin_inset Quotes srd +\end_inset + +. +\layout Standard + +This warning can usually be ignored due to the very good compatibility amongst + 14 bit PIC devices. +\layout Standard + +You might also consider recompiling the library for your specific device + by changing the ARCH=p16f877 (default target) entry in +\family typewriter +device/lib/pic/Makefile.in +\family default + and +\family typewriter +device/lib/pic/Makefile +\family default + to reflect your device. + This might even improve performance for smaller devices as unneccesary + BANKSELs migth be removed. +\layout Subsection + +Known bugs +\layout Subsubsection + +initialized data +\layout Standard + +Currently, data can only be initialized if it resides in the source file + together with +\emph on +main() +\emph default +. + Data in other source files will silently +\series bold +not +\series default + be initialized. \layout Section The PIC16 @@ -16536,6 +16829,20 @@ status Collapsed / \end_inset +-optimize-df Analyze the dataflow of the generated code and improve it. +\layout List +\labelwidthstring 00.00.0000 + +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + -obanksel=nn Set optimization level for inserting BANKSELs. \newline @@ -19751,7 +20058,7 @@ on, which also builds and installs the debugger in the target directory specified during configuration. The debugger allows you debug BOTH at the C source and at the ASM source level. - Sdcdb is available on Unix platforms only. + Sdcdb is currently not available on Win32 platforms. \layout Section Compiling for Debugging @@ -20069,84 +20376,49 @@ quit \layout Section Interfacing with DDD +\layout Comment + +The screenshot was converted from png to eps with: +\begin_inset Quotes sld +\end_inset + +bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps +\begin_inset Quotes srd +\end_inset + + which produces a pretty compact eps file which is free from compression + artifacts. +\layout Comment + +The screenshot was included in sdccman.lyx cvs version 1.120 but later removed + as this broke the build system on Sourceforge (pdf-file was broken). \layout Standard -Figure -\begin_inset LatexCommand \ref{fig:ddd_screenshot} +The .eps File +\size footnotesize + +\begin_inset LatexCommand \url{http://cvs.sourceforge.net/viewcvs.py/*checkout*/sdcc/sdcc/doc/figures/ddd_example.eps} \end_inset - shows a debugging session with DDD + +\size default + shows a screenshot of a debugging session with DDD \begin_inset LatexCommand \index{DDD (debugger)} \end_inset (Unix only) on a simulated 8032. + The debugging session might not run as smoothly as the screenshot suggests. The debugger allows setting of breakpoints, displaying and changing variables, single stepping through C and assembler code. -\layout Standard - - -\begin_inset Note -collapsed false +\newline +The source was compiled with +\family sans +\series bold -\layout Standard - -The screenshot was converted from png to eps with: -\layout Standard - -bmeps -c -e8f -p3 ddd_example.png >ddd_example.eps -\layout Standard - -Which produces a pretty compact eps file which is free from compression - artifacts. - -\end_inset - - -\layout Standard - - -\begin_inset Float figure -placement htbp -wide false -collapsed false - -\layout Standard -\align center - -\begin_inset Graphics - filename figures/ddd_example.eps - display color - width 100text% - rotateOrigin center - -\end_inset - - -\layout Caption - - -\begin_inset LatexCommand \label{fig:ddd_screenshot} - -\end_inset - -Debugging session with DDD on a simulated 8032. - Debugging might not run as smoothly as the screenshot suggests -. -\end_inset - - -\layout Standard - -Insiders familiar with the gdb commands (previous section) can enter them - in the lowermost frame of the screenshot. - The source was compiled with -\family sans -\series bold - -\newline +\newline \newline sdcc - @@ -24402,6 +24674,11 @@ so little-endian is the more efficient byte order. Highest Order Bit \begin_inset LatexCommand \index{Highest Order Bit} +\end_inset + + / Any Order Bit +\begin_inset LatexCommand \index{Any Order Bit} + \end_inset @@ -24409,7 +24686,8 @@ Highest Order Bit It is frequently required to obtain the highest order bit of an integral type (long, int, short or char types). - SDCC recognizes the following expression to yield the highest order bit + Also obtaining any other order bit is not uncommon. + SDCC recognizes the following expressions to yield the highest order bit and generates optimized code for it, e.g.: \layout Verse @@ -24423,7 +24701,11 @@ foo () { \newline \SpecialChar ~ \SpecialChar ~ -unsigned char hob; +unsigned char hob1, aob1; +\newline +\SpecialChar ~ +\SpecialChar ~ +bit hob2, hob3, aob2, aob3; \newline \SpecialChar ~ \SpecialChar ~ @@ -24432,7 +24714,27 @@ unsigned char hob; \newline \SpecialChar ~ \SpecialChar ~ -hob = (gint >> 15) & 1; +hob1 = (gint >> 15) & 1; +\newline +\SpecialChar ~ +\SpecialChar ~ +hob2 = (gint >> 15) & 1; +\newline +\SpecialChar ~ +\SpecialChar ~ +hob3 = gint & 0x8000; +\newline +\SpecialChar ~ +\SpecialChar ~ +aob1 = (gint >> 9) & 1; +\newline +\SpecialChar ~ +\SpecialChar ~ +aob2 = (gint >> 8) & 1; +\newline +\SpecialChar ~ +\SpecialChar ~ +aob3 = gint & 0x0800; \newline \SpecialChar ~ \SpecialChar ~ @@ -24585,125 +24887,1029 @@ will generate the following code: \SpecialChar ~ mov\SpecialChar ~ \SpecialChar ~ - _foo_hob_1_1,a -\layout Standard - -Variations of this case however will -\emph on -not -\emph default - 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, - e.g.: -\layout Verse - - -\family typewriter -xyz = gint + ((gint >> 15) & 1); -\layout Standard - -will still be recognized. -\layout Subsection - -Peephole Optimizer -\begin_inset LatexCommand \label{sub:Peephole-Optimizer} - -\end_inset - - -\begin_inset LatexCommand \index{Peephole optimizer} - -\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\SpecialChar ~ -@\SpecialChar ~ -microsoft.com). - A default set of rules are compiled into the compiler, additional rules - may be added with the -\emph on -- -\begin_inset ERT -status Collapsed - -\layout Standard - -\backslash -/ -\end_inset - --peep-file -\begin_inset LatexCommand \index{-\/-peep-file} - -\end_inset - - -\emph default - option. - The rule language is best illustrated with examples. -\layout Verse - - -\family typewriter -replace { + _foo_hob1_1_1,a \newline \SpecialChar ~ \SpecialChar ~ -mov %1,a -\newline \SpecialChar ~ \SpecialChar ~ -mov a,%1 +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 66 ;\SpecialChar ~ + hob.c 8 \newline -} by { +0011 E5*01\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 67\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + a,(_gint + 1) \newline +0013 33\SpecialChar ~ \SpecialChar ~ \SpecialChar ~ -mov %1,a +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 68\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + rlc\SpecialChar ~ +\SpecialChar ~ + a \newline -} -\layout Standard - -The above rule will change the following assembly -\begin_inset LatexCommand \index{Assembler routines} - -\end_inset - - sequence: -\layout Verse - - -\family typewriter -mov r1,a +0014 92*00\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 69\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + _foo_hob2_1_1,c \newline -mov a,r1 -\layout Standard - -to -\layout Verse - - -\family typewriter -mov r1,a -\layout Standard - -Note: All occurrences of a -\emph on -%n -\emph default - (pattern variable) must denote the same string. - With the above rule, the assembly sequence: +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 66 ;\SpecialChar ~ + hob.c 9 +\newline +0016 E5*01\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 67\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + a,(_gint + 1) +\newline +0018 33\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 68\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + rlc\SpecialChar ~ +\SpecialChar ~ + a +\newline +0019 92*01\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 69\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + _foo_hob3_1_1,c +\newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 70 ;\SpecialChar ~ + hob.c 10 +\newline +001B E5*01\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 71\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + a,(_gint + 1) +\newline +001D 03\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 72\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + rr\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + a +\newline +001E 54 01\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 73\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + anl\SpecialChar ~ +\SpecialChar ~ + a,#0x01 +\newline +0020 F5*03\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 74\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + _foo_aob1_1_1,a +\newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 75 ;\SpecialChar ~ + hob.c 11 +\newline +0022 E5*01\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 76\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + a,(_gint + 1) +\newline +0024 13\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 77\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + rrc\SpecialChar ~ +\SpecialChar ~ + a +\newline +0025 92*02\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 78\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + _foo_aob2_1_1,c +\newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 79 ;\SpecialChar ~ + hob.c 12 +\newline +0027 E5*01\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 80\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + a,(_gint + 1) +\newline +0029 A2 E3\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 81\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + c,acc[3] +\newline +002B 92*03\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 82\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + _foo_aob3_1_1,c +\layout Standard + +Other variations of these cases however will +\emph on +not +\emph default + be recognized. + They are standard C expressions, so I heartily recommend these be the only + way to get the highest order bit, (it is portable). + Of course it will be recognized even if it is embedded in other expressions, + e.g.: +\layout Verse + + +\family typewriter +xyz = gint + ((gint >> 15) & 1); +\layout Standard + +will still be recognized. +\layout Subsection + +Higher Order Byte +\begin_inset LatexCommand \index{Higher Order Byte} + +\end_inset + + / Higher Order Word +\begin_inset LatexCommand \index{Higher Order Word} + +\end_inset + + +\layout Standard + +It is also frequently required to obtain a higher order byte or word of + a larger integral type (long, int or short types). + SDCC recognizes the following expressions to yield the higher order byte + or word and generates optimized code for it, e.g.: +\layout Verse + + +\family typewriter +unsigned int gint; +\newline +unsigned long int glong; +\newline + +\newline +foo () { +\newline +\SpecialChar ~ +\SpecialChar ~ +unsigned char hob1, hob2; +\newline +\SpecialChar ~ +\SpecialChar ~ +unsigned int how1, how2; +\newline +\SpecialChar ~ +\SpecialChar ~ +... + +\newline +\SpecialChar ~ +\SpecialChar ~ +hob1 = (gint >> 8) & 0xFF; +\newline +\SpecialChar ~ +\SpecialChar ~ +hob2 = glong >> 24; +\newline +\SpecialChar ~ +\SpecialChar ~ +how1 = (glong >> 16) & 0xFFFF; +\newline +\SpecialChar ~ +\SpecialChar ~ +how2 = glong >> 8; +\newline +\SpecialChar ~ +\SpecialChar ~ +.. + +\newline +} +\layout Standard + +will generate the following code: +\layout Verse + + +\family typewriter +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 91 ;\SpecialChar ~ + hob.c 15 +\newline +0037 85*01*06\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 92\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + _foo_hob1_1_1,(_gint + 1) +\newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 93 ;\SpecialChar ~ + hob.c 16 +\newline +003A 85*05*07\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 94\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + _foo_hob2_1_1,(_glong + 3) +\newline +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 95 ;\SpecialChar ~ + hob.c 17 +\newline +003D 85*04*08\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 96\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + _foo_how1_1_1,(_glong + 2) +\newline +0040 85*05*09\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 97\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + (_foo_how1_1_1 + 1),(_glong + 3) +\newline +0043 85*03*0A\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 98\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + _foo_how2_1_1,(_glong + 1) +\newline +0046 85*04*0B\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + 99\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ +\SpecialChar ~ + mov\SpecialChar ~ +\SpecialChar ~ + (_foo_how2_1_1 + 1),(_glong + 2) +\layout Standard + +Again, variations of these cases may +\emph on +not +\emph default + be recognized. + They are standard C expressions, so I heartily recommend these be the only + way to get the higher order byte/word, (it is portable). + Of course it will be recognized even if it is embedded in other expressions, + e.g.: +\layout Verse + + +\family typewriter +xyz = gint + ((gint >> 8) & 0xFF); +\layout Standard + +will still be recognized. +\layout Subsection + +Peephole Optimizer +\begin_inset LatexCommand \label{sub:Peephole-Optimizer} + +\end_inset + + +\begin_inset LatexCommand \index{Peephole optimizer} + +\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\SpecialChar ~ +@\SpecialChar ~ +microsoft.com). + A default set of rules are compiled into the compiler, additional rules + may be added with the +\emph on +- +\begin_inset ERT +status Collapsed + +\layout Standard + +\backslash +/ +\end_inset + +-peep-file +\begin_inset LatexCommand \index{-\/-peep-file} + +\end_inset + + +\emph default + option. + The rule language is best illustrated with examples. +\layout Verse + + +\family typewriter +replace { +\newline +\SpecialChar ~ +\SpecialChar ~ +mov %1,a +\newline +\SpecialChar ~ +\SpecialChar ~ +mov a,%1 +\newline +} by { +\newline +\SpecialChar ~ +\SpecialChar ~ +mov %1,a +\newline +} +\layout Standard + +The above rule will change the following assembly +\begin_inset LatexCommand \index{Assembler routines} + +\end_inset + + sequence: +\layout Verse + + +\family typewriter +mov r1,a +\newline +mov a,r1 +\layout Standard + +to +\layout Verse + + +\family typewriter +mov r1,a +\layout Standard + +Note: All occurrences of a +\emph on +%n +\emph default + (pattern variable) must denote the same string. + With the above rule, the assembly sequence: \layout Verse @@ -25118,6 +26324,18 @@ return rets;/* is invalid in SDCC although allowed in ANSI */ \end_deeper \layout Itemize +initialization of structure arrays must be fully braced. +\begin_deeper +\layout Verse + + +\family typewriter +struct s { char x } a[] = {1, 2}; /* invalid in SDCC */ +\newline +struct s { char x } a[] = {{1}, {2}}; /* OK */ +\end_deeper +\layout Itemize + 'long long \begin_inset LatexCommand \index{long long (not supported)}