Motorola SC140 user manual Fractional Arithmetic

Page 7

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

Image 7
Contents Motorola Typical development process is represented in Figure Compiler Hands On File I/O ExerciseGood To Know Interpretation of 16-bit Integer and Fractional Data Values Integer and Fractional Arithmetic ExerciseInteger Arithmetic Compiler Support on StarCoreFractional Arithmetic Good To Know Local Optimization Local Versus Global Optimization ExerciseCompiler Support on StarCore StarCore C Compiler Global Optimization Local OptimizationMemory Alignment Exercise AA BB CC DD First Code Section Second Code Section Split Summation Exercise Code Generated Assembly Code = ∑ a i x n For 0 ≤ n L Multi-Sample ExerciseIntermediate Version Compromise Between Memory and Speed Further Speed Optimization Control Code The True Bit Exercise Save Ex7.c as Ex71.c Calling an Assembly Routine From C Exercise Current Following output should be displayed Challenge Introduction to the SC140 Tools Solutions to ExercisesAligned ExerciseExpected Motorola INC Intermediate version Compromise between Memory and Speed Compiler Support on StarCore Further Optimizing the Speed Compiler Support on StarCore Compiler Support on StarCore Motorola INC Zoffset equ Moffset equ Exercise Compiler Support on StarCore Compiler Support on StarCore AN2009/D