LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.

Slides:



Advertisements
Similar presentations
1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Advertisements

MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Computer Architecture CSCE 350
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Ch. 8 Functions.
The University of Adelaide, School of Computer Science
CS3350B Computer Architecture Winter 2015 Lecture 4
Lecture 8: MIPS Instruction Set
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Chapter 3 Loaders and Linkers
The Functions and Purposes of Translators Code Generation (Intermediate Code, Optimisation, Final Code), Linkers & Loaders.
CS 31003: Compilers ANIRUDDHA GUPTA 11CS10004 G2 CLASS DATE : 24/07/2013.
Computer Organization CS224 Fall 2012 Lesson 12. Synchronization  Two processors or threads sharing an area of memory l P1 writes, then P2 reads l Data.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Compilation (Semester A, 2013/14) Lecture 13: Assembler, Linker & Loader Noam Rinetzky Slides credit: Eli Bendersky, Mooly Sagiv & Sanjeev Setia.
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
CPSC Compiler Tutorial 8 Code Generator (unoptimized)
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 33: Code Generation and Linking COMP 144 Programming Language Concepts Spring 2002.
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
MIPS Assembler Programming
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Spring 2004 © UCB Roy Wang inst.eecs.berkeley.edu/~cs61c-tf inst.eecs.berkeley.edu/~cs61c.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Software Development and Software Loading in Embedded Systems.
MIPS coding. SPIM Some links can be found such as:
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Runtime Environments Compiler Construction Chapter 7.
Topic 2d High-Level languages and Systems Software
C OMPUTER A RCHITECTURE & O RGANIZATION Assemblers and Compilers Engr. Umbreen Sabir Computer Engineering Department, University of Engg. & Technology.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
CS412/413 Introduction to Compilers and Translators April 14, 1999 Lecture 29: Linking and loading.
1 CS503: Operating Systems Spring 2014 Part 0: Program Structure Dongyan Xu Department of Computer Science Purdue University.
Chapter 13 : Symbol Management in Linking
1/10/2016\course\cpeg323-07F\Topic2c-323.ppt1 Topic2c High-Level languages and System Software (Toolchain) Introduction to Computer Systems Engineering.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
CSc 453 Linking and Loading
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
Hello world !!! ASCII representation of hello.c.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Binding & Dynamic Linking Presented by: Raunak Sulekh(1013) Pooja Kapoor(1008)
Lecture 3 Translation.
Assemblers, linkers, loaders
Computer Architecture & Operations I
ENERGY 211 / CME 211 Lecture 25 November 17, 2008.
The University of Adelaide, School of Computer Science
Program Execution in Linux
Software Development with uMPS
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Topic 2e High-Level languages and Systems Software
Computer Organization & Compilation Process
CALL & Pthread.
The University of Adelaide, School of Computer Science
Computer Organization and Design Assembly & Compilation
Computer Architecture
Topic2d High-Level languages and System Software (Toolchain)
Program Execution in Linux
10/6: Lecture Topics C Brainteaser More on Procedure Call
Computer Organization & Compilation Process
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Topic 2b ISA Support for High-Level Languages
Presentation transcript:

LECTURE 3 Translation

PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application and is fixed in size. The static data area is also fixed in size and contains: Global variables Static local variables String and sometimes floating-point constants The run-time stack Contains activation records, each containing information associated with a function invocation. Saved values of callee-saved registers Local variables and arguments not allocated to registers. Space for the maximum words of arguments passed on stack to other functions. The heap contains dynamically allocated data (e.g. data allocated by the new operator in C++ or malloc function call in C).

ORGANIZATION OF PROCESS MEMORY Reserved Text Static Data Dynamic Data Stack $sp  $gp  pc  Address 0  Here is MIPS convention for allocation of memory. The stack starts at the higher-end of memory and grows downward, while the heap grows upward into the same space. The lower end of memory is reserved. The text segment follows, housing the MIPS machine code.

TRANSLATION PROCESS Preprocessing Compiling Assembling Linking Loading

TRANSLATION PROCESS

PREPROCESSING Some preliminary processing is performed on a C or C++ file. Definitions and macros File inclusion Conditional compilation Try g++ with the -E option!

COMPILING Compiling is referred to as both the entire translation process from source file to executable or the step that translates a source file in a high-level language (sometimes already preprocessed) and produces an assembly file. Compilers are also responsible for checking for correct syntax, making semantic checks, and performing optimizations to improve performance, code size, and energy usage.

ASSEMBLING Assemblers take an assembly language file as input and produce an object file as output. Assembling is typically accomplished in two passes. First pass: stores all of the identifiers representing addresses or values in a table as there can be forward references. Second pass: translates the instructions and data into bits for the object file.

THE OBJECT FILE For Unix systems, the object file contains: An object file header describing the size and position of the other portions of the object file. The text segment containing the machine instructions. The data segment containing the data values. Relocation information identifying the list of instructions and data words that depend on absolute addresses. A symbol table containing global labels and associated addresses in object file and the list of unresolved references. Debugging information to allow a symbolic debugger to associate machine instruction addresses with source line statements and data addresses with variable names.

LINKING Linkers take object files and object libraries as input and produce an executable file as output. Linkers also resolve external references by either finding the symbols in another object file or in a library. The linker aborts if any external references cannot be resolved. The linker determines the addresses of absolute references using the relocation information in the object files. The executable has a similar format as object files with no unresolved references and no relocation information.

LINKING

LOADING The loader copies the executable file (or a portion of it) from disk into memory so it can start executing. Reads the executable file's header to determine the size of the text and data segments. Allocates the address space for the process (text, static data, heap, and stack segments). Copies the instructions into the text segment and data into the static data segment. Copies arguments passed to the program onto the stack. Initializes the machine registers and stack pointer. Jumps to a start-up routine that will call the main function.

GCC EXAMPLE $ ls exp.c exp.h main.c $ gcc -c exp.c $ gcc -c main.c $ ls exp.c exp.h exp.o main.c main.o $ gcc main.o exp.o -o exp_prog exp.c exp.h exp.o exp_prog main.c main.o Let’s say I have three files – a class declared in exp.h and defined in exp.c, as well as a main.c file which uses the class. Preprocessing, Compiling, and Assembling the source code individually. Result is an object file. Linking the object files together into an executable file. You can check out the pre-processed version of your code with the –E option. Prints to stdout. You can check out the assembly version of your code with the –S option. Check the filename.s file.

STORED PROGRAM CONCEPT Memory can contain both instructions and data and the computer is instructed to start executing at a specific location. Different programs can be loaded in different locations and the processor can switch between processes very quickly.