Question

Need to implement an IterativeMax function in assembly language using the MIPS calling convention. IterativeMax take...

Need to implement an IterativeMax function in assembly language using the MIPS calling convention.

IterativeMax take two arguments:

The address of an array of word-long (four byte) signed integers, held in $a0.

The length of the array as an unsigned integer, held in $a1.

The main purpose of the function is to determine which element of the provided array is the largest (i.e., the maximum element in the array). This is achieved by going through the array one element at a time. On each element, the function should do the following, in order:

1. Print out the current element of the array

2. Determine what the new maximal element of the array is so far. For example, if the old maximum was 5 and 7 was just observed in the array, then the maximum should be set to 7.

3. Print out the new maximum element of the array so far (after setting the new maximum in the previous step)

(code should work with any other valid (non-empty) array)

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

Please find the code below::

.data
A: .word 110,160,20,70,60,140,150, 80, 90,100, 10, 30, 40,120,130,50
size: .word 16 # lenqth of array A
max: .word 0
prompt: .asciiz " Current Element : "
prompt1: .asciiz " Maximum Element so far : "
prompt2: .asciiz " Maximum Element is : "
.text

la $a0,A   #store address of A
lw $a1,size #store size of array

jal IterativeMax
sw $t6,max
li $v0,4
la $a0,prompt2 #it will print prompt
syscall
li $v0,1 #print max
lw $a0,max
syscall
li $v0,10 #Terminate execution
syscall


##################
IterativeMax:
li $s0,0
li $t6,0 #store max as 0
move $t7,$a0 #get array address
maxLoop:
mul $t0,$s0,4
add $t0,$t0,$t7
lw $t0,($t0)

li $v0,4
la $a0,prompt #it will print prompt
syscall
li $v0,1
move $a0,$t0
syscall
blt $t0,$t6,skipMax
move $t6,$t0 #store result in v0
skipMax:

li $v0,4
la $a0,prompt1 #it will print prompt
syscall
li $v0,1
move $a0,$t6
syscall
add $s0,$s0,1 #increament
blt $s0,$a1,maxLoop
jr $ra


output:

Add a comment
Know the answer?
Add Answer to:
Need to implement an IterativeMax function in assembly language using the MIPS calling convention. IterativeMax take...
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
  • 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...

  • How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...

    How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++ .data # Defines variable section of an assembly routine. array: .word x, x, x, x, x, x, x, x, x, x # Define a variable named array as a word (integer) array # with 10 unsorted integer numbers of your own. # After your program has run, the integers in this array # should be sorted. .text # Defines the start of the code...

  • Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how...

    Subroutines in MIPS Determines the minimum of two integers Functions within the MIPS slides describe how one can use subroutines (also called procedures, functions, and methods) in MIPS. Because of the importance of subroutines in modern programming, most hardware designers include mechanisms to help programmers. In a high-level language like C or Java, most of the details of subroutine calling are hidden from the programmer. MIPS has special registers to send information to and from a subroutine. The registers $a0,...

  • 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...

  • daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function....

    daily21. Computing 1. C programming Please provide comments and write pre-condition and post-condition for the function. Description Create a project called Daily21. Add a source file called daily21.c into the project. In this exercise, you will practice working with an array of integers. In the main function, you first need to create an integer array with 10 elements in t. Use a loop to read 10 integers from the user and store the values to the array (in the order...

  • 1. Write a program in Assembly language using MIPS instruction set that reads two integer numbers...

    1. Write a program in Assembly language using MIPS instruction set that reads two integer numbers from the user named as start and end number and finds out all the prime numbers between start and end (including start and end). Your program should do the validation of both the numbers as follows: i. start number must be smaller or equal to the end number. ii. Both numbers must be positive. iii. The maximum value for the end number is 10000...

  • Please help me with this in C# language. Returning an array from a function The goal...

    Please help me with this in C# language. Returning an array from a function The goal for this exercise is to make sure that you return an array from a method (as a return value). Also: to give you more practice creating and using methods/functions. What you need to do for this exercise: In the starter project, add code to the Returning_An_Array class, so that the RunExercise method does the following: Declare an integer array variable, but DO NOT ALLOCATE...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations // ...

    // =================== Support Code ================= // Queue // // // // - Implement each of the functions to create a working circular queue. // - Do not change any of the function declarations //   - (i.e. queue_t* create_queue(unsigned int _capacity) should not have additional arguments) // - You should not have any 'printf' statements in your queue functions. //   - (You may consider using these printf statements to debug, but they should be removed from your final version) // ==================================================...

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
ADVERTISEMENT