Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello there, I\'m working on translating C++ to MIPS but having some difficultie

ID: 3543331 • Letter: H

Question

Hello there,

I'm working on translating C++ to MIPS but having some difficulties. Followes is both the c++ code and my attempted solution.


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

#include <iostream>

using namespace std;


int byteToDec(int arg0, char *arg1);

void IPtoDD(int arg0, char *arg1);


int main()

{

    int num = 0x8234000a;

    char str[16];

    

    IPtoDD(num, str);

    cout << str << endl;


    num = 0xab0932ba;

    

    cout << num << endl;

    IPtoDD(num, str);

    cout << str << endl;

    

    system("PAUSE");

}


int byteToDec(int arg0, char *arg1)

{

    int temp, flag = 0, count = 0;


    if (arg0==0)

    {

        *arg1 = '0';

        return 1;

    }

    else

    {

        temp = arg0/100;


        if (temp != 0)

        {

            *arg1++ = (char) temp + 0x30;

            count++;

            flag = 1;

        }


        temp = (arg0 % 100) / 10;


        if ((flag!=0) || (temp != 0))

        {

            *arg1++ = (char) temp + 0x30;

            count++;

        }


        temp = arg0 % 10;

        *arg1 = (char) temp + 0x30;

        count++;


        return count;

    }

}


void IPtoDD(int arg0, char *arg1)

{

    int temp, numChar, shift = 24;


    for (int i=0; i<4; i++)

    {

        temp = arg0 >> shift;

        temp = temp & 0x000000ff;

        numChar = byteToDec(temp,arg1);

        arg1 += numChar;

        *arg1++ = '.';

        shift -= 8;

    }


    arg1--;

    *arg1 = 0;

    

    return;

}

Explanation / Answer

?

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote