Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

What should be an ideal company's budgeting process look like?

Answered: 1 week ago

Question

2. Identify conflict triggers in yourself and others

Answered: 1 week ago