Question

1- Write a MIPS assembly program to initialize register Ss0 to 8, register Ssl to 12, regis- ter Ss2 to 5, and register Ss3 t

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

Screenshot

Edlt Execute mips1 asin 05et paressters For hinction cel O Type hene to search A40-14-211-----------------------------------------------------------------------

Program

#Declaration part
.data
     array: .space 16
#Program starts here
.text
     #Assign values
     addiu $s0,$0,8
     addiu $s1,$0,12
     addiu $s2,$0,5
     addiu $s3,$0,2
     addiu $t0,$0,4
     #Get address of the array
     la $t1,array
     #Insert values into array
     sw $s0,0($t1)
     sw $s1,4($t1)
     sw $s2,8($t1)
     sw $s3,12($t1)
     #Set parameters for function call
     addiu $a1,$0,4
     la $a0,array
     #Call sortfunction
     jal selectionSort
     #Print sorted array
     la $t0,array
loop:
    beq $a1,0,exit
    lw $a0,($t0)
    li $v0,1
    syscall
    li $v0,11
    li $a0,32
    syscall
    addiu $a1,$a1,-1
    addiu $t0,$t0,4
    j loop
#End of the program
exit:
    li $v0,10
    syscall
  
#Selection sort function
selectionSort:
     li $t0,0                       #for c
     li $t1,0                       #for d
     li $t2,0                       #for position
     move $t4,$a1                  #get array size in t4
     addi $t4,$t4,-1                #to get n-1
     move $s0,$a0                  #Get address of the array in s0
     move $s1,$a0                  #Get address of the array in s1
#c loop
firstLoop:
    beq $t0,$t4,returnSort        #for(int c=0;c<n-1;c++)
    lw $t5,($s0)                #value of index c into t5
    la $t2,($s0)                #set position=c
    addi $t1,$t0,1              #d=c+1
    addi $s0,$s0,4              #get next element as first element i j loop
    la $s1,($s0)                  #start fron c+1 index
#d loop
secondLoop:
     beq $t1,$a1,returnFirstLoop   #check n
     lw $t6,($s1)                  #comparison elemnt in t6
     ble $t5,$t6,next              #compare
#If greater
    la $t2,($s1)
    lw $t5,($t2)                #Get address of position,that is in t2
next:
    addi $t1,$t1,1             #Increment counter   
    addi $s1,$s1,4             #increment address to get next value
    j secondLoop                #Repeat
#Swap and return to first loop
returnFirstLoop:
    #store min in arr[i]
    addi $s0,$s0,-4         
    lw $t5,($s0)
    lw $t6,($t2)
    sw $t6,($s0)
    #store Arr[i] in arr[position]
    sw $t5,($t2)
    #Increment counter and address
    addi $t0,$t0,1
    addi $s0,$s0,4
    j firstLoop
#Reurn from function to main
returnSort:
    jr $ra

--------------------------------------------------------

Output

2 5 8 12

Add a comment
Know the answer?
Add Answer to:
1- Write a MIPS assembly program to initialize register Ss0 to 8, register Ssl to 12, regis- ter ...
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
  • 4. (3 pts. each) Write the hexadecimal representation of each MIPS assembly instruction: (4.1) sub $s3,...

    4. (3 pts. each) Write the hexadecimal representation of each MIPS assembly instruction: (4.1) sub $s3, $t1, $s2 (4.2) bne $t3, $t4, 18 (4.3) sll $s0, $t5, 2 5. (20 pts.) Consider the following C (or java) code: else f=f+2; By storing the value of j in Ss0, write a sequence of MIPS assembly instructions that will execute these lines of code for the following two cases: (5.1) assuming that the values of f, g and h are stored in...

  • ***Please give comments and show it running*** Create a MIPS program that gets a set of...

    ***Please give comments and show it running*** Create a MIPS program that gets a set of numbers from the user, sorts them using selection sort, and displays the sorted numbers on the screen. You should create a subprogram to do the selection sort, sending it the length and address of the array. This is the pseudo code for the structure the selection: for (int i = 0; i < aLength-1; i++) {     /* find the min element in the...

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

  • Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers

    Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...

  • 1. Write a Java program to implement Counting Sort and write a driver to test it....

    1. Write a Java program to implement Counting Sort and write a driver to test it. Note: use random number generator to generate your input with n = 10, 50, and 100. Verify that the running time is O(n). 2. Write a Java program to implement Bucket Sort and write a driver to test it. Note: use random number generator to generate your input with n = 10, 50, and 100. Verify that the running time is O(n). 3. In...

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

  • "you will write a program in C++ which will read a list of up to 100...

    "you will write a program in C++ which will read a list of up to 100 integers from the user, and print them back to the screen in sorted order. The user can indicate that they are done entering numbers by entering any negative value. Your program will store the entered numbers into an array. It will then sort the array, using the selection sort algorithm. After each iteration of the sorting algorithm, it will print the current state of...

  • PROJECT TASKS 1. Read the problem definition below and write a C++ program that implements your...

    PROJECT TASKS 1. Read the problem definition below and write a C++ program that implements your solution. Readability of the program will be graded based on variable naming, indentation, commenting (not too little and not too much), spacing, consistency, and styling in general including choice of functions. [NOTE: the code at the end of this document does not completely meet requirements as it uses many single letter variables and has no internal documentation. You need to improve it.] 2. Compile...

  • Objective Create a MIPS program in Mars to perform a sorting algorithm. Specification: 1) Download the...

    Objective Create a MIPS program in Mars to perform a sorting algorithm. Specification: 1) Download the file Assign2.asm. Read it and make sure it can be compiled and executed in Mars. 2) Write code to finish all the tasks listed in Assign2.asm. In Assign2.asm, an array‘a’ of ‘n’=11 integers are given at the beginning (make sure do not change these integers): 43, -5, 11, 12, 64, -7, 14, 71, 70, 13, -27 The finished Assign2.asm should be filled with your...

  • I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that...

    I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...

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