1 / 9

CDA 3100

CDA 3100. Recitation Week 7. Write a Complete MIPS Program. For each array element i , find the min(array0[i], array1[i]) and store it into array2[i] array0, array1, and array2 store floating point numbers Each array holds 5 elements array0 holds [0.6, 0.7, 0.9, 0.1, -0.8]

berne
Download Presentation

CDA 3100

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CDA 3100 Recitation Week 7

  2. Write a Complete MIPS Program • For each array element i, find the min(array0[i], array1[i]) and store it into array2[i] • array0, array1, and array2 store floating point numbers • Each array holds 5 elements • array0 holds [0.6, 0.7, 0.9, 0.1, -0.8] • array1 holds [0.8, 1.9, 11.2, -0.19, 0.7]

  3. Some useful instructions • swc1 $f0, 0($t0) • Store floating point number into address • lwc1 $f0, 0($t0) • Load address as floating point number • s.s $f0, 0($t0) • Store floating point number into address • l.s $f0, 0($t0) • Load address as floating point number • mov.s $f0, $f1 • Copy a floating point number • c.lt.s $f0, f1 • If $f0 < $f1, a flag that can be used for jumps is triggered • bc1t L1 • Branch to L1 if flag is set • jalFunc • Go to a function • jr $ra • Return from function

  4. Answer (1) .data array0: .float 0.6, 0.7, 0.9, 0.1, -0.8 array1: .float 0.8, 1.9, 11.2, -0.19, 0.7 array2: .space 20 msg_newline: .asciiz “\n” .text .globl main

  5. Answer (2) main: la $a0, array0 la $a1, array1 la $a2, array2 li $a3, 5 jalfloatArray done: addi $t0, $a2, 0 addi $t1, $0, 0

  6. Answer (3) loop: li $v0, 2 l.s $f12, 0($t0) syscall li $v0, 4 la $a0, msg_newline syscall addi $t0, $t0, 4 addi $t1, $t1, 1 blt $t1, $a3, loop exit: li $v0,10 syscall

  7. Answer (4) floatArray: addi $sp, $sp, -12 swc1 $f0, 8($sp) swc1 $f1, 4($sp) swc1 $f2, 0($sp) addi $t0, $a0, 0 addi $t1, $a1, 0 addi $t2, $a2, 0 addi $t9, $0, 0

  8. Answer (5) floatArrayloop: l.s $f0, 0($t0) l.s $f1, 0($t1) c.lt.s $f0, $f1 bc1t floatArrayskip mov.s $f0, $f1

  9. Answer (6) floatArrayskip: s.s $f0, 0($t2) addi $t0, $t0, 4 addi $t1, $t1, 4 addi $t2, $t2, 4 addi $t9, $t9, 1 blt $t9, $a3, floatArrayloop lwc1 $f0, 8($sp) lwc1 $f1, 4($sp) lwc1 $f2, 0($sp) addi $sp, $sp, 12 jr $ra

More Related