Simple inline Sparc assembly example : set input and get output - right syntax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I try to do a simple example to insert, into a C code, a piece of Sparc
assembly 32 bits; this little code performs an incrementation on the
variable  "sum".

The code is :

  *  #include <stdio.h>
    #include <sys/time.h>
    #include <unistd.h>
    
    int n;
    int sum;
    
    int main ()
    {
      n = 100;
      sum = 0;
    
      struct timeval tv1, tv2;
      long long diff;
    
      gettimeofday (&tv1, NULL);
    
      asm volatile ("set sum, %g1\n\t" \
                    "set n, %g3\n" \
                    "loop:\n\t" \
                    "add %g1, 1, %g2\n\t" \
                    "sub %g3, 1, %g4\n\t" \
                    "bne loop\n\t" \
                    "nop\n\t" \
                    : "=r" (sum)
                    : "r" (n)
                    );
    
      gettimeofday (&tv2, NULL);
    
      diff = (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec -
tv1.tv_usec);
      printf ("Elapsed time = %d usec\n", diff);
    
      printf ("Sum = %d\n", sum);
    
      return 0;
    
    }*

Unfortunately, compilation with gcc4.1.2 produces the following errors :

    *loop_dev_for-assembly_code.c: In function #main#:
    loop_dev_for-assembly_code.c:18: error: invalid 'asm': invalid operand
output code
    loop_dev_for-assembly_code.c:18: error: invalid 'asm': operand number
out of range
    loop_dev_for-assembly_code.c:18: error: invalid 'asm': invalid operand
output code
    loop_dev_for-assembly_code.c:18: error: invalid 'asm': operand number
out of range
    loop_dev_for-assembly_code.c:18: error: invalid 'asm': operand number
out of range
    loop_dev_for-assembly_code.c:18: error: invalid 'asm': operand number
out of range
*

It seems the line 18 corresponds to "`asm volatile ("set sum, %g1\n\t" \
...`".

But I don't know how to circumvent these errors. It may come from the
variable `sum` which is set to `%g1` register.

About the links between variable belonging to C code and variable localted
in Assembly code part. I have also seen, for inputs and outputs parameters,
the syntax `"=g"` (output paramter ??), `"g"` (input parameter) : I think
that it corresponds to different registers between the 2 syntax.

if someone could help me to find the main mistakes that I have made in this
inline assembly code and some clues to use right syntax for the link between
input and output variables. 

Thanks for your help, regards.




--
View this message in context: http://gcc.1065356.n8.nabble.com/Simple-inline-Sparc-assembly-example-set-input-and-get-output-right-syntax-tp1376842.html
Sent from the gcc - Help mailing list archive at Nabble.com.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux