In this project you are asked to write MIPS code to finish a

In this project, you are asked to write MIPS code to finish all the functions listed in project2.asm. In project2.asm, an array A of 10 integers are given at the beginning (make sure do not change these integers):

34, 5, 11, -12, 60, -2, 14, 71, 13, -27

The finished project2.asm should be filled with your MIPS code in the specified space to implement the given C code and with the finished code, it reads in one index i (the range of the index is between 0 and 9) from the console, then find the minimum value (MIN) and the maximum value (MAX) in the subarray A[0..i], i.e., A[0] through A[i]. You need to use branch instructions, as well as other MIPS instructions we learned for memory and register operations. In project2.asm, I have provided code to read the index i and print out MIN and MAX. Please read the code in project2.asm carefully before working on this project.

A sample result:
--------------------------------------------
Index i [0~9]:
4

MIN=-12
MAX=60
---------------------------------------------

For project submission, please submit your completed project2.asm and make sure it can be compiled and executed in Mars.

CODE TO USE (Copy and paste the following code)...

.data
baseadd: .word 34, 5, 11, -12, 60, -2, 14, 71, 13, -27

string1: .asciiz \"Index i [0~9]:\ \"
string2: .asciiz \"\ MIN=\"
string3: .asciiz \"\ MAX=\"

.text
main:  
       # Input i to $s1
       addi $v0, $zero, 4 # code for printing string is 4
       la $a0, string1    # load address of string to be printed into $a0
       syscall    # call operating system
       addi $v0, $zero, 5 # code for reading integer is 5
        syscall    # call operating system
        add $s1, $v0, $zero     # i in $s1
      
        #baseadd of the array to $s5
        la $s5, baseadd   
       
        #Load A[0] to initialize MIN ($s6) and MAX ($s7)
        lw $s6, ($s5)
        lw $s7, ($s5)   
      
       # initialize j=0 (j in $t1)
       add $t1, $zero, $zero
      
       # You write code here to implement the following C code.
        # This will find the MIN ($s6) and MAX ($s7)
        # in the array from A[0] through A[i].
        # Note that you need to use lw to load A[j].

        # while (j<=i)
       #   {
       #   if A[j]<MIN
       #       MIN=A[j];
       #   if A[j]>MAX
       #       MAX=A[j];
       #   j=j+1;
       #   }  

        # Print MIN from s6  
Exit:    addi $v0, $zero, 4 # code for printing string is 4
       la $a0, string2    # load address of string to be printed into $a0
       syscall    # call operating system                                                                                                                     
       add $a0, $s6, $zero  
       addi $v0,$zero,1   # prints integer
       syscall

       # Print MAX from s7  
        addi $v0, $zero, 4 # code for printing string is 4
       la $a0, string3    # load address of string to be printed into $a0
       syscall    # call operating system                                                                                                                     
       add $a0, $s7, $zero  
       addi $v0,$zero,1   # prints integer
       syscall

       # exit  
       addi $v0, $zero, 10
       syscall

Solution

.data
baseadd: .word 34, 5, 11, -12, 60, -2, 14, 71, 13, -27
string1: .asciiz \"Index i [0~9]:\ \"
string2: .asciiz \"Index j [0~9]:\ \"
string3: .asciiz \"\ A[i]=\"
string4: .asciiz \"\ A[j]=\"
string5: .asciiz \"\ A[i]+A[j]=\"
string6: .asciiz \"\ A[i]-A[j]=\"

.text
main:

   li $v0,4
la $a0,string1
syscall
  
li $v0, 5
syscall
move $s1, $v0


li $v0,4
la $a0,string2   
syscall

li $v0, 5
syscall
move $s2, $v0

la $s5, baseadd
la $s6, baseadd    

li $t1,0
li $t2,0  
  
loop:
   lw $s3,0($s5)
       addi $s5,$s5,4
   beq $t1,$s1,loop1
       addi $t1,$t1,1
       j loop
      
   loop1:
   lw $s4,0($s6)
       add $s6,$s6,4
   beq $t2,$s2,loop2
       addi $t2,$t2,1
       j loop1
      
   loop2:
      
       add $t1,$s3,$s4
       sub $t2,$s3,$s4
      
   li $v0,4
la $a0,string3   
syscall
      
   li $v0, 1
move $a0, $s3
syscall
     
   li $v0,4
la $a0,string4   
syscall

   li $v0, 1
move $a0, $s4
syscall
     
   li $v0,4
la $a0,string5   
syscall
     
     
     
   li $v0, 1
move $a0, $t1
syscall
     
   li $v0,4
la $a0,string6   
syscall
     
   li $v0, 1
move $a0, $t2
syscall
     
li $v0, 10
syscall

In this project, you are asked to write MIPS code to finish all the functions listed in project2.asm. In project2.asm, an array A of 10 integers are given at th
In this project, you are asked to write MIPS code to finish all the functions listed in project2.asm. In project2.asm, an array A of 10 integers are given at th
In this project, you are asked to write MIPS code to finish all the functions listed in project2.asm. In project2.asm, an array A of 10 integers are given at th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site