-1

I would like to get linked with a C compiler.

  • What is the convention to pass values to function using MIPS?
  • Is there a coding convention or RFC-Like document?
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
ALUFTW
  • 1,914
  • 13
  • 24
  • 1
    Did you do any research? Have you for example checked [wikipedia](https://en.wikipedia.org/wiki/Calling_convention#MIPS) at least? – Jester May 18 '16 at 00:17

1 Answers1

2

There is no correct way, with assembly language you can do whatever you want.

But if you are trying to link with a C compiler for example then, why dont you just try using the compiler you have? It obviously can create objects that link with other objects made by the same compiler.

extern unsigned int more_fun ( unsigned int a, unsigned int b );
unsigned int fun ( unsigned int a, unsigned int b )
{
    unsigned int c;
    c = more_fun(a,b+7);
    return(c+a+5);
}

this is what mine produces (with certain flags), object not linked...

00000000 <fun>:
   0:   27bdffe8    addiu   sp,sp,-24
   4:   24a50007    addiu   a1,a1,7
   8:   afbf0014    sw  ra,20(sp)
   c:   afb00010    sw  s0,16(sp)
  10:   0c000000    jal 0 <fun>
  14:   00808025    move    s0,a0
  18:   8fbf0014    lw  ra,20(sp)
  1c:   26100005    addiu   s0,s0,5
  20:   02021021    addu    v0,s0,v0
  24:   8fb00010    lw  s0,16(sp)
  28:   03e00008    jr  ra
  2c:   27bd0018    addiu   sp,sp,24

I think that spells it out, and gives you a way to figure it out for more complicated parameters or return values. I prefer to compile and disassemble to compile to assembly. Much easier to read and actually see what is produced. YMMV.

old_timer
  • 69,149
  • 8
  • 89
  • 168
  • You can get rid of the "noise" in normal gcc `-S` output in a few ways. The easiest is usually using Godbolt, which has MIPS and MIPS64 gcc5.4 installed. e.g. https://godbolt.org/g/JrbUQD. Unfortunately its usual filtering of assembler directives and comments seems to not be doing a good job on the 32-bit output, and the function-call is loading the function address into a register instead of using a direct jal. I guess there's a code-model option I don't know about? Anyway, see also http://stackoverflow.com/questions/38552116/how-to-remove-noise-from-gcc-clang-assembly-output. – Peter Cordes Nov 29 '16 at 05:11
  • Although assemble + disassemble may still be better for MIPS, since gcc output uses numbered registers like `$31` instead of `ra`. – Peter Cordes Nov 29 '16 at 05:13
  • I build my own binutils and change it from the s0,a0,ra (ewww) to register numbers with a simple patch...I think arm binutils now needs the same patch. – old_timer Nov 29 '16 at 20:04