Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile code in C to MIPS assembly

I wrote a C program that I need to see it in MIPS assembly code.

How do I install or operate a software that takes *.c file to be *.txt or *.something_else to see its MIPS assembly code ?

My OS is Linux.

Thanks a lot !!

BTW my code is:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SIZE 128

int main ()

{
    char mychar , string [SIZE];
    int i;
    int count =0 ;  

    printf ("Please enter your string: \n\n");
    fgets (string, SIZE, stdin);

    printf ("Please enter char to find: ");
    mychar = getchar();

    for (i=0 ; string[i] != '\0' ; i++ )
        if ( string[i]  == mychar )
            count++;

    printf ("The char %c appears %d times\n" ,mychar ,count);


    return 0;
}
like image 475
C_guy Avatar asked Dec 01 '25 14:12

C_guy


2 Answers

What you want is a MIPS cross-compiler, unless you're running Linux on a MIPS box, in which case you want a regular MIPS compiler. Here is a howto for setting up a cross compiler on Linux.

Once you've compiled it, you'll want to see the MIPS disassembly. objdump can help you there.

like image 139
nmichaels Avatar answered Dec 03 '25 10:12

nmichaels


You need to install a MIPS cross-compile library, and then you need to pass -S and one of the -march=mips* options to gcc.

like image 23
Ignacio Vazquez-Abrams Avatar answered Dec 03 '25 11:12

Ignacio Vazquez-Abrams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!