Question: Need help modifying my MIPS code so it works with all negative numbers as well as with positive numbers. .data arr1: .word 0,0,0,0,0,0,0,0,0,0 newline: .asciiz

Need help modifying my MIPS code so it works with all negative numbers as well as with positive numbers.

.data arr1: .word 0,0,0,0,0,0,0,0,0,0 newline: .asciiz " " input: .asciiz "Enter number of elements in array : " space: .asciiz " " str1: .asciiz "Please Enter A Number : " str2: .asciiz " Largest element in array is : " error1: .asciiz "Error: Size of Array should be between 1 and 10: " .text

main: #prompts and reads integer li $v0,4 la $a0,input syscall li $v0,5 syscall

add $s3, $v0, $0 blt $s3, 1, error bgt $s3, 10, error

move $s0,$v0 #load size of array #reduce s0 by 1 as zero based index subi $s0,$s0,1

mul $t7,$s0,4 #get last element integer index

in: #prompt for integer li $v0,4 la $a0,str1 syscall #get number li $v0,5 syscall #read input unti t1 is empty add $t1,$t0,$zero sll $t1,$t0,2 add $t3,$v0,$zero #store data at location sw $t3,arr1 ($t1) addi $t0,$t0,1 slt $t1,$s0,$t0 beq $t1,$zero,in

li $s7,0 li $t0,0 #load last address of array when size is 10 loop: lw $s1,arr1 ($t0)

ble $s1,$s7,skip move $s7,$s1 #store largest element

skip: addi $t0,$t0,4 slt $t1,$t7,$t0 beq $t1,$zero,loop

li $v0,4 la $a0,str2 syscall

li $v0,1 move $a0,$s7 syscall

done: li $v0, 10 syscall

error: li $v0, 4 la $a0, error1 syscall j main

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!