Unformatted text preview:

1 ECE 15B COMPUTER ORGANIZATION Dr. Rahul Singh!Lecture 17!Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!June 2, 2009 Electrical and Computer Engineering University of California, Santa Barbara!Announcements!• Project #3 !• Due June 10, 5pm!• Submit via email!• Homework #4!• Due June 5, 5pm!• In box on 3rd Floor HFH!• Final Exam!• Monday June 8 at 4:00 pm!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!1!Electrical and Computer Engineering University of California, Santa Barbara!Review: Language Continuum!• In general, we interpret a high level language if efficiency is not critical or translated to a lower level language to improve performance!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!2!Easy to program!Inefficient to interpret!Efficient!Difficult to program!Scheme!Java!C++! C! Assembly! machine language!Java bytecode!Electrical and Computer Engineering University of California, Santa Barbara!Review: 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!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!3!2 Electrical and Computer Engineering University of California, Santa Barbara!Steps to Running a Program!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!4!C program: foo.c!Compiler!Assembly program: foo.s Assembler!Executable(mach lang pgm): a.out Loader!Memory Object(mach lang module): foo.o Linker!lib.o!Electrical and Computer Engineering University of California, Santa Barbara!Compiler!• Input: High-Level Language Code !• e.g., C, Java such as foo.c, foo.java!• Output: Assembly Language Code!• e.g., foo.s for MIPS!• Note: Output may contain pseudo-instructions!• Pseudoinstructions: instructions that assembler understands but not part of instruction set (“macros”)!• For example:!mov $s1, $s2 or $s1, $s2, $zero!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!5!Electrical and Computer Engineering University of California, Santa Barbara!Where are we now?!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!6!C program: foo.c!Compiler!Assembly program: foo.s Assembler!Executable(mach lang pgm): a.out Loader!Memory Object(mach lang module): foo.o Linker!lib.o!Electrical and Computer Engineering University of California, Santa Barbara!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!• Replaces Pseudo-instructions!• Produce Machine Language!• Creates Object File!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!7!3 Electrical and Computer Engineering University of California, Santa Barbara!Assembler Directives (p. A-51 to A-53)!• Give directions to assembler, but do not produce machine instructions!• .text !• Subsequent items (e.g. instructions) to be put in user text segment!• .data!• Subsequent items (e.g. data) put in user data segment !• .globl sym!• declares sym global !• 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!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!8!Electrical and Computer Engineering University of California, Santa Barbara!Pseudoinstruction Replacement!• Assembler treats convenient variations of machine language instructions as if real instructions!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!9!. !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)!Electrical and Computer Engineering University of California, Santa Barbara!Producing Machine Language!• 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!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!10!Electrical and Computer Engineering University of California, Santa Barbara!Producing Machine Language!• 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…!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!11!4 Electrical and Computer Engineering University of California, Santa Barbara!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!June 2, 2009!Lecture 17: Executing Programs: Compiling, Assembling, Linking and Loading (Part II)!12!Electrical and Computer Engineering University of California, Santa Barbara!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!June 2,


View Full Document

UCSB ECE 15 - Lecture_17

Documents in this Course
Load more
Download Lecture_17
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture_17 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture_17 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?