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]); }
How can I convert the following C code to MIPS Assembly? +++++++++++++++++++++++++++++++++ MIPS main program ++++++++++++++++++++++++++++++++...
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
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
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...
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 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 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....
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 MIPS assembly code that corresponds to the following C code. Note: use the stack to store all register values that you use in the procedures. int aver(int * array, int N){ int i, sum = 0; for ( i=0;i i<N; i++) sum += array[i]; return sum/N;} int Max( int * array, int N){ int i, Maximum = array[i]; for ( i = 1; i< N; i++) if ( array[i] > Maximum) Maximum = array[i]; return Maximum; } int...
Consider the following code C++ like program: int i, j, arr[5]; //arr is an array starting at index 0 void exchange(int x, int y) { int temp:= x; x:= y; y:= temp; } main(){ for (j = 0; j < 5; j++) arr[j]:= j; i:= 1; exchange(i, arr[i+1]); output(i, arr[2]); //print i and arr[2] } What is the output of the code if both parameters in function swapping are passed by: a- value? b- reference? c- value-result?
Turn the Following c-code into MIPS assembly code. You are given the main procedure which calls multiply. You are also given the argument registers to be used. /* C-program */ int multiply (int number, int times) { int f; f = number * times return f; } # MIPS PROGRAM # assumes we have called the program leaf_example # $a0=number, $a1=times, $s0=f main: $addi $a0,$zero,3 $addi $a1,$zero,2 jal multiply # place the address into $ra j EXIT2 EXIT2: j OS...