Lec 4Systems Architecture1 Systems Architecture Lecture 4: Compilers, Assemblers, Linkers & Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.

Slides:



Advertisements
Similar presentations
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
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.
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.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
Faculty of Computer Science © 2006 CMPUT 229 Why Computer Architecture? An Introduction to CMPUT 229.
Lecture 8: MIPS Instruction Set
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
Machine Programming I: Basics
University of Washington Instruction Set Architectures ISAs Brief history of processors and architectures C, assembly, machine code Assembly basics: registers,
Instruction Set Architectures
Carnegie Mellon 1 Machine-Level Programming I: Basics /18-213: Introduction to Computer Systems 5 th Lecture, Tue. May 27, 2015 Instructors: Nathaniel.
Machine-Level Programming I: Introduction Topics Assembly Programmer’s Execution Model Accessing Information Registers Memory Arithmetic operations CS.
Machine-Level Programming I: Introduction January 29, 2002 Topics Assembly Programmer’s Execution Model Accessing Information –Registers –Memory Arithmetic.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Machine-Level Programming I: Introduction Apr. 10, 2006 Topics Assembly Programmer’s Execution Model Accessing Information Registers Memory Arithmetic.
Machine-Level Programming I: Introduction Apr. 14, 2008 Topics Assembly Programmer’s Execution Model Accessing Information Registers Memory Arithmetic.
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Carnegie Mellon 1 Machine-Level Programming I: Basics /18-213: Introduction to Computer Systems 5 th Lecture, Sep. 11, 2012 Instructors: Dave O’Hallaron,
Carnegie Mellon 1 Machine-Level Programming I: Basics Lecture, Feb. 14, 2013 These slides are from website which accompanies the.
Carnegie Mellon 1 Machine-Level Programming I: Basics /18-213: Introduction to Computer Systems 5 th Lecture, Jan 28, 2014 Instructors: Seth Copen.
1 Machine-Level Programming I: Basics Comp 21000: Introduction to Computer Organization & Systems Spring 2015 Instructor: John Barr * Modified slides from.
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.
Machine-Level Programming 1 Introduction Topics Assembly Programmer’s Execution Model Accessing Information Registers Memory Arithmetic operations.
Machine-Level Programming I: Introduction Topics Assembly Programmer’s Execution Model Accessing Information Registers Memory Arithmetic operations CS.
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Machine-Level Programming I: Basics Sep. 15, 2015.
University of Washington Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Recitation 6 – 2/26/01 Outline Linking Exam Review –Topics Covered –Your Questions Shaheen Gandhi Office Hours: Wednesday.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Carnegie Mellon 1 Machine-Level Programming I: Basics Slides based on from those of Bryant and O’Hallaron.
University of Washington Basics of Machine Programming The Hardware/Software Interface CSE351 Winter 2013.
Machine-Level Programming 1 Introduction Topics Assembly Programmer’s Execution Model Accessing Information Registers Memory Arithmetic operations.
University of Amsterdam Computer Systems – the instruction set architecture Arnoud Visser 1 Computer Systems The instruction set architecture.
1 Linking. 2 Outline What is linking and why linking Complier driver Static linking Symbols & Symbol Table Suggested reading: 7.1~7.5.
University of Washington Today Lab1, how is it going?  Now due on Sunday HW 1 out! (Integer, FP, …) Luis out of town Monday (no class)  Spend the time.
1 Machine-Level Programming I: Basics Comp 21000: Introduction to Computer Organization & Systems Spring 2015 Instructor: John Barr * Modified slides from.
Linking I Topics Assembly and symbol resolution Static linking Systems I.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Machine-Level Programming I: Introduction Jan. 30, 2001 Topics Assembly Programmer’s Execution Model Accessing Information –Registers –Memory Arithmetic.
Spring 2016Machine Code & C Roadmap 1 car *c = malloc(sizeof(car)); c->miles = 100; c->gals = 17; float mpg = get_mpg(c); free(c); Car c = new Car(); c.setMiles(100);
Lecture 3 Translation.
Section 5: Procedures & Stacks
X86 Assembly - Data.
Instruction Set Architecture
Machine-Level Programming I:
Machine-Level Programming I:
Static and dynamic analysis of binaries
Lecture 6: Assembly Programs
The University of Adelaide, School of Computer Science
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Topic 2e High-Level languages and Systems Software
Machine-Level Programming 1 Introduction
C Prog. To Object Code text text binary binary Code in files p1.c p2.c
Jeremy R. Johnson Wed. Apr. 5, 2000
Machine-Level Programming I: Introduction Feb. 1, 2000
Machine-Level Programming I: Introduction
Computer Organization and Design Assembly & Compilation
X86 Assembly - Data.
Machine-Level Programming: Introduction
Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan
Systems Architecture I
Machine-Level Programming I: Basics
Machine-Level Programming I: Basics Comp 21000: Introduction to Computer Organization & Systems Instructor: John Barr * Modified slides from the book.
Machine-Level Programming I:
10/6: Lecture Topics C Brainteaser More on Procedure Call
Machine-Level Programming I:
Program Assembly.
Machine-Level Programming I: Introduction Sept. 10, 2002
Presentation transcript:

Lec 4Systems Architecture1 Systems Architecture Lecture 4: Compilers, Assemblers, Linkers & Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some material drawn from CMU CSAPP Slides: Kesden and Puschel

Lec 4Systems Architecture2 Introduction Objective: To introduce the role of compilers, assemblers, linkers and loaders. To see what is underneath a C program: assembly language, machine language, and executable.

Lec 4Systems Architecture3 Compilation Process

Lec 4Systems Architecture4 Below Your Program Example from a Unix system Source Files: count.c and main.c Corresponding assembly code: count.s and main.s Corresponding machine code (object code): count.o and main.o Library functions: libc.a Executable file: a.out format for a.out and object code: ELF (Executable and Linking Format)

Lec 4Systems Architecture5 Producing an Executable Program Example from a Unix system (SGI Challenge running IRIX 6.5) Compiler: count.c and main.c  count.s and main.s –gcc -S count.c main.c Assembler: count.s and main.s  count.o and main.o –gcc -c count.s main.s –as count.s -o count.o Linker/Loader: count.o main.o libc.a  a.out –gcc main.o count.o –ld main.o count.o -lc (additional libraries are required)

Lec 4Systems Architecture6 Source Files void main() { int n,s; printf("Enter upper limit: "); scanf("%d",&n); s = count(n); printf("Sum of i from 1 to %d = %d\n",n,s); } int count(int n) { int i,s; s = 0; for (i=1;i<=n;i++) s = s + i; return s; }

Lec 4Systems Architecture7 Assembly Code for MIPS (count.s) #.file 1 "count.c".option pic2.section.text.text.align 2.globl count.ent count count:.LFB1:.frame $fp,48,$31 # vars= 16, regs= 2/0, args= 0, extra= 1 6.mask 0x ,-8.fmask 0x ,0 subu $sp,$sp,48.LCFI0: sd $fp,40($sp)

Lec 4Systems Architecture8. LCFI1: sd $28,32($sp).LCFI2: move $fp,$sp.LCFI3:.set noat lui $1,%hi(%neg(%gp_rel(count))) addiu $1,$1,%lo(%neg(%gp_rel(count))) daddu $gp,$1,$25.set at sw $4,16($fp) sw $0,24($fp) li $2,1 # 0x1 sw $2,20($fp).L3: lw $2,20($fp) lw $3,16($fp) slt $2,$3,$2 beq $2,$0,.L6 b.L4 L6: lw $2,24($fp) lw $3,20($fp) addu $2,$2,$3 sw $2,24($fp).L5: lw $2,20($fp) addu $3,$2,1 sw $3,20($fp) b.L3.L4: lw $3,24($fp) move $2,$3 b.L2.L2: move $sp,$fp ld $fp,40($sp) ld $28,32($sp) addu $sp,$sp,48 j $31.LFE1:.end count

Lec 4Systems Architecture9 Executable Program for MIPS (a.out) f45 4c c e e b b b c c c

Assembly Characteristics: Data Types “Integer” data of 1, 2, or 4 bytes –Data values –Addresses (untyped pointers) Floating point data of 4, 8, or 10 bytes No aggregate types such as arrays or structures –Just contiguously allocated bytes in memory Lec 4Systems Architecture10

Assembly Characteristics: Operations Perform arithmetic function on register or memory data Transfer data between memory and register –Load data from memory into register –Store register data into memory Transfer control –Unconditional jumps to/from procedures –Conditional branches Lec 4Systems Architecture11

Code for sum 0x : 0x55 0x89 0xe5 0x8b 0x45 0x0c 0x03 0x45 0x08 0x89 0xec 0x5d 0xc3 Object Code Assembler –Translates.s into.o –Binary encoding of each instruction –Nearly-complete image of executable code –Missing linkages between code in different files Linker –Resolves references between files –Combines with static run-time libraries E.g., code for malloc, printf –Some libraries are dynamically linked Linking occurs when program begins execution Total of 13 bytes Each instruction 1, 2, or 3 bytes Starts at address 0x Lec 4Systems Architecture12

Disassembled : 0:55 push %ebp 1:89 e5 mov %esp,%ebp 3:8b 45 0c mov 0xc(%ebp),%eax 6: add 0x8(%ebp),%eax 9:89 ec mov %ebp,%esp b:5d pop %ebp c:c3 ret d:8d lea 0x0(%esi),%esi Disassembling Object Code Disassembler objdump -d p –Useful tool for examining object code –Analyzes bit pattern of series of instructions –Produces approximate rendition of assembly code –Can be run on either a.out (complete executable) or.o file Lec 4Systems Architecture13

Disassembled 0x :push %ebp 0x :mov %esp,%ebp 0x :mov 0xc(%ebp),%eax 0x :add 0x8(%ebp),%eax 0x :mov %ebp,%esp 0x40104b :pop %ebp 0x40104c :ret 0x40104d :lea 0x0(%esi),%esi Alternate Disassembly Within gdb Debugger gdb p disassemble sum –Disassemble procedure x/13b sum –Examine the 13 bytes starting at sum Object 0x401040: 0x55 0x89 0xe5 0x8b 0x45 0x0c 0x03 0x45 0x08 0x89 0xec 0x5d 0xc3 Lec 4Systems Architecture14

What Can be Disassembled? Anything that can be interpreted as executable code Disassembler examines bytes and reconstructs assembly source % objdump -d WINWORD.EXE WINWORD.EXE: file format pei-i386 No symbols in "WINWORD.EXE". Disassembly of section.text: : :55 push %ebp :8b ec mov %esp,%ebp :6a ff push $0xffffffff : push $0x a:68 91 dc 4c 30 push $0x304cdc91 Lec 4Systems Architecture15