Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te

Slides:



Advertisements
Similar presentations
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
Advertisements

MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Lecture 8: MIPS Instruction Set
CS61C L11 Linker © UC Regents 1 CS61C - Machine Structures Lecture 11 - Starting a Program October 4, 2000 David Patterson
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.
Compiling, Assembling, Loading, Linking (CALL) I (1) Fall 2005 Lecture 09: Program Translation.
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.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
 Procedures (subroutines) allow the programmer to structure programs making them : › easier to understand and debug and › allowing code to be reused.
CS61C L18 Running a Program I (1) Garcia, Spring 2007 © UCB Router Security Hole!  Huge security hole has been found – if you have a home router, crackers.
CS 61C L13 CALL (1) A Carle, Summer 2006 © UCB inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #13: CALL Andy Carle.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS61C L20 Synchronous Digital Systems (1) Garcia, Fall 2006 © UCB Blu-ray vs HD-DVD war over?  As you know, there are two different, competing formats.
CS 61C L18 Running a Program aka Compiling, Assembling, Loading, Linking (CALL) I (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia
CS61C L18 Running a Program aka Compiling, Assembling, Loading, Linking (CALL) I (1) Garcia © UCB Lecturer PSOE Dan Garcia
CS 61C L19 Running a Program aka Compiling, Assembling, Loading, Linking (CALL) II (1) Garcia, Fall 2004 © UCB Lecturer PSOE Dan Garcia
MIPS Assembler Programming
An introduction to systems 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.
CS61C L13 CALL I (1) Chae, Summer 2008 © UCB Albert Chae, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #13 – Compiling,
CS61C L18 Running a Program I (1) Garcia, Fall 2006 © UCB Berkeley beat-down  #10 Cal bears ate the OU ducks They’ve scored 35, 42, 42, 49, 41.
MIPS Instruction Set Advantages
Computer Architecture and Design – ECEN 350 Part 4 [Some slides adapted from M. Irwin, D. Paterson and others]
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
MIPS coding. SPIM Some links can be found such as:
inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 18 – Running a Program I (Compiling, Assembling, Linking, Loading) Researchers.
CDA 3101 Fall 2013 Introduction to Computer Organization Pointers & Arrays MIPS Programs 16 September 2013.
inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 18 – Running a Program I (Compiling, Assembling, Linking, Loading)
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 4.
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.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
CENG 311 Starting a Program. Review (1/2) °IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with +/- infinity, Not-a-Number (Nan),
MIPS assembly syntax Home Assignment 3 Assigned. Deadline 2016 February 14, Sunday.
The Assembly Process Computer Organization and Assembly Language: Module 10.
CS 61C: Great Ideas in Computer Architecture Running a Program - CALL (Compiling, Assembling, Linking, and Loading) 1 Instructors: Nick Weaver & Vladimir.
Lecture 16: 10/29/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CS 110 Computer Architecture Lecture 7: Running a Program - CALL (Compiling, Assembling, Linking, and Loading) Instructor: Sören Schwertfeger
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 4 - Assembler 1.
Lecture 3 Translation.
faculty “re-imagine” ugrad education
Assembler, Compiler, MIPS simulator
Computer Architecture & Operations I
IT 251 Computer Organization and Architecture
MIPS Instruction Set Advantages
System Programming and administration
MIPS assembly syntax Comments
Instructor: Justin Hsia
youtube.com/watch?v=hy0ptZisr70
There is one handout today at the front and back of the room!
Instructions - Type and Format
CALL & Pthread.
Green Subscription Based PC Announced
Inst.eecs.berkeley.edu/~cs61c UCB CS61C : Machine Structures Lecture 12 Instruction Format III and Compilation Instructor Paul Pearce.
Computer Organization and Design Assembly & Compilation
An introduction to systems programming
Program Assembly.
Week 5 Computers are like Old Testament gods; lots of rules and no mercy. Joseph Campbell.
Presentation transcript:

Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 18 – Running a Program I 2004-03-03 Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te Greet class

Interpretation vs Translation Translating C Programs Overview Interpretation vs Translation Translating C Programs Compiler Assembler Linker Loader An Example

Language Continuum Scheme Java C++ C Assembly Java bytecode machine language Easy to program Inefficient to interpret Efficient Difficult to program In general, we interpret a high level language if efficiency is not critical or translated to a lower level language to improve performance

Interpretation vs Translation How do we run a program written in a source language? Interpreter: Directly executes a program in the source language Translator: Converts a program from the source language to an equivalent program in another language For example, consider a Scheme program foo.scm

Interpretation Scheme program: foo.scm Scheme Interpreter

Translation Scheme program: foo.scm Scheme Compiler Executable(mach lang pgm): a.out Hardware Scheme Compiler is a translator from Scheme to machine language.

Any good reason to interpret machine language in software? Interpretation Any good reason to interpret machine language in software? SPIM – useful for learning / debugging Apple Macintosh conversion Switched from Motorola 680x0 instruction architecture to PowerPC. Could require all programs to be re-translated from high level language Instead, let executables contain old and/or new machine code, interpret old code in software if necessary

Interpretation vs. Translation? Easier to write interpreter Interpreter closer to high-level, so gives better error messages (e.g., SPIM) Translator reaction: add extra information to help debugging (line numbers, names) Interpreter slower (10x?) but code is smaller (1.5X to 2X?) Interpreter provides instruction set independence: run on any machine Apple switched to PowerPC. Instead of retranslating all SW, let executables contain old and/or new machine code, interpret old code in software if necessary

Steps to Starting a Program C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o Linker lib.o Executable(mach lang pgm): a.out Loader Memory

Compiler Input: High-Level Language Code (e.g., C, Java such as foo.c) Output: Assembly Language Code (e.g., foo.s for MIPS) Note: Output may contain pseudoinstructions Pseudoinstructions: instructions that assembler understands but not in machine (last lecture) For example: mov $s1, $s2 = or $s1, $s2, $zero

Where Are We Now? C program: foo.c Compiler Assembly program: foo.s Assembler Object(mach lang module): foo.o Linker lib.o Executable(mach lang pgm): a.out Loader Memory

Assembler Input: Assembly Language Code (e.g., foo.s for MIPS) Output: Object Code, information tables (e.g., foo.o for MIPS) Reads and Uses Directives Replace Pseudoinstructions Produce Machine Language Creates Object File

Assembler Directives (p. A-51 to A-53) Give directions to assembler, but do not produce machine instructions .text: Subsequent items put in user text segment .data: Subsequent items put in user data segment .globl sym: declares sym global and can be referenced from other files .asciiz str: Store the string str in memory and null-terminate it .word w1…wn: Store the n 32-bit quantities in successive memory words

Pseudoinstruction Replacement Asm. treats convenient variations of machine language instructions as if real instructions Pseudo: Real: subu $sp,$sp,32 addiu $sp,$sp,-32 sd $a0, 32($sp) sw $a0, 32($sp) sw $a1, 36($sp) mul $t7,$t6,$t5 mul $t6,$t5 mflo $t7 addu $t0,$t6,1 addiu $t0,$t6,1 ble $t0,100,loop slti $at,$t0,101 bne $at,$0,loop la $a0, str lui $at,left(str) ori $a0,$at,right(str)

Producing Machine Language (1/2) Simple Case Arithmetic, Logical, Shifts, and so on. All necessary info is within the instruction already. What about Branches? PC-Relative So once pseudoinstructions are replaced by real ones, we know by how many instructions to branch. So these can be handled easily.

Producing Machine Language (2/2) What about jumps (j and jal)? Jumps require absolute address. What about references to data? la gets broken up into lui and ori These will require the full 32-bit address of the data. These can’t be determined yet, so we create two tables…

List of “items” in this file that may be used by other files. Symbol Table List of “items” in this file that may be used by other files. What are they? Labels: function calling Data: anything in the .data section; variables which may be accessed across files First Pass: record label-address pairs Second Pass: produce machine code Result: can jump to a later label without first declaring it

List of “items” for which this file needs the address. What are they? Relocation Table List of “items” for which this file needs the address. What are they? Any label jumped to: j or jal internal external (including lib files) Any piece of data such as the la instruction

Object File Format object file header: size and position of the other pieces of the object file text segment: the machine code data segment: binary representation of the data in the source file relocation information: identifies lines of code that need to be “handled” symbol table: list of this file’s labels and data that can be referenced debugging information

Peer Instruction Which of the following instructions may need to be edited during link phase? Loop: lui $at, 0xABCD # a ori $a0,$at, 0xFEDC # b jal add_link # c bne $a0,$v0, Loop # d A. a. only B. b. only C. c. only D. d. only E.  a., b., and c. F.  All of the above

Buffer Slide

} data reference; relocate Peer Instruction Which of the following instructions may need to be edited during link phase? Loop: lui $at, 0xABCD # a ori $a0,$at, 0xFEDC # b jal add_link # c bne $a0,$v0, Loop # d } data reference; relocate subroutine; relocate PC-relative branch; OK A. a. only B. b. only C. c. only D. d. only E.  a., b., and c. F.  All of the above