Question

The program I'm using is MIPS (mars) assembly; Write a program that in the main routine...

The program I'm using is MIPS (mars) assembly;

Write a program that in the main routine ask the user input n numbers(2<n<11) and pass n and array pointer

to FillArray to stores numbers in the array. Main again passes the pointer to AddElement Function to

add the elements of the array, and return the result back to main to print it.

                                                                    

                                                                    

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below:

.data
array : .space 1000
msg2: .asciiz "Enter element "
msg3: .asciiz " : "
msg4: .asciiz "Sum of array values is : "
msg6: .asciiz "Enter size of the array : "
size : .word 10
.text
main :
li   $v0, 4
la   $a0, msg6
syscall
li $v0, 5
syscall
sw $v0,size #store result to size
lw $s0,size #size of array
la $t0,array #save address of array
jal fillArray #call function fill array
jal addElement #call function fill array
li   $v0, 4
la   $a0, msg4
syscall
li $v0,1
move $a0,$t7
syscall


li $v0,10 #terminate call
syscall

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

fillArray :
li $s1,0 #index for loop
read_values_loop:
bge $s1,$s0,read_values_loop_exit

#show enter value message
li   $v0, 4
la   $a0, msg2
syscall

addi $s2,$s1,1
move $a0,$s2
li $v0,1
syscall

li   $v0, 4
la   $a0, msg3
syscall


li $v0, 5
syscall

mul $s2,$s1,4
add $s2,$s2,$t0 #load address of array element
sw $v0,0($s2) #save value to array

addi $s1,$s1,1
j read_values_loop
read_values_loop_exit:
jr $ra

addElement:
###################adding elements####################

li $s1,0 #index for loop
li $t7,0 #store sum of element
add_loop:
bge $s1,$s0,addLoopExit

mul $s2,$s1,4
add $s2,$s2,$t0 #load address of array element
lw $v0,0($s2) #load value to array

add $t7,$t7,$v0 #add number
addi $s1,$s1,1
j add_loop
addLoopExit:

jr $ra


Add a comment
Know the answer?
Add Answer to:
The program I'm using is MIPS (mars) assembly; Write a program that in the main routine...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers...

    Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers from user and stores all the numbers in the array intArray. Now, read another integer number N from the user, find the total number of array elements that are greater or equal to the number N, and the total number of array elements that are lower than the number N You must have two procedures: i. ReadIntegerArray: this procedure should read integer array elements...

  • Write a program that will do the following. The main function should ask the user how...

    Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...

  • MIPS CODE required to write an assembly program to find the maximum of an array of integers by...

    required to write an assembly program to find the maximum of anarray of integers by doing the following:1. Prompt user to input array size n (n <= 10)2. Prompt user to input element values of array A one by one3. Display the result on the console.This program must at least include one function. The main program will read the valuesof the array (as user inputs the element values) and stores them in the memory (datasegments section) and at the end...

  • MIPS 1(a): Using MARS (MIPS assembly simulator), write and debug a program with comments that will...

    MIPS 1(a): Using MARS (MIPS assembly simulator), write and debug a program with comments that will store words in a RAM array using the instruction sw and indirect addressing as specified in the data table below. Although the addresses and data are in given hexadecimal, your code will contain corresponding values in decimal. Use (268501056)_10 = (10010040)_16 as the base address of the array. Since the instruction sw and indirect addressing (using offsets) are needed to store the data in...

  • using Mips assembly to work on Mars simulator write a program that outputs the maximum and...

    using Mips assembly to work on Mars simulator write a program that outputs the maximum and minimum values of an entered array

  • Need to write a MIPS assembly program that finds the minimum and maximum and sum of...

    Need to write a MIPS assembly program that finds the minimum and maximum and sum of a stored array. It also finds the locations of the minimum and maximum. The interaction between the main program and the function is solely through the stack. The function stores $ra immediately after being called and restores $ra before returning to main. The main program reserves a static C like array (index starts from 0) of 10 elements and initializes it. The maximum should...

  • Introduction: In this lab, you will write a MIPS program to read in (up to) 50...

    Introduction: In this lab, you will write a MIPS program to read in (up to) 50 integer values from the user, store them in an array, print out the amay, one number per line, reverse the elements in the array and finally print out the elements in the just-reversed) array. Feel free to do this lab and all assembly programming labs) in Windows. You must use MARS Getting started: l. In MARS, create a new assembly file with the name...

  • please can you help me to solve it in Mips Assembly that works on Mars 4.5:...

    please can you help me to solve it in Mips Assembly that works on Mars 4.5: The function isEven, tests whether a number num is even or not. Write the main function of a program that reads a nuber num, calls the function isEven and then prints a message to indicate whether num is even or not. And then, ask the user if she wants to continue or not (Y/N). please answer it

  • MARS MIP assembly language quesion Write a program that reads 3 integers, print them, stores them,...

    MARS MIP assembly language quesion Write a program that reads 3 integers, print them, stores them, and add them together and print the result

  • Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to...

    Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to track the number of Deer Hunting Licenses issued in a county and the state. It will display a menu with 5 choices numbered 1-5. They are (1) update the count, (2) display the number of licenses already issued to a county whose number is input, (3) display the county number and the number of licenses already issued to a range of counties whose starting...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT