Question: Convert (findlargest) procedure to be recursive? .data prompt: .asciiz Smallest number is : prompt1: .asciiz Biggest number is : prompt2: .asciiz

Convert (findlargest) procedure to be recursive?

.data prompt: .asciiz " Smallest number is : " prompt1: .asciiz " Biggest number is : " prompt2: .asciiz " Range of number is : " array : .word 10,-5,-30,15,20,-1,-26,-18,64 .text .globl main main :

j range #only call to function from main

range: la $s7,array #store array index li $s1,0 #store index to pass to array li $s0,10 #size of array lw $s2,array jal findLargest move $t7,$s2 #get largest

li $s1,0 #store index to pass to array li $s0,10 #size of array lw $s2,array jal findSmallest move $t6,$s2 #get largest

li $v0,4 la $a0,prompt1 #it will print prompt syscall li $v0,1 move $a0,$t7 #print number of items syscall

li $v0,4 la $a0,prompt #it will print prompt syscall li $v0,1 move $a0,$t6 #print number of items syscall

li $v0,4 la $a0,prompt2 #it will print prompt syscall li $v0,1 sub $a0,$t7,$t6 #print number of items syscall

li $v0,10 syscall

findLargest: subu $sp,$sp,4 # point to the place for the new item, sw $ra,($sp) # store the contents of $ra as the new top. blt $s1,$s0,else j skipCall else: mul $t0,$s1,4 #get integer index add $t0,$t0,$s7 lw $t0,($t0) ble $t0,$s2,skipAssignBig move $s2,$t0 skipAssignBig: add $s1,$s1,1 jal findLargest skipCall: lw $ra,($sp) # store the contents of $ra as the new top. addu $sp,$sp,4 # point to the place for the new item, move $v1,$s4 jr $ra

findSmallest: subu $sp,$sp,4 # point to the place for the new item, sw $ra,($sp) # store the contents of $ra as the new top. blt $s1,$s0,else2 j skipCall2 else2: mul $t0,$s1,4 #get integer index add $t0,$t0,$s7 lw $t0,($t0) bge $t0,$s2,skipAssignSmall move $s2,$t0 skipAssignSmall: add $s1,$s1,1 jal findSmallest skipCall2: lw $ra,($sp) # store the contents of $ra as the new top. addu $sp,$sp,4 # point to the place for the new item, move $v1,$s4 jr $ra

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!