recursiveFunction.asm

Info icon This preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
# Student: Zhenxing He # Description: recursiveFunction.asm - This program uses recursive function to find the smallest integer in a given array. # The given array A = {5, 2, -9, 10, -23, 43, 2, 1, 3, 5, 10}, low( the first index of array A) = 0, # high( the last index of array A ) = 10 .data A: .word 5, 2, -9, 10, -23, 43, 2, 1, 3, 5, 10 str: .asciiz "The minimum of array A is:\n" .text .globl main main: la $a0, A li $a1, 0 # low li $a2, 10 #high jal Min move $t5, $v0 la $a0, str li $v0, 4 syscall move $a0, $t5 li $v0, 1 syscall li $v0, 10 syscall .text Min: bne $a1, $a2, RecursiveCall # branch if low != high sll $a1, $a1, 2 # low*4 add $t1, $a0, $a1 # A+low lw $v0, 0($t1) # load A[low] jr $ra RecursiveCall: add $t0, $a1, $a2 # low + high sra $t0, $t0, 1 # (low + high)/2 addi $sp, $sp, -16 sw $ra, 0($sp) # back up the return address sw $a1, 4($sp)
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern