Executing MIPS (LLVM) generated code on spim simulator fails

0

I have a simple C source file that prints prime numbers, and I compile it to MIPS with:

$ clang -target mipsel-linux-gnu main.c -S -o main.s

When I try to run it on the spim simulator it fails:

$ spim -f main.s
SPIM Version 8.0 of January 8, 2010
Copyright 1990-2010, James R. Larus.
All Rights Reserved.
See the file README for a full copyright notice.
Loaded: /usr/lib/spim/exceptions.s
spim: (parser) syntax error on line 3 of file main.s
        .abicalls
                ^
The following symbols are undefined:
main

Instruction references undefined symbol at 0x00400014
[0x00400014]    0x0c000000  jal 0x00000000 [main]           ; 188: jal main

Here is my C source file for completion:

#include <stdio.h>

int IsPrime(int p)
{
    int i;
    int j;

    for (i=2;i<p;i++)
    {
        for (j=2;j<p;j++)
        {
            if (i*j == p)
            {
                return 0;
            }
        }
    }
    return 1;
}
void PrintPrimes(int start,int end)
{
    int i=0;

    for (i=start;i<=end;i++)
    {
        if (IsPrime(i))
        {
            printf("%d\n",i);
        }
    }
}
int main(int argc, char **argv)
{
    PrintPrimes(2,100);
    return 0;
}
clang
llvm
mips
abi
asked on Stack Overflow Dec 24, 2018 by OrenIshShalom • edited Dec 24, 2018 by OrenIshShalom

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0