1 / 14

Today ’ s Topic

Today ’ s Topic. Breakdown of CC script. Today ’ s Objectives. Within context of “ compiling ” C program Define actions of linker, compiler, assembler, OS, macro preprocessor, loader Draw block diagram showing order of linker, compiler, assembler, OS, macro preprocessor, loader

Download Presentation

Today ’ s Topic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Today’s Topic • Breakdown of CC script

  2. Today’s Objectives • Within context of “compiling” C program • Define actions of linker, compiler, assembler, OS, macro preprocessor, loader • Draw block diagram showing order of linker, compiler, assembler, OS, macro preprocessor, loader • Explain why runtime stack needed for C • Draw logical division of memory into stack, heap • Compare and contrast stack and heap • For C program, indicate which variables are stored in heap; in stack; in neither

  3. Breaking Down CC Preprocessed Source source ASM Compiler Assembler Preprocessor .s O B J E C T Executable Program In Memory Executable Loader Linker .o a.out

  4. Breaking Down CC Preprocessed Source source ASM Compiler Assembler Preprocessor .s O B J E C T Executable Program In Memory Executable Loader Linker .o a.out

  5. C Preprocessor (cpp) • Pass over source • Insert included files • Perform macro substitutions • Define macros • #define NUM 100 • #define xx(v,name,op,metrics) \ v=xxinit(op,name,IR->metrics) • gcc –E example.c sends preprocessor output to stdout

  6. Breaking Down CC Preprocessed Source source ASM Compiler Assembler Preprocessor .s O B J E C T Executable Program In Memory Executable Loader Linker .o a.out

  7. Compiler • gcc actually name of a script • Compiler translates one language to another (or the same???) • gcc compiler translates C to assembler • gcc –S example.c “saves” example.s • Compiler consists of • Parser • Code generation • Mysticism

  8. Breaking Down CC Preprocessed Source source ASM Compiler Assembler Preprocessor .s O B J E C T Executable Program In Memory Executable Loader Linker .o a.out

  9. Assembler • Another translator ??? (as example.s) • Assembler to (binary) object • Why not compile straight to binary? • gcc –c example.c to “save” object • NM to look at object (nm example.o)

  10. Breaking Down CC Preprocessed Source source ASM Compiler Assembler Preprocessor .s O B J E C T Executable Program In Memory Executable Loader Linker .o a.out

  11. Linker • Combine objects, both user .o files and libraries, make an executable • gcc *.o –lm yields a.out • gcc –o myExec *.o –lm • Use nm to look at object

  12. Breaking Down CC Preprocessed Source source ASM Compiler Assembler Preprocessor .s O B J E C T Executable Program In Memory Executable Loader Linker .o a.out

  13. Loader • Gets an address to place program • Changes necessary addresses (if any) • Places code into memory

  14. Operating System • Oversees whole process • “Recognizes” gcc example.c command • Parses flags and arguments • Invokes gcc script • Performs memory mangagement (malloc) • Chooses “address” to place program

More Related