MIPS Assembler Programming

Slides:



Advertisements
Similar presentations
The University of Adelaide, School of Computer Science
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.
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.
Wannabe Lecturer Alexandre Joly inst.eecs.berkeley.edu/~cs61c-te
The University of Adelaide, School of Computer Science
Lecture 8: MIPS Instruction Set
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.
CPE 731 Advanced Computer Architecture Instruction Set Principles Dr. Gheith Abandah Adapted from the slides of Prof. David Patterson, University of California,
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.
MIPS on FLEET Amir Kamil. Goals Run most MIPS assembly code on FLEET  Attempt to duplicate level of support in SPIM interpreter  MIPS assembly translated.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
L6 – Simulator 1 Comp 411 – Fall /12/06 Adventures in Assembly Land What is an Assembler ASM Directives ASM Syntax Intro to SPIM Simple examples.
Lecture 5: Procedures. Function call book-keeping in C main() { int i,j,k,m;... i = mult(j,k);... m = mult(i,i);... } /* really dumb mult function */
L5 – Simulator 1 Comp 411 – Fall /16/09 Adventures in Assembly Land What is an Assembler ASM Directives ASM Syntax Intro to SPIM/MARS Simple examples.
VHDL Synthesis of a MIPS-32 Processor Bryan Allen Dave Chandler Nate Ransom.
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:
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University See: P&H Appendix A1-2, A.3-4 and 2.12.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Computer Organization and Design Assembly & Simulation
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.
Computer Organization and Design Assembly & Simulation Montek Singh Mon, Feb 7, 2011 Lecture 5.
RISC, CISC, and Assemblers Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H Appendix B.1-2, and Chapters 2.8 and 2.12;
MIPS Assembly Language Chapter 13 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
EEL5708/Bölöni Lec 3.1 Fall 2006 Sept 1, 2006 Lotzi Bölöni EEL 5708 High Performance Computer Architecture Lecture 3 Review: Instruction Sets.
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 Language Chapter 15 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
MIPS Instruction Set Architecture Prof. Sirer CS 316 Cornell University.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Computer Organization and Design Assembly & Simulation Montek Singh Wed, Sep 26, 2012 Lecture 7.
Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See: P&H Appendix A1-2, A.3-4 and 2.12.
Computer Organization and Design Assembly & Simulation Montek Singh Feb 22, 2016 Lecture 6.
EEL5708/Bölöni Lec 3.1 Fall 2004 Sept 1, 2004 Lotzi Bölöni Fall 2004 EEL 5708 High Performance Computer Architecture Lecture 3 Review: Instruction Sets.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Instructor: Prof. Hany H Ammar, LCSEE, WVU
Lecture 3 Translation.
Computer Architecture & Operations I
Prof. Hsien-Hsin Sean Lee
Computer Organization and Design Assembly & Simulation
Computer Organization and Design Instruction Sets - 2
Computer Organization and Design Instruction Sets - 2
These are slides from Comp411
32-bit MIPS ISA.
ENGR 3410 – Computer Architecture Mark L. Chang Fall 2006
Computer Organization and Design Instruction Sets
Adventures in Assembly Land
Assemblers, Linkers, and Loaders
Assemblers, Linkers, and Loaders
Appendix A Classifying Instruction Set Architecture
MPIS Instructions Functionalities of instructions Instruction format
ECE232: Hardware Organization and Design
Computer Organization and Design Assembly & Simulation
Computer Organization and Design Assembly & Compilation
Assembly and Simulation
MIPS Instruction Set Architecture
Assemblers, Linkers, and Loaders
CS352H Computer Systems Architecture
10/6: Lecture Topics C Brainteaser More on Procedure Call
Adventures in Assembly Land
Program Assembly.
Adventures in Assembly Land
Assemblers, Linkers, and Loaders
Presentation transcript:

MIPS Assembler Programming Prof. Sirer CS 316 Cornell University

Instructions Arithmetic Control Flow Memory Special ADD, ADDU, SUB, SUBU, AND, OR, XOR, NOR, SLT, SLTU ADDI, ADDIU, ANDI, ORI, XORI, LUI, SLL, SRL, SLLV, SRLV, SRAV, SLTI, SLTIU MULT, DIV, MFLO, MTLO, MFHI, MTHI Control Flow BEQ, BNE, BLEZ, BLTZ, BGEZ, BGTZ J, JR, JAL, JALR, BEQL, BNEL, BLEZL, BGTZL Memory LW, LH, LB, LHU, LBU, LWL, LWR SW, SH, SB, SWL, SWR Special LL, SC, SYSCALL, BREAK, SYNC, COPROC

Assembler Translates text assembly language to binary machine code Input: a text file containing MIPS instructions in human readable form Output: an object file (.o file in Unix, .obj in Windows) containing MIPS instructions in executable form

Assembly Language Assembly language is used to specify programs at a low-level What does a program consist of? MIPS instructions Program data (strings, variables, etc)

Program Layout Programs consist of segments used for different purposes Text: holds instructions Data: holds statically allocated program data such as variables, strings, etc. BSS: holds dynamically allocated program data Stack: holds activation records “cornell cs” 13 25 data add r1,r2,r3 ori r2, r4, 3 ... text

Assembling Programs Programs consist of a mix of instructions, pseudo-ops and assembler directives Assembler lays out binary values in memory based on directives .text .ent main main: la $4, Larray li $5, 15 ... li $4, 0 jal exit .end main .data Larray: .long 51, 491, 3991

Forward References Two-pass assembly One-pass (or backpatch) assembly Do a pass through the whole program, allocate instructions and lay out data, thus determining addresses Do a second pass, emitting instructions and data, with the correct label offsets now determined One-pass (or backpatch) assembly Do a pass through the whole program, emitting instructions, emit a 0 for jumps to labels not yet determined, keep track of where these instructions are Backpatch, fill in 0 offsets as labels are defined

Handling Forward References Example: bne $1, $2, L sll $0, $0, 0 L: addiu $2, $3, 0x2 The assembler will change this to bne $1, $2, +1 sll $0, $0, 0 addiu $7, $8, $9 Final machine code 0X14220001 # bne 0x00000000 # sll 0x24620002 # addiu

Object File Generation A program is made up by code and data from several object files Each object file is generated independently Assembler starts at some PC address, e.g. 0, in each object file, generates code as if the program were laid out starting out at location 0x0 It also generates a symbol table, and a relocation table In case the segments need to be moved

Object file Header Text Segment Data Segment Relocation Information Symbol Table Debugging Information

Separate Compilation Separately compiling modules and linking them together obviates the need to recompile the whole program every time something changes Need to just recompile a small module A linker coalesces object files together to create a complete program

Linkers Combine object files into an executable Resolves symbols Creates final executable Stores entry point in executable so processor knows where to start executing End result: a program on disk, ready to execute Static linkers Dynamic linkers Integrate code at runtime, reduces executable size One copy of shared library in memory Performance hit

Loaders Reads executable from disk Loads code and data into memory Initializes registers, stack, arguments Jumps to entry-point Part of the Operating System (OS)