Motorola SC140 user manual Integer and Fractional Arithmetic Exercise

Page 5

Hardware Support on StarCore

2 Integer and Fractional Arithmetic Exercise

One of the strengths of both the StarCore architecture and the StarCore compiler is the ability to perform both fractional and integer arithmetic. This exercise presents a reminder about integer and fractional arithmetic representation and then shows how to use the StarCore compiler fractional intrinsics. Values stored in memory or registers are interpreted differently depending on the operation performed. For integers, the binary point is considered to be immediately to the right of the LSB. For the fractional case, the binary point is considered to be immediately to the right of the MSB. Table 1 illustrates this for 16-bit data values.

Table 1. Interpretation of 16-bit Integer and Fractional Data Values

Binary Representation

Hexadecimal

Integer Value

Fractional value

Representation

(decimal)

(decimal)

 

 

 

 

 

 

 

 

 

0100 0000 0000 0000

0x4000

16384

0.5

 

 

 

 

0001 0000 0000 0000

0x1000

4096

0.125

 

 

 

 

0000 0000 0000 0000

0x0000

0

0.0

 

 

 

 

1100 0000 0000 0000

0xC000

-16384

-0.5

 

 

 

 

1111 0000 0000 0000

0xF000

-4096

-0.125

 

 

 

 

2.1 Hardware Support on StarCore

StarCore has a dual instruction set for operations that produce different results depending on whether fractional or integer arithmetic is used. The instruction set is complementary when an integer or a fractional operation leads to the same result, regardless of the operation type: for example, an addition.

The instruction set is dual (as shown in Table 2) in two cases, which automatically take care of data alignment, zero filling, and sign extension:

when an integer or a fractional operation leads to a different result depending on the operation type: for example, a multiplication.

when data is transferred from/to memory.

Table 2. Fractional and Integer Assembly Language Instructions

Operation

Integer

Fractional

 

 

 

 

 

 

Multiply

impy

mpy

 

 

 

Multiply accumulate

imac

mac

 

 

 

Move

move.b, move.w,

move.f, move.2f, move.4f

 

move.2w, move.4w

 

 

 

 

Introduction to the SC140 Tools

5

Image 5
Contents Motorola Typical development process is represented in Figure Compiler Good To Know File I/O ExerciseHands On 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