Next Previous Contents

# SDCC Compiler User Guide

## Sandeep Dutta (sandeep.dutta@usa.net)

## 1. Introduction

## 2. Installation

- 2.1 Components of SDCC
- 2.2 Installation for Version <= 2.1.7
- 2.3 Installation for Version >= 2.1.8a

  ## 3. Compiling.

  - 3.1 Single Source file projects.
  - 3.2 Projects with multiple source files.
  - 3.3 Projects with additional libraries.

    ## 4. Command Line options

    ## 5. Language Extensions

    - 5.1 Storage Classes.

      ## 6. Optimizations

      - 6.1 Sub-expression elimination
      - 6.2 Dead-Code elimination.
      - 6.3 Copy-Propagation:
      - 6.4 Loop optimizations
      - 6.5 Algebraic simplifications:
      - 6.6 'switch' statements.
      - 6.7 bit-shifting operations.
      - 6.8 Highest Order Bit.
      - 6.9 Peep-hole optimizer.

        ## 7. Pointers

        ## 8. Parameters & Local Variables

        - 8.1 Overlaying

          ## 9. critical Functions.

          ## 10. Absolute addressing.

          ## 11. Interrupt Service Routines

          ## 12. Startup Code

          ## 13. Inline assembler code.

          ## 14. int (16 bit) and long (32 bit ) support.

          ## 15. Floating point support

          ## 16. Memory Models

          ## 17. Flat 24 bit addressing model.

          ## 18. Defines created by the compiler.

          ## 19. Pragmas

          ## 20. Library routines.

              printf_small("my str %s, my int %d\n",(char _generic *)mystr,myint);

          - stdarg.h - 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'

            va_list, va_start, va_arg, va_end.

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

            atoi, atol.

          - string.h - contains the following functions.

            strcpy, strncpy, strcat, strncat, strcmp, strncmp, strchr, strrchr, strspn, strcspn, strpbrk, strstr, strlen, strtok, memcpy, memcmp, memset.

          - ctype.h - contains the following routines.

            iscntrl, isdigit, isgraph, islower, isupper, isprint, ispunct, isspace, isxdigit, isalnum, isalpha.

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

                //Example:
                     //     #define DYNAMIC_MEMORY_SIZE 0x2000
                     //
                 .....
                     //     unsigned char xdata dynamic_memory_pool[DYNAMIC_MEMORY_SIZE];

                     //     unsigned char xdata * current_buffer;
                     //     .....

                 //     void main(void)
                     //     {
                     //         ...
                     //
                 init_dynamic_memory(dynamic_memory_pool,DYNAMIC_MEMORY_SIZE);
                     //
                 //Now it's possible to use malloc.
                     //         ...
                     //         current_buffer
                 = malloc(0x100);
                     //

          - serial.h - Serial IO routines are also developed by Dmitry S. Obukhov (dso@usa.net). These routines are interrupt driven with a 256 byte circular buffer, they also expect external ram to be present. Please see documentation in file SDCCDIR/sdcc51lib/serial.c . Note the header file "serial.h" MUST be included in the file containing the 'main' function.
          - ser.h - Alternate serial routine provided by Wolfgang Esslinger <wolfgang@WiredMinds.com> these routines are more compact and faster. Please see documentation in file SDCCDIR/sdcc51lib/ser.c
          - ser_ir.h - Another alternate set of serial routines provided by Josef Wolf <jw@raven.inka.de> , these routines do not use the external ram.
          - reg51.h - contains register definitions for a standard 8051
          - reg552.h - contains register definitions for 80C552.
          - float.h - contains min, max and other floating point related stuff.

          All library routines are compiled as --model-small , they are all non-reentrant, if you plan to use the large model or want to make these routines reentrant, then they will have to be recompiled with the appropriate compiler option.

          Have not had time to do the more involved routines like printf, will get to them shortly.

          ## 21. Interfacing with assembly routines.

          - 21.1 Global registers used for parameter passing.
          - 21.2 With --noregparms option.

            ## 22. External Stack.

            ## 23. ANSI-Compliance.

            ## 24. Cyclomatic Complexity

            ## 25. TIPS

            ## 26. Retargetting for other MCUs.

            ## 27. Reporting Bugs

            ## 28. SDCDB - Source level debugger.

            - 28.1 Compiling for debugging.
            - 28.2 How the debugger works.
            - 28.3 Starting the debugger.
            - 28.4 Command line options.
            - 28.5 Debugger Commands.
            - 28.6 Interfacing with XEmacs.

              ## 29. Conclusion

              ## 30. Acknowledgments

              ## 31. Appendix A: The Z80 and gbz80 port

              Next Previous Contents