23
Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades reported: 169 Mean: 43.6 Standard deviation: 10.8 Minimum: 2.0 1st quartile: 37.0 2nd quartile (median): 46.0 3rd quartile: 52.0 Maximum: 59.0 Max possible: 60.0 Reminder: Homework 6 is due Monday, March 9 at 11:59pm Project 2 has been posted (due Friday, March 20) Exam solutions posted on next Monday (probably)

Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Exam 1 Info

Exam 1 returned in Tu/W lab

cs61cl-tb@h30 [4] ~ > glookup -s exam1

Number of grades reported: 169Mean: 43.6Standard deviation: 10.8Minimum: 2.01st quartile: 37.02nd quartile (median): 46.03rd quartile: 52.0Maximum: 59.0Max possible: 60.0

Reminder: Homework 6 is due Monday, March 9 at 11:59pm Project 2 has been posted (due Friday, March 20) Exam solutions posted on next Monday (probably)

Page 2: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Guest Lecture - CALL

Where are we going? Number Representation Floating Point Compilation, Assembly, 

Linking, Loading Caches

Page 3: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Motivation

What happens when we type                                gcc program.c ­o program?

What work is done to turn the source code into  something the computer can process?

How is it possible to play N64 games on your PC?

Page 4: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Lowdown

Page 5: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Compiler

Translates from one programming language to another (e.g. C ­> Assembly)

Pseudo­instructions may be present in output Targeted optimization at this step

Page 6: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Assembler

Decodes assembly language into machine language (opcodes + symbol table)

Splits pseudo­instructions into actual ones Resolves symbolic names Processes directives Generates symbol and relocation tables Output is in an object file

Page 7: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Assembler

Regular Instructions

Pseudo­instructions

Symbolic Names

Relocation Table

Symbol Table

Directives

Straight­up conversion Instruction:  sra $s1 $0 8

R Fields:  0 0 0 17 8 3 Binary: 000000 00000 00000 

10001 01000 000011 Hex:  0x00008A03               

  What about  la $a0, str?

Page 8: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Assembler

Regular Instructions

Pseudo­instructions

Symbolic Names

Relocation Table

Symbol Table

Directives

la $a0, str

Pseudo, so broken down into: lui $at,left_16(str)ori $a0,$at,right_16(str)

Note the usage of $at

Page 9: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Assembler

Regular Instructions

Pseudo­instructions

Symbolic Names

Relocation Table

Symbol Table

Directives

L1: slt $t0, $0, $a1 beq $t0, $0, L2 addi $a1, $a1, -1 j L1 L2: add $t1, $a0, $a1

We can resolve branches right now! L1: slt $t0, $0, $a1 beq $t0, $0, 2 addi $a1, $a1, -1 j L1 L2: add $t1, $a0, $a1

Page 10: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Assembler

Regular Instructions

Pseudo­instructions

Symbolic Names

Relocation Table

Symbol Table

Directives

Jumps are more troublesome Require the absolute address Don't know how objects will arrange Forward addressing

Thus, maintain two tables Symbol Table Relocation Table

Page 11: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Assembler

Regular Instructions

Pseudo­instructions

Symbolic Names

Relocation Table

Symbol Table

Directives

Relocation table contains a list of things we need to fix in the file Labels referenced in jump instructions Global labels targeted by la External labels not in the current file

We fix these later on when the information becomes available

Page 12: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Assembler

Regular Instructions

Pseudo­instructions

Symbolic Names

Relocation Table

Symbol Table

Directives

Symbol table associates identifiers with where it is declared Relative address of labels to the start 

of the text segment Ordering of variables in the .data 

segment

This is for later reference by the program or by another object file

Page 13: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Assembler

Regular Instructions

Pseudo­instructions

Symbolic Names

Relocation Table

Symbol Table

Directives

Directives give guidelines to assembler

.globl – Declares a global    variable

.text – Marks beginning of the code segment

.data – Start of variable declaration for storage in memory

.asciiz – Declares a \0 terminated string

.word – 32 bit integer                                    

And many more...

Page 14: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

ELF Layout

The Executable and Linking Format Object Header Section Headers .text segment .data segment Relocation Table Symbol Table Misc. + Debug Info

Page 15: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Linker

Page 16: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Linker

Input has all the necessary files Start by concatenating data and text segments Then fix up things in all the relocation tables by 

consulting the symbol table of each file Assume 0 is the start address of text segment Separate object files allow

Distribution of obfuscated object+header files Quick recompilation of just the modified source files

Page 17: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Loader

Loads text and data of program into memory Initialize registers ($sp, $gp, $fp, etc.) Moves command line input parameters to registers Executes and increments program counter

Page 18: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Summary

Compiler turns source code into assembly code      (.c ­> .s)

Assembler turns assembly code into machine code (.s ­> .o)

Linker combines many object files and libraries into an executable (.o + .o ­> a.out)

Loader loads the program into memory and runs (./a.out)

Page 19: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Demo

Questions? We'll clarify here with a demo

Page 20: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Compiler vs Interpreter

Compiler translates high­level language into machine language (eventually)

Examples: Assembly, C/C++, Java Interpreter runs the high­level language directly Examples: Matlab, Perl, Python, Scheme, Java          

        Compilation and interpretation are not exclusive Java translates source to bytecode, then interprets

Page 21: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Compiler vs Interpreter

(+) Easier to write interpreter (CS 61A), less code (+) Interpreter is more easily portable (­) Interpreter has overhead

Must maintain internally symbols, stack, and state

(­) Programs on interpreters are harder to distribute

Page 22: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Just In Time Compilation

Compile only what we need when we encounter it Slow at first, fast later Combines the (+) of compilation and interpretation Allows runtime optimization for specific processor 

instructions Java and Microsoft .NET do this

Page 23: Exam 1 Info - Open Computing Facilityrfguo/CS61CL/CS61CL Guest... · 2009-03-06 · Exam 1 Info Exam 1 returned in Tu/W lab cs61cl-tb@h30 [4] ~ > glookup -s exam1 Number of grades

Images Used with Permission from Wikipedia

CS61CL Spring 2009 EditionRichard Guo

Dynamic vs Static Linking

So far, we've done static linking Embeds libraries and objects in a single file

Dynamic linking loads required objects at runtime (+) Reduced file size and memory usage at runtime (+) Library updates are propagated automatically (­) Linking process takes time