MIPS%20coding - PowerPoint PPT Presentation

About This Presentation
Title:

MIPS%20coding

Description:

MIPS coding. SPIM. Some links can be found such as: ... Here by comparing arrays and pointers in MIPS assembly we can have a much better ... Comparing Two Versions ... – PowerPoint PPT presentation

Number of Views:132
Avg rating:3.0/5.0
Slides: 35
Provided by: zhen6
Learn more at: http://www.cs.fsu.edu
Category:

less

Transcript and Presenter's Notes

Title: MIPS%20coding


1
MIPS coding
2
SPIM
  • Some links can be found such as
  • http//www.cs.gmu.edu/dnord/cs265/spim_intro.html

3
A C Sort Example
4
A C Sort Example
5
A C Sort Example
6
A C Sort Example
7
A C Sort Example
8
Character and String Operations
  • Characters are encoded as 0s and 1s using ASCII
    most commonly
  • American Standard Code for Information
    Interchange
  • Each character is represented using 8 bits (or a
    byte)
  • MIPS provides instructions to move bytes
  • Load byte (lb) loads a byte to the rightmost 8
    bits of a register
  • Store byte (sb) write the rightmost 8 bits of a
    register to memory

9
String Copy Procedure
10
String Copy Procedure
  • Do we have to use s0?

11
Arrays vs. Pointers
  • Pointers sometime seem difficult to understand in
    C/C
  • Here by comparing arrays and pointers in MIPS
    assembly we can have a much better understanding
    of the differences

12
C Programs Using Arrays and Pointers
13
C Programs Using Arrays and Pointers
14
MIPS Assembly Using Arrays
  • Register allocations Two parameters are in a0
    (for array) and a1 (for size), and local
    variable i is allocated to register t0

15
MIPS Assembly Using Pointers
  • Register allocations Two parameters are in a0
    (for array) and a1 (for size), and local
    variable p is allocated to register t0

16
Comparing Two Versions
  • Suppose the size of array is n, how many
    instructions for the array version?
  • How many instructions for the pointer version?

17
Comparing Two Versions
  • Suppose the size of array is n, how many
    instructions for the array version?
  • How many instructions for the pointer version?

18
Comparing Two Versions
  • Suppose the size of array is n, how many
    instructions for the array version?
  • How many instructions for the pointer version?

19
Tree Sort
  • This example shows to support data structures
    such as nodes in a binary tree
  • Binary search tree
  • One way to create a sorted list is to insert
    values sequentially into a binary tree, where the
    values in the left tree are no larger than the
    value in the node and the values in the right
    tree are no smaller than the value in the node

20
Tree Node
  • In C, each tree node will be defined as a
    recursive data structure
  • How can we do that in MIPS?
  • In MIPS we do not have types explicitly
  • The types are defined implicitly based on the
    instructions we use

21
Tree Node
  • In MIPS, we need three words

22
Searching the Tree
23
Treesort.s
  • It first creates an empty tree by creating a root
    node with empty left and right pointers
  • Loop
  • Read a new value
  • If it is the sentinel value, break out the loop
  • Otherwise, insert the value into the tree and
    repeat
  • Traverse the tree recursively
  • http//www.cs.fsu.edu/zzhang/CDA3100_Spring_2008_
    files/tree_sort.asm

24
Note
  • Note that a number can be written and saved in
    different ways
  • For example, number 1234 can be represented as
    1234 (as a string)
  • number 1234 can be represented as a twos
    complement integer

25
Number 1234 in Memory
26
Addressing Modes
  • An addressing mode is a form for specifying one
    or more operands
  • Typically one instruction set architecture will
    use multiple forms of addressing modes
  • In MIPS, we have five different addressing modes

27
MIPS Addressing Modes
28
Translating a C Program
29
Generated Intel Assembly Example
30
Assembler
  • The primary task of an assembler is to translate
    assembly into machine code
  • It produces an object file, which consists of
    machine language instructions, data, and
    information needed to place instructions properly
    in memory
  • A UNIX object file consists of the object file
    header, text segment, static data segment,
    relocation information, symbol table, and
    debugging information
  • Which instructions may change depending on the
    absolute locations of instructions?

31
Linkers
  • Object files need to be combined together in
    order to produce an executable program
  • The tool is called the linker
  • Searches the libraries to find library routines
    used by the program
  • Determines the memory locations for each module
    and relocates its instructions by adjusting
    absolute references
  • Resolve any unresolved references among files
    (including libraries)

32
Linkers
33
Loaders
  • Note that an executable file is on the disk
  • To run a program, it needs to be loaded into
    memory

34
Dynamically Linked Libraries
Write a Comment
User Comments (0)
About PowerShow.com