tags:

views:

40

answers:

2

Hi all,

I would like to do some "inline" assemly programming in Sparc and I am wondering how I can do that with register passing.

Best to explain my issue with a small example

int main()
{
   int a = 5;
   int b = 6;
   int res;

   asm_addition(a,b);

   printf("Result: %d\n", res);
   return(0);
}
  // My assembler addition

.global asm_addition            

.align  4   

    add rs1, rs2, rd
    restore

Does anyone know which registers I have to use so that the values a and b will be added? Finally, which register do I need to speficy for rd so that the result will then be printed put with the last printf statement following the assemly routine.

Thanks so much for some input!

A: 

The calling convention might depend on OS. I presume Solaris. Google for system v application binary interface sparc, the PDF is easy to find.

Full inline assembler documentation is buried somewhere in the SunStudio PDFs and not so easy to find. Officially it is also accessible via man -s 1 inline, though on my system I have to open the file manually. In the man page, look for "Coding Conventions for SPARC Systems".

Dummy00001
A: 

On Solaris the parameter are passed via register %o0 to %o5 then over the stack. If the called function is a leaf function (i.e. it doesn't call another function) the register window is not moved forward and the function accesses them directly via %o0 to %o5. If the register window is moved, then the function can access the parameters via the %i0 to %i5 registers. The return value goes the same way via %i0 in the callee which becomes %o0 in the caller. For floating point parameter they are handled via the FP registers but there you will have to read the document Dummy00001 pointed to.

tristopia