113
SAM4CP [DATASHEET]
43051E–ATPL–08/14
Operation
Use these instructions to add 16-bit and 8-bit data and then to halve the result before writing the result to the destination
register:
The SHADD16 instruction:
1.
2.
3.
Adds each halfword from the first operand to the corresponding halfword of the second operand.
Shuffles the result by one bit to the right, halving the data.
Writes the halfword results in the destination register.
The SHADDB8 instruction:
1.
2.
3.
Adds each byte of the first operand to the corresponding byte of the second operand.
Shuffles the result by one bit to the right, halving the data.
Writes the byte results in the destination register.
Restrictions
Do not use SP and do not use PC
.
Condition Flags
These instructions do not change the flags.
Examples
SHADD16 R1, R0 ;Adds halfwords in R0 to corresponding halfword of R1
;and writes halved result to corresponding halfword in
;R1
SHADD8 R4, R0, R5 ;Adds bytes of R0 to corresponding byte in R5 and
;writes halved result to corresponding byte in R4.
12.6.5.11 SHASX and SHSAX
Signed Halving Add and Subtract with Exchange and Signed Halving Subtract and Add with Exchange.
Syntax
op{cond
} {
Rd
},
Rn
,
Rm
where:
op
is any of:
SHASX Add and Subtract with Exchange and Halving.
SHSAX Subtract and Add with Exchange and Halving.
cond
is an optional condition code, see
“Conditional Execution”
.
Rd
is the destination register.
Rn, Rm
are registers holding the first and second operands.
Operation
The SHASX instruction:
1.
2.
Adds the top halfword of the first operand with the bottom halfword of the second operand.
Writes the halfword result of the addition to the top halfword of the destination register, shifted by one bit to the
right causing a divide by two, or halving.
Subtracts the top halfword of the second operand from the bottom highword of the first operand.
Writes the halfword result of the division in the bottom halfword of the destination register, shifted by one bit to the
right causing a divide by two, or halving.
3.
4.