C8051F120/1/2/3/4/5/6/7 C8051F130/1/2/3
168
Rev. 1.4
12.6. Rounding and Saturation
A Rounding Engine is included, which can be used to provide a rounded result when operating on frac-
tional numbers. MAC0 uses an unbiased rounding algorithm to round the data stored in bits 31
–
16 of the
accumulator, as shown in Table 12.1. Rounding occurs during the third stage of the MAC0 pipeline, after
any shift operation, or on a write to the LSB of the accumulator. The rounded results are stored in the
rounding registers: MAC0RNDH (SFR Definition 12.12) and MAC0RNDL (SFR Definition 12.13). The
accumulator registers are not affected by the rounding engine. Although rounding is primarily used for frac-
tional data, the data in the rounding registers is updated in the same way when operating in integer mode.
The rounding engine can also be used to saturate the results stored in the rounding registers. If the
MAC0SAT bit is set to ‘1’ and the rounding register overflows, the rounding registers will saturate. When a
positive overflow occurs, the rounding registers will show a value of 0x7FFF when saturated. For a nega-
tive overflow, the rounding registers will show a value of 0x8000 when saturated. If the MAC0SAT bit is
cleared to ‘0’, the rounding registers will not saturate.
12.7. Usage Examples
This section details some software examples for using MAC0.
shows a series of two MAC
operations using fractional numbers.
shows a single operation in Multiply Only mode with
integer numbers. The last example, shown in
, demonstrates how the left-shift and right-
shift operations can be used to modify the accumulator. All of the examples assume that all of the flags in
the MAC0STA register are initially set to ‘0’.
12.7.1. Multiply and Accumulate Example
The example below implements the equation:
MOV MAC0CF, #0Ah ; Set to Clear Accumulator, Use fractional numbers
MOV MAC0AH, #40h ; Load MAC0A register with 4000 hex = 0.5 decimal
MOV MAC0AL, #00h
MOV MAC0BH, #20h ; Load MAC0B register with 2000 hex = 0.25 decimal
MOV MAC0BL, #00h ; This line initiates the first MAC operation
MOV MAC0BH, #E0h ; Load MAC0B register with E000 hex = -0.25 decimal
MOV MAC0BL, #00h ; This line initiates the second MAC operation
NOP
NOP ; After this instruction, the Accumulator should be equal to 0,
; and the MAC0STA register should be 0x04, indicating a zero
NOP ; After this instruction, the Rounding register is updated
Table 12.1. MAC0 Rounding (MAC0SAT = 0)
Accumulator Bits 15–0
(MAC0ACC1:MAC0ACC0)
Accumulator Bits 31–16
(MAC0ACC3:MAC0ACC2)
Rounding
Direction
Rounded Results
(MAC0RNDH:MAC0RNDL)
Greater Than 0x8000
Anything
Up
(MAC0ACC3:MAC0ACC2) + 1
Less Than 0x8000
Anything
Down
(MAC0ACC3:MAC0ACC2)
Equal To 0x8000
Odd (LSB = 1)
Up
(MAC0ACC3:MAC0ACC2) + 1
Equal To 0x8000
Even (LSB = 0)
Down
(MAC0ACC3:MAC0ACC2)
0.5
0.25
×
(
)
0.5
0.25
–
×
(
)
+
0.125
0.125
–
0.0
=
=
Summary of Contents for C8051F12 Series
Page 2: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 2 Rev 1 4 NOTES ...
Page 104: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 104 Rev 1 4 NOTES ...
Page 112: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 112 Rev 1 4 NOTES ...
Page 176: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 176 Rev 1 4 ...
Page 184: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 184 Rev 1 4 NOTES ...
Page 197: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 Rev 1 4 197 NOTES ...
Page 198: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 198 Rev 1 4 ...
Page 210: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 210 Rev 1 4 NOTES ...
Page 218: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 218 Rev 1 4 NOTES ...
Page 234: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 234 Rev 1 4 NOTES ...
Page 258: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 258 Rev 1 4 NOTES ...
Page 272: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 272 Rev 1 4 NOTES ...
Page 286: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 286 Rev 1 4 NOTES ...
Page 308: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 308 Rev 1 4 NOTES ...
Page 340: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 340 Rev 1 4 NOTES ...
Page 348: ...C8051F120 1 2 3 4 5 6 7 C8051F130 1 2 3 348 Rev 1 4 NOTES ...