Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Substring in Mips

Tags:

substring

mips

How to get a substring of a string in Mips?

like image 851
Yanh Huan Avatar asked Dec 04 '25 06:12

Yanh Huan


1 Answers

Just get a cross compiler, code it in C and get the output assembly. You can use the -S option if using gcc.

For example:

root@:~/stackoverflow# cat strstr.c

    #include <string.h>

    /*
     * Find the first occurrence of find in s.
     */
    char *
    strstr(const char *s, const char *find)
    {
            char c, sc;
            size_t len;


            if ((c = *find++) != 0) {
                    len = strlen(find);
                    do {
                            do {
                                    if ((sc = *s++) == 0)
                                            return (NULL);
                            } while (sc != c);
                    } while (strncmp(s, find, len) != 0);
                    s--;
            }
            return (s);
    }

root@:~/stackoverflow# gcc -S -mrnames strstr.c -o strstr.s

    strstr.c: In function `strstr':
    strstr.c:23: warning: return discards qualifiers from pointer target type

root@:~/stackoverflow#

like image 172
Tom Avatar answered Dec 06 '25 08:12

Tom