Program Assembly.

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

The University of Adelaide, School of Computer Science
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.
Lecture 8 Sept 23 Completion of Ch 2 translating procedure into MIPS role of compilers, assemblers, linking, loading etc. pitfalls, conclusions Chapter.
Assembly Code Example Selection Sort.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
Computer Architecture CSCE 350
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
CS3350B Computer Architecture Winter 2015 Lecture 4
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Lecture 8: MIPS Instruction Set
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.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
MIPS Assembler Programming
RISC Concepts, MIPS ISA and the Mini–MIPS project
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
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:
CS35101 Computer Architecture Spring 2006 Week 5 Paul Durand ( Course url:
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 4.
© 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.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Lecture 10: MIPS Simulator Today’s topic –SPIM Simulator Readings –Appendix B 1.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
Csci 136 Computer Architecture II – More on MIPS ISA Xiuzhen Cheng
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
The MIPS Processor Computer Organization The MIPS Processor Appendix A.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 3.
The Assembly Process Computer Organization and Assembly Language: Module 10.
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
Lecture 3 Translation.
ECE3055 Computer Architecture and Operating Systems Chapter 2: Procedure Calls & System Software These lecture notes are adapted from those of Professor.
Computer Architecture & Operations I
CSCI206 - Computer Organization & Programming
Lecture 6: Assembly Programs
Computer Architecture Instruction Set Architecture
MIPS ISA-II: Procedure Calls & Program Assembly
The University of Adelaide, School of Computer Science
MIPS Coding Continued.
ECE3055 Computer Architecture and Operating Systems MIPS ISA
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Topic 2e High-Level languages and Systems Software
MIPS coding.
MIPS Procedures.
CSCI206 - Computer Organization & Programming
Assemblers and Compilers
MIPS coding.
Lecture 7: Examples, MARS, Arithmetic
Instruction encoding The ISA defines Format = Encoding
MIPS coding.
Computer Organization and Design Assembly & Compilation
MIPS Coding.
Computer Architecture
MIPS Functions.
Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan
COMS 361 Computer Organization
Lecture 6: Assembly Programs
Review.
MIPS Coding Continued.
MIPS coding.
10/6: Lecture Topics C Brainteaser More on Procedure Call
MIPS Functions.
Presentation transcript:

Program Assembly

Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions Review memory organization Memory (data movement) instructions Control flow instructions Procedure/Function calls Program assembly

Reading Reading 2.8, 2.12 Appendix A: A1 - A.6 (7.1-7.6 in online text) Practice Problems: 10, 14,23 Goals Understand the binary encoding of complete program executables How can procedures be independently compiled and linked (e.g., libraries)? What makes up an executable? How do libraries become part of the executable? What is the role of the ISA in encoding programs? What constitutes the hardware/software interface

The Complete Picture Reading: 2.12, A2, A3, A4, A5 C program compiler Assembly assembler Object module Object library linker executable loader memory

The Assembler Create a binary encoding of all native instructions Translation of all pseudo-instructions Computation of all branch offsets and jump addresses Symbol table for unresolved (library) references Create an object file with all pertinent information Header (information) Text segment Data segment Relocation information Symbol table Example:

Assembly Process Local labels, global labels, external labels and the symbol table What does mean when a symbol is unresolved? Absolute addresses and re-location

Example .data What changes when you relocate code? Hard address! L1: .word 0x44,22,33,55 # array .text .globl main main: la $t0, L1 li $t1, 4 add $t2, $t2, $zero loop: lw $t3, 0($t0) add $t2, $t2, $t3 addi $t0, $t0, 4 addi $t1, $t1, -1 bne $t1, $zero, loop bgt $t2, $0, then move $s0, $t2 j exit then: move $s1, $t2 exit: li $v0, 10 syscall What changes when you relocate code? 00400000] 3c081001 lui $8, 4097 [L1]         [00400004] 34090004 ori $9, $0, 4             [00400008] 01405020 add $10, $10, $0          [0040000c] 8d0b0000 lw $11, 0($8)             [00400010] 014b5020 add $10, $10, $11         [00400014] 21080004 addi $8, $8, 4            [00400018] 2129ffff   addi $9, $9, -1           [0040001c] 1520fffc   bne $9, $0, -16 [loop-0x0040001c] [00400020] 000a082a slt $1, $0, $10           [00400024] 14200003 bne $1, $0, 12 [then-0x00400024] [00400028] 000a8021 addu $16, $0, $10         [0040002c] 0810000d j 0x00400034 [exit]       [00400030] 000a8821 addu $17, $0, $10        [00400034] 3402000a ori $2, $0, 10           [00400038] 0000000c syscall Hard address! Assembly Program Native Instructions Assembled Binary

Linker & Loader Linker Loader “Links” independently compiled modules Determines “real” addresses Updates the executables with real addresses Static vs. dynamic (lazy) linking Loader As the name implies Specifics are operating system dependent We will come back to this later when we discuss OS

Linking Program A Program B Assembly A Assembly B cross reference header text static data Assembly A Assembly B reloc cross reference symbol table labels debug Why do we need independent compilation? What are the issues with respect to independent compilation? references across files (can be to data or code!) absolute addresses and relocation Study: Example on pg. 127

Example: # separate file .text 0x20040004 addi $4, $0, 4 0x20050005 jal func_add done 0x0340200a 0x0000000c .text .globl func_add func_add: add $2, $4, $5 0x00851020 jr $31 0x03e00008 0x00400000 0x20040004 0x00400004 0x20050005 0x00400008 ? 0x0040000c 0x3402000a 0x00400010 0x0000000c 0x00400014 0x008551020 0x00400018 0x03e00008 Ans: 0x0c100005

Standard Formats: ELF Executable and Linking Format (ELF) ELF header Program Header Table (optional) Section 1 Section 2 Section Header Table (required) ELF header Program Header Table (required) Segment 1 Segment 2 Section Header Table (optional) Linking View Execution View See wikipedia.org

Standard Object File Formats There are other formats associated with different operating systems ISA neutral format for building executables Tools Source  assembly  object  executable  process image Header (information) Text segment Data segment Relocation information Symbol table Image stored on disk How do we translate the image into a running process?  OS

The Computing Model Revisited Register File (Programmer Visible State) Memory Interface stack 0x00 0x01 0x02 0x03 Processor Internal Buses 0x1F Dynamic Data Data segment (static) Text Segment Programmer Invisible State Reserved 0xFFFFFFFF Program Counter Instruction register Arithmetic Logic Unit (ALU) Memory Map Kernel registers Program Execution and the von Neumann model

Stored Program Concept Fetch & Execute Cycle  sequential flow of control Instructions are fetched and put into a special register Bits in the register "control" the subsequent actions Fetch the “next” instruction and continue Program Counter  Program Counter + 4 (byte addressing!) Von Neumann execution model Example: compiler ISA HW HW support

Study Guide Encode/disassemble jal and jr instructions Compute number of bytes to encode a SPIM program What does it mean for a code segment to be relocatable? Identify addresses that need to be modified when a program is relocated. Given the new start address modify the necessary addresses Encode/disassemble jal and jr instructions Computation of jal encodings for independently compiled modules

Study Guide (cont.) How are independently compiled modules linked into a single executable? (assuming one calls a procedure located in another)

Glossary Disassembly Independent compilation Labels: local, global, external Linker/loader Linking: static, dynamic, lazy Native instructions Object file Pseudo instructions Relocatable code Symbol table Unresolved symbol