ST20-C1 STMICROELECTRONICS [STMicroelectronics], ST20-C1 Datasheet - Page 38

no-image

ST20-C1

Manufacturer Part Number
ST20-C1
Description
Instruction Set Reference Manual
Manufacturer
STMICROELECTRONICS [STMicroelectronics]
Datasheet
4.4 Arithmetic
Saturated arithmetic is achieved on the ST20-C1 by evaluating an expression and
then performing the saturate instruction. If an overflow or underflow has occurred then
the corresponding status bit will have been set, which will cause saturate to change
the value in Areg to the most positive or most negative value respectively. saturate
clears the overflow and underflow bits.
For example, to perform a saturated multiply of a and b :
4.4.4
The expression (-e) can be evaluated with overflow signalling by:
or
The first sequence , using not , requires one less stack register than the second. not is
a bitwise inversion which is described in section 4.8.
4.4.5
The long arithmetic instructions are listed in Table 4.6.
Multiple length addition and subtraction
Multiple length addition or subtraction are performed using addc and subc , executed
once for each word of the result. For both instructions, the carry (or borrow) is held in
the carry bit of the status register. This keeps the carrying separate from overflow, so
address calculations may be safely performed using add , sub and wsub without
affecting the carry.
The addc instruction forms (Breg + Areg) + Status
word of the result in Areg and the most significant (carr y) bit in the carry bit of the
status register. The Areg is rotated into the Creg.
Similarly, the subc instruction forms (Breg - Areg) - Status
significant word of the result in Areg and the borrow bit in the carry bit of the status
register. The Areg is rotated into the Creg.
Addition of two double length unsigned values, X and Y , giving Z , without overflow
signalling can therefore be compiled as follows
38/205
ld a; ld b;
mul; saturate;
Unary minus
e; not; adc 1;
ldc 0; e; sub;
Long arithmetic
addc
subc
umac
Mnemonic
Table 4.6 Long arithmetic instructions
add with carry
subtract with carry
unsigned multiply accumulate
Name
carry
leaving the least significant
carry
leaving the least

Related parts for ST20-C1