Compiler Support on StarCore

5.Open the generated assembly file Ex2.sl and look at the integer instructions within the loop.

6.In the box provided here, write down the integer C code and the generated assembly instructions for the loop. Notice that the first data load is automatically pipelined in the software.

Integer Arithmetic

C code

Generated Assembly code

Fractional Arithmetic

7.For fractional arithmetic, copy and paste the loop of Ex2.c.

The first loop remains unchanged and performs integer calculation while the second loop is modified to perform fractional arithmetic.

8.In the second loop, replace the integer arithmetic operation with the appropriate fractional intrinsic.

Remember, fractional arithmetic is performed using C compiler intrinsics. In this example, the L_mac intrinsic is used. Its prototype is: long int L_mac(long int, short int, short int). Therefore, the code modifications should be:

a.Create a new variable “fres” of type “long int.”

b.Replace “res += x[i] * x[i];” with the instruction “fres = L_mac(fres,x[i],x[i]).”

c.Include the file prototype.h, which contains all the intrinsics prototypes.

d.Add another printf statement to print out the fractional result. The result is still a “long int,” so “%d” should still be used.

9.Recompile the code with the -Soption and look at the generated assembly file Ex2.sl within the second loop.

10.In the box provided below, write the fractional C code and the generated assembly instructions for that loop.

Fractional Arithmetic

C code

Generated Assembly code

Introduction to the SC140 Tools

7

Page 7
Image 7
Motorola SC140 user manual Fractional Arithmetic