Mips assembler Programming Prof. Sirer cs 316



Yüklə 464 b.
tarix08.10.2017
ölçüsü464 b.
#3557


MIPS Assembler Programming

  • Prof. Sirer

  • CS 316

  • Cornell University


Instructions

  • Arithmetic

    • 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


Assembling Programs

  • Programs consist of a mix of instructions, pseudo-ops and assembler directives

  • Assembler lays out binary values in memory based on directives



Forward References

  • Two-pass 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



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



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)



Yüklə 464 b.

Dostları ilə paylaş:




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©www.genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə