convert c++ to mips assembly code online code example
Example 1: convert c++ to mips assembly code online
#include <iostream>
using namespace std;
void heapify(int arr[], int n, int i)
{
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
if (l < n && arr[l] > arr[largest])
largest = l;
if (r < n && arr[r] > arr[largest])
largest = r;
if (largest != i) {
swap(arr[i], arr[largest]);
heapify(arr, n, largest);
}
}
void deleteRoot(int arr[], int& n)
{
int lastElement = arr[n - 1];
arr[0] = lastElement;
n = n - 1;
heapify(arr, n, 0);
}
void printArray(int arr[], int n)
{
for (int i = 0; i < n; ++i)
cout << arr[i] << " ";
cout << "\n";
}
int main()
{
int arr[] = { 10, 5, 3, 2, 4 };
int n = sizeof(arr) / sizeof(arr[0]);
deleteRoot(arr, n);
printArray(arr, n);
return 0;
}
Example 2: convert c++ to mips assembly code online
#include <iostream>
using namespace std;
void heapify(int arr[], int n, int i)
{
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;
if (l < n && arr[l] > arr[largest])
largest = l;
if (r < n && arr[r] > arr[largest])
largest = r;
if (largest != i) {
swap(arr[i], arr[largest]);
heapify(arr, n, largest);
}
}
void deleteRoot(int arr[], int& n)
{
int lastElement = arr[n - 1];
arr[0] = lastElement;
n = n - 1;
heapify(arr, n, 0);
}
void printArray(int arr[], int n)
{
for (int i = 0; i < n; ++i)
cout << arr[i] << " ";
cout << "\n";
}
int main()
{
int arr[] = { 10, 5, 3, 2, 4 };
int n = sizeof(arr) / sizeof(arr[0]);
deleteRoot(arr, n);
printArray(arr, n);
return 0;
}
Example 3: convert c++ to mips assembly code online
# Not sure what to do now? Enter your mips code here
Example 4: convert c++ to mips assembly code online
#include <stdio.h>
int main() {
int i;
int sum = 0;
for (i=0; i<=100; i++)
sum = sum + i*i;
printf("The sum from 0 to 100 is %d\n",sum);