#include #include #include int main () { // Init sum int sum = 0; // Number of iterations int n = 100000000; struct timeval tv1, tv2; long int diff; // Start time gettimeofday (&tv1, NULL); // Loop with Sparc assembly into C source asm volatile ("clr %%g1\n\t" "clr %%g2\n\t" "mov %1, %%g1\n" // %1 = input parameter "loop:\n\t" "add %%g2, 1, %%g2\n\t" "subcc %%g1, 1, %%g1\n\t" "bne loop\n\t" "nop\n\t" "mov %%g2, %0\n" // %0 = output parameter : "=r" (sum) // output : "r" (n) // input : "g1", "g2"); // clobbers // End time gettimeofday (&tv2, NULL); // Compute runtime for loop diff = (tv2.tv_sec - tv1.tv_sec) * 1000000L + (tv2.tv_usec - tv1.tv_usec); // Print results printf ("Elapsed time = %d usec\n", diff); printf ("Sum = %ld\n", sum); return 0; }