Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help fix MIPS assembly program. The program takes 10 values from the user and inputs them into an array. It then provides the option to

Help fix MIPS assembly program. The program takes 10 values from the user and inputs them into an array. It then provides the option to replace a value at a given index in the array. It also allows for the maximum value or the minimum value to be removed.Upon exit of the program it should display the product and the sum of the array. My code is below as well as an example i/o for how the program should operate.

Please enter 10 integer values: 1 2 3 4 5 6 7 8 9 10 Your values are: 1 2 3 4 5 6 7 8 9 10 Menu (enter an int as your choice): 1) Replace an element at a certain position 2) Remove the max element 3) Remove the min element 4) Compute values and exit What would you like to do? 1 What position from the array do you wish to replace? 3 What value to you want to change it to? 4 Your values are: 1 2 4 4 5 6 7 8 9 10 Menu (enter an int as your choice): 1) Replace an element at a certain position 2) Remove the max element 3) Remove the min element 4) Compute values and exit What would you like to do? 2 Your values are: 1 2 4 4 5 6 7 8 9 Menu (enter an int as your choice): 1) Replace an element at a certain position 2) Remove the max element 3) Remove the min element 4) Compute values and exit What would you like to do? 4 The summation of all values in the array is: 46, the product of all values in the array is: 483840

Here is the current MIPs program:

.data

numbers: .space 400

x: .word 10

message1: .asciiz "Enter an integer:"

message2: .asciiz "The array contains the following: "

next_line: .asciiz ", "

txt6: .asciiz "Menu(enter an int as your choice):

1) Replace an element at a certain position

2) Remove the max element

3) Remove the min element

4) Compute values and exit "

txt7: .asciiz "What position from the array do you wish to replace?"

txt8: .asciiz "What value to you want to change it to?"

.text

.globl main

main:

la $a1, numbers # $a1 is the base address of the array

li $a2, 10 # $a2 = 10;

li $a3, 0 #

li $t7, 0 #

jal readArray

jal printArray

jal menu

jr $ra

readArray:

li $t0, 0 # i = 0;

loop: bge $t0, $a2, Exit1 #if (i >= 9)Exit the loop;

# cout << message1 << endl;

la $a0, message1

li $v0, 4

syscall

# cin >> numbers[i];

li $v0, 5

syscall

sw $v0, ($a1)

addi $a1, $a1, 4 # move the array over by 1 element

addi $t0, $t0, 1 #i++

#############

# beq $t0, 1, first # branches to first if $t0 = 1

# blt $s0, $t1, min # branches to min if $s0 < $t1

# bgt $s0, $t2, max # branches to max if $s0 > $t2

#first:

# add $t1, $s0, 0 # $t1 = $s0 + 0

# add $t2, $s0, 0 # $t2 = $s0 + 0

## j loop # reloop

#min:

# add $t1, $s0, 0 # $t1 = $s0 + 0

# j loop # reloop

#max:

# add $t2, $s0, 0 # $t2 = $s0 + 0

# j loop # reloop

################

printArray:

add $a0, $t1, 0

li $v0, 1

syscall

add $a0, $t7, 0

li $v0, 1

syscall

la $a1,numbers

li $t0, 0 #1 = 0;

# cout << message2 << endl;

la $a0, message2

li $v0, 4

syscall

loop1:

bge $t0, $a2, Exit1 #if (i >= 9) Exit the loop;

li $v0, 1

lw $a0, 0($a1)

syscall

#cout << " " << endl;

la $a0, next_line

li $v0, 4

syscall

addi $a1, $a1, 4

addi $t0, $t0, 1

j loop1

replaceElement:

la $a0, txt7 # copies address of txt7 into $a0

li $v0, 4 # loads print string instruction into $v0

syscall

li $v0, 5 # load 5(read float instruction) into register $v0

syscall

add $t6, $t6, $v0 #puts value of wanted spot in $a3

la $a0, txt8 # copies address of txt8 into $a0

li $v0, 4 # loads print string instruction into $v0

syscall

li $v0, 5 # load 5(read float instruction) into register $v0

syscall

#add $t7, $t7, $v0 # puts value for spot in array in $t7

##############################################

#li $t0, 5 # this is my representation of "i"

#la $t2, numbers

sll $t1, $t6, 2 # scale by 4

addu $t1, $t1, $a1 # add offset and base together

sw $t1, ($v0) # fetch the data

##############################################

jal printArray

jal menu

menu:

la $a0, txt6 # copies address of txt6 into $a0

li $v0, 4 # loads print string instruction into $v0

syscall

li $v0, 5 # load 5(read float instruction) into register $v0

syscall

beq $v0, 1, replaceElement

beq $v0, 2, removemax # branches to remove max if user enters 2

beq $v0, 3, removemin # branches to remove min if user enters 3

beq $v0, 4, Exit1

syscall

Exit1:

jr $ra

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

Prepare a short profile of Henry words worth Longfellow?

Answered: 1 week ago

Question

What is RAM as far as telecommunication is concerned?

Answered: 1 week ago

Question

Question 1: What is reproductive system? Question 2: What is Semen?

Answered: 1 week ago

Question

Describe the sources of long term financing.

Answered: 1 week ago

Question

9. Describe the characteristics of power.

Answered: 1 week ago

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago