I tried gcc -S Source.c
but I must edit produced assembly file Source.s.
How should I edit it to work on Spim?

- 1
- 1
-
I assume you're using the gcc MIPS cross compiler (so you're not emitting x86 assembly), correct? Then `gcc -S` is definitely a good start. And yes, you'll then need to hand-edit the code for SPIM: https://stackoverflow.com/a/3231839/421195. See also: https://stackoverflow.com/q/4175450/421195 – paulsm4 Apr 04 '21 at 03:47
-
Yes, exactly. I tried gcc -S but I do not know how can I edit this produced assembly code for Spim, produced assembly file has too many differences from MIPS. – seydanurdemir Apr 04 '21 at 04:07
-
"gcc" can emit assembly code for many different architectures. If you're on a PC, the default architecture is Intel x86/i386. It sounds like that's what's happening here. If so, you can easily download a gcc "cross compiler" for MIPS. This will generate MIPS assembly. It will be *CLOSE* to what you need for SPIM ... but even so, you'll still have to hand-edit the GCC/MIPS assembly code. Please refer to the links I cited for getting a copy of the gcc MIPS cross compiler. – paulsm4 Apr 04 '21 at 19:15
-
Yes I got it, actually I hope to find any other solution, may be any command line argument or any environment for this, but seems there is no solution this way, may I should look for cross compilers. Thank for your reply. – seydanurdemir Apr 04 '21 at 23:28
2 Answers
There isn't any official C to MIPS Assembly compiler but if you insist then give this github a try

- 177
- 1
- 8
-
Thank you for your reply, I was looking for a solution like this, after could not find any command line argument. I think it will be useful. – seydanurdemir Apr 06 '21 at 16:39
-
-
I voted but I am the new one here, so it does not seem I guess. Thank you again. – seydanurdemir Apr 09 '21 at 00:34
try gcc-mips-linux-gnu
. first, install it , if you are on Ubuntu you can use sudo apt install gcc-mips-linux-gnu
. after that install sudo apt-get install build-essential gcc-mipsel-linux-gnu
.
now you can try mipsel-linux-gnu-gcc -fverbose-asm -S myprog.c
to compile c file. if you didn't have any issue while compiling then you can see through myprog.s to see assembly instructions,it might differ with code can run on simp , specially in syscall
instruction that simp have but it is n't identical to it in code that have built with GCC because it have made to run on mips architecture linux system not simp.
for further information take a look at this topic , it isn't for working on spim but it might help : link

- 1
-
As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 13 '22 at 20:01