Question

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 section for the program .

.globl main main:

la $a0, array # Moves the address of array into register $a0.

# Set argument 1 to the array.

addi $a1, $zero, 10   # Set argument 2 to (n = 10)

jal pancakeSort # Call pancakeSort
li $v0, 10 # Terminate program run
syscall

The C-code is

// Reverses arr[0..i]
void flip(int arr[], int k)  {
    int temp, start = 0;
    while (start < k) {
        temp = arr[start];
        arr[start] = arr[k];
        arr[k] = temp;
        start++;

k--; }

}

// Returns index of the maximum element in arr[0..n-1] int findMax(int arr[], int n) {

int max = arr[0];
intmi =0; for(inti=1;i<n;++i) {

if (arr[i] > arr[mi]) {
            mi = i;

} }

return mi; }

// The main function that sorts given array using flip operations. void pancakeSort(int *arr, int n) {

int size, i;

    printf(“\nThe original list is “);
    for(i = 0; i < n, i++)
        printf(“%d “, arr[i]);
    // Start from the complete  array and one by one
    // reduce current size   by one
    for (size = n; size > 1; size--) {

// Find index of the maximum element in arr[0..size-1] int mi = findMax(arr, size);

        // Move the maximum element to end of current array
        // if it's not already at the end.
        if (mi != size) {

// To move at the end, first move maximum number to beginning flip(arr, mi);

// Now move the maximum number to end by reversing current array

            flip(arr, size-1);
        }

}

    printf(“\nThe sorted list is “);
    for(i = 0; i < n, i++)
        printf(“%d “, arr[i]);
}
0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...
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
  • MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4,...

    MIPS assembly language Implement the following code in MIPS int array [ ] {2, 3, 4, 5, 6); int main) int num, position; scanf("%d",&num) ; position search(array, printf("The position is: num, 5); %d\n",positio int search(int array, int num, int size int position =-1; for(int i-0;i<size; i++) if(array [i]=num) { position-i; break; return position; Register map $s1: position $a0: array address $a1: num . $a2: size . $VO: return value

  • How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include...

    How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include void program_one (); void program_two (); void program_three (); void program_four(); void program_five(); int main() { int menu_option = 0; while (menu_option != 9) { printf(" = 1\n"); //Change this to your first program name. Nothing else. printf(" = 2\n"); //Change this to your second program name. Nothing else. printf(" = 3\n"); //Change this to your third program name. Nothing else. printf(" =...

  • I need some with this program, please look at the changes I need closely. Its running...

    I need some with this program, please look at the changes I need closely. Its running correctly, but I need to do a few adjustments here is the list of changes I need: 1. All of the integers on a single line, sorted in ascending order. 2. The median value of the sorted array on a single line 3. The average of the sorted array on a single line Here is the program: #include<stdio.h> #include<stdlib.h> /* This places the Adds...

  • I need to program 3 and add to program 2 bellows: Add the merge sort and...

    I need to program 3 and add to program 2 bellows: Add the merge sort and quick sort to program 2 and do the same timings, now with all 5 sorts and a 100,000 element array. Display the timing results from the sorts. DO NOT display the array. ____________________>>>>>>>>>>>>>>>>>>>>___________________________ (This is program 2 code that I did : ) ---->>>>>> code bellow from program 2 java program - Algorithms Write a program that randomly generates 100,000 integers into an array....

  • MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i...

    MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i int x=5 ; int y: y function(x); printf "yd",y); return 0; int function (int a) return 3*a+5; Assumptions: . Place arguments in $a0-$a3 . Place return values in $vO-$v1 Return address saved automatically in $ra . lgnore the stack for this example. (Thus, the function will destroy registers used by calling function

  • c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each...

    c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each size Im trying to do time analysis for Quick sort but i keep getting time = 0 also i want edit the program to test different random sizes of the array and give me the time in a...

  • its brr[8] (40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program...

    its brr[8] (40%) Convert the following C-pseudo code into MIPS assembly code as a standalone program (including main and all the required directives). You can use any register. You must comply, however, with the convention of register usage. Before writing your code perform an explicit register allocation phase. Note that the C snippet is int arr[8]; int brr[4]-{1, 2, 3, 4, 5, 6, 7, 8) int i-8; while (i>-0) arrli]-brr[i-); (40%) Convert the following C-pseudo code into MIPS assembly code...

  • C program-- the output is not right please help me to correct it. #include <stdio.h> int...

    C program-- the output is not right please help me to correct it. #include <stdio.h> int main() { int arr[100]; int i,j,n,p,value,temp; printf("Enter the number of elements in the array: \n "); scanf("%d",&n); printf("Enter %d elements in the array: \n",n); for(i=0;i<n;i++) { printf("\nelement %d: ",i); scanf("\n%d",&arr[i]); } printf("\nEnter the value to be inserted: \n "); scanf("\n%d",&value); printf("The exist array is: \n"); for(i=0;i<n;i++) { printf("%d",arr[i]); } p=i; for(i=0;i<n;i++) if(value<arr[i] ) { p = i; break; } arr[p]=value; printf("\n"); for (i =...

  • In mips code please Implement the following C code in MAL and develop a small main...

    In mips code please Implement the following C code in MAL and develop a small main program that tests your implementation on an integer array. You must use nested procedures in your implementation. int getArrAvg (int Arr) int sum0 for (int i = 0; i < 10; i += 1) sum-addfn (sum, Arr[i]) return sum/10; int addfn (int a, int b) return ab;

  • Write a C program by completing the following skeleton program. /* file minmax.c  **************************************** *   ...

    Write a C program by completing the following skeleton program. /* file minmax.c  **************************************** *        a C program skeleton for the problem *        Find the minimum and maximum values in an array **********************************************************/ #include <stdio.h> /* DATA segment: Global variables */ #define SIZE 10         int arr[SIZE] = { -5, 0xffffface, 0x31, 52, 054, /* base 8 */                         0,...

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