MIPS assembly - PowerPoint PPT Presentation

About This Presentation
Title:

MIPS assembly

Description:

MIPS assembly Exercise 2 How to implement this with only the instructions we learnt? if ($t1 $t2) $t0 = $t1; else $t0 = $t2; Exercise 2 # if ($t1 $t2) $t0 ... – PowerPoint PPT presentation

Number of Views:82
Avg rating:3.0/5.0
Slides: 8
Provided by: Zhen67
Learn more at: http://www.cs.fsu.edu
Category:
Tags: mips | assembly

less

Transcript and Presenter's Notes

Title: MIPS assembly


1
MIPS assembly
2
Exercise 2
  • How to implement this with only the instructions
    we learnt?
  • if (t1 gt t2)
  • t0 t1
  • else
  • t0 t2

3
Exercise 2
  • if (t1 gt t2) t0 t1 else t0 t2
  • sub t3, t1, t2
  • srl t3, t3, 31
  • bne t3, zero, L1
  • ori t0, t1, 0
  • j L2
  • L1
  • ori t0, t2, 0
  • L2

4
slt, slti
  • slt t3, t1, t2 set t3 to be 1 if t1 lt t2
    else clear t3 to be 0. Set Less Than.
  • slti t3, t1, 100 set t3 to be 1 if t1 lt
    100
  • else clear t3 to be 0.
  • Using slt, the code is simpler.

5
Using slt
  • slt t3, t1, t2
  • bne t3, zero, L21
  • ori t0, t1, 0
  • j L22
  • L21
  • ori t0, t2, 0
  • L22

6
Compiling a while loop in C
  • How to translate the following to MIPS assembly?
  • We first translate into a C program using if and
    goto

7
Compiling a while loop in C
  • Assume that i and k correspond to registers s3
    and s5 and starting address of array save is in
    s6
Write a Comment
User Comments (0)
About PowerShow.com