AVR32 Architecture Document: Feature Summary
AVR32 Architecture Document: Feature Summary
32000D–04/2011
1. Introduction
AVR32 is a new high-performance 32-bit RISC microprocessor core, designed for cost-sensitive
embedded applications, with particular emphasis on low power consumption and high code den-
sity. In addition, the instruction set architecture has been tuned to allow for a variety of
microarchitectures, enabling the AVR32 to be implemented as low-, mid- or high-performance
processors. AVR32 extends the AVR family into the world of 32- and 64-bit applications.
2 AVR32
32000D–04/2011
AVR32
1.2.3 FlashVault
Revision 3 of the AVR32 architecture introduced a new CPU state called Secure State. This
state is instrumental in the new security technology named FlashVault. This innovation allows
the on-chip flash and other memories to be partially programmed and locked, creating a safe on-
chip storage for secret code and valuable software intellectual property. Code stored in the
FlashVault will execute as normal, but reading, copying or debugging the code is not possible.
This allows a device with FlashVault code protection to carry a piece of valuable software such
as a math library or an encryption algorithm from a trusted location to a potentially untrustworthy
partner where the rest of the source code can be developed, debugged and programmed.
3
32000D–04/2011
1.3 Microarchitectures
The AVR32 architecture defines different microarchitectures. This enables implementations that
are tailored to specific needs and applications. The microarchitectures provide different perfor-
mance levels at the expense of area and power consumption. The following microarchitectures
are defined:
1.3.1 AVR32A
The AVR32A microarchitecture is targeted at cost-sensitive, lower-end applications like smaller
microcontrollers. This microarchitecture does not provide dedicated hardware registers for shad-
owing of register file registers in interrupt contexts. Additionally, it does not provide hardware
registers for the return address registers and return status registers. Instead, all this information
is stored on the system stack. This saves chip area at the expense of slower interrupt handling.
Upon interrupt initiation, registers R8-R12 are automatically pushed to the system stack. These
registers are pushed regardless of the priority level of the pending interrupt. The return address
and status register are also automatically pushed to stack. The interrupt handler can therefore
use R8-R12 freely. Upon interrupt completion, the old R8-R12 registers and status register are
restored, and execution continues at the return address stored popped from stack.
The stack is also used to store the status register and return address for exceptions and scall.
Executing the rete or rets instruction at the completion of an exception or system call will pop
this status register and continue execution at the popped return address.
1.3.2 AVR32B
The AVR32B microarchitecture is targeted at applications where interrupt latency is important.
The AVR32B therefore implements dedicated registers to hold the status register and return
address for interrupts, exceptions and supervisor calls. This information does not need to be
written to the stack, and latency is therefore reduced. Additionally, AVR32B allows hardware
shadowing of the registers in the register file. The INT0 to INT3 contexts may have dedicated
versions of the registers in the register file, allowing the interrupt routine to start executing
immediately.
The scall, rete and rets instructions use the dedicated status register and return address regis-
ters in their operation. No stack accesses are performed.
4 AVR32
32000D–04/2011
AVR32
2. Programming Model
This chapter describes the programming model and the set of registers accessible to the user.
Table 2-1. Overview of execution modes, their priorities and privilege levels.
Type Data Width
Byte 8 bits
Halfword 16 bits
Word 32 bits
Double Word 64 bits
When any of these types are described as unsigned, the N bit data value represents a non-neg-
ative integer in the range 0 to + 2N-1.
When any of these types are described as signed, the N bit data value represents an integer in
the range of -2N-1 to +2N-1-1, using two’s complement format.
Some instructions operate on fractional numbers. For these numbers, the data value represents
a fraction in the range of -1 to +1-2-(N-1), using two’s complement format.
31 8 7 0
000000000000000000000000 B y te U n s ig n e d b y te
31 16 15 0
SSSSSSSSSSSSSSSS S H a lfw o rd S ig n e x te n d e d h a lfw o rd
31 16 15 0
0000000000000000 H a lfw o rd U n s ig n e d h a lfw o rd
31 0
to p upper lo w e r b o tto m W o rd
5
32000D–04/2011
AVR32 can access data of size byte, halfword, word and doubleword using dedicated instruc-
tions. The memory system can support unaligned accesses for selected load/store instructions
in some implementations. Any other unaligned access will cause an address exception.
For performance reasons, the user should make sure that the stack always is word aligned. This
means that only word instructions can be used to access the stack. When manipulating the
stack pointer, the user has to ensure that the result is word aligned before trying to load and
store data on the stack. Failing to do so will result in performance penalties. Code will execute
correctly if the stack is unaligned but with a significant performance penalty.
Table 2-2. Instructions are stored in memory in a big endian fashion and must be aligned on
half word boundaries
Word Address
I J N+24
H1 H2 N+20
F2 G N+16
E2 F1 N+12
D E1 N+8
C1 C2 N+4
A B N
Byte Address 0 1 2 3
Byte Address 0 1 2 3
6 AVR32
32000D–04/2011
AVR32
Table 2-3. Overview of execution modes, their priorities and privilege levels.
Priority Mode Security Description
1 Non Maskable Interrupt Privileged Non Maskable high priority interrupt mode
2 Exception Privileged Execute exceptions
3 Interrupt 3 Privileged General purpose interrupt mode
4 Interrupt 2 Privileged General purpose interrupt mode
5 Interrupt 1 Privileged General purpose interrupt mode
6 Interrupt 0 Privileged General purpose interrupt mode
N/A Supervisor Privileged Runs supervisor calls
N/A Application Unprivileged Normal program execution mode
Mode changes can be made under software control, or can be caused by external interrupts or
exception processing. A mode can be interrupted by a higher priority mode, but never by one
with lower priority. Nested exceptions can be supported with a minimal software overhead.
When running an operating system on the AVR32, user processes will typically execute in the
application mode. The programs executed in this mode are restricted from executing certain
instructions. Furthermore, most system registers together with the upper halfword of the status
register cannot be accessed. Protected memory areas are also not available. All other operating
modes are privileged and are collectively called System Modes. They have full access to all priv-
ileged and unprivileged resources. After a reset, the processor will be in supervisor mode.
7
32000D–04/2011
anisms are in place to make sure the nonsecure software can not read or modify instruction or
data belonging to the secure software. The secure state is described in chapter 4.
Table 2-4. Entry and exit from states, modes and functions
Entry method Exit method
Non-maskable Interrupt Signal on NMI line rete
Exception Mode Internal error signal generated rete
Interrupt3 Signal on INT3 line rete
Interrupt2 Signal on INT2 line rete
Interrupt1 Signal on INT1 line rete
Interrupt0 Signal on INT0 line rete
Supervisor Mode scall instruction rets
Application Mode Returned to from any of the above modes Can not be exited from
ret{cond}, ldm, popm,
Subprogram Function call
mov PC, LR
Secure state sscall retss
8 AVR32
32000D–04/2011
AVR32
Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0
PC PC PC PC PC PC PC PC
LR LR LR LR LR LR LR LR
SP_APP SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS
R12 R12 R12 R12 R12 R12 R12 R12
R11 R11 R11 R11 R11 R11 R11 R11
R10 R10 R10 R10 R10 R10 R10 R10
R9 R9 R9 R9 R9 R9 R9 R9
R8 R8 R8 R8 R8 R8 R8 R8
INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7
INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6
FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5
SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4
R3 R3 R3 R3 R3 R3 R3 R3
R2 R2 R2 R2 R2 R2 R2 R2
R1 R1 R1 R1 R1 R1 R1 R1
R0 R0 R0 R0 R0 R0 R0 R0
SR SR SR SR SR SR SR SR
Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0
PC PC PC PC PC PC PC PC
LR LR LR / LR_INT0 LR / LR_INT1 LR / LR_INT2 LR / LR_INT3 LR LR
SP_APP SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS
R12 R12 R12 R12
R11 R11 R11 R11
R10 R10 R10 R10
R9 R9 R9 R9
R8 R8 R8 R8
INT0PC
R7 INT0PC
R7 banked banked banked banked INT0PC
R7 INT0PC
R7
INT1PC
R6 INT1PC
R6 registers registers registers registers INT1PC
R6 INT1PC
R6
(implementation (implementation (implementation (implementation
FINTPC
R5 FINTPC
R5 defined) defined) defined) defined) FINTPC
R5 FINTPC
R5
SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4
R3 R3 R3 R3
R2 R2 R2 R2
R1 R1 R1 R1
R0 R0 R0 R0
SR SR SR SR SR SR SR SR
RSR_SUP RSR_INT0 RSR_INT1 RSR_INT2 RSR_INT3 RSR_EX RSR_NMI
RAR_SUP RAR_INT0 RAR_INT1 RAR_INT2 RAR_INT3 RAR_EX RAR_NMI
The register file is designed with an implementation specific part and an architectural defined
part. Depending on the implementation, each of the interrupt modes can have different configu-
9
32000D–04/2011
rations of shadowed registers. This allows for maximum flexibility in targeting the processor for
different application, see Figure 2-4 on page 10.
Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0
PC PC PC PC PC PC PC PC
LR LR LR LR LR_INT2 LR_INT3 LR LR
SP_APP SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS
R12 R12 R12 R12 R12_INT2 R12_INT3 R12 R12
R11 R11 R11 R11 R11_INT2 R11_INT3 R11 R11
R10 R10 R10 R10 R10_INT2 R10_INT3 R10 R10
R9 R9 R9 R9 R9_INT2 R9_INT3 R9 R9
R8 R8 R8 R8 R8_INT2 R8_INT3 R8 R8
INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 R7 R7_INT3
INT0PC INT0PC
R7 INT0PC
R7
INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 R6 R6_INT3
INT1PC INT1PC
R6 INT1PC
R6
FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 R5_INT3
FINTPC FINTPC
R5 FINTPC
R5
SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 R4_INT3
SMPC SMPC
R4 SMPC
R4
R3 R3 R3 R3 R3 R3_INT3 R3 R3
R2 R2 R2 R2 R2 R2_INT3 R2 R2
R1 R1 R1 R1 R1 R1_INT3 R1 R1
R0 R0 R0 R0 R0 R0_INT3 R0 R0
SR SR SR SR SR SR SR SR
RSR_SUP RSR_INT0 RSR_INT1 RSR_INT2 RSR_INT3 RSR_EX RSR_NMI
RAR_SUP RAR_INT0 RAR_INT1 RAR_INT2 RAR_INT3 RAR_EX RAR_NMI
Three different shadowing schemes are offered, small, half and full, ranging from no general
registers shadowed to all general registers shadowed, see Figure 2-5 on page 10.
Figure 2-5. AVR32 offers three different models for shadowed registers.
Small Half Full
10 AVR32
32000D–04/2011
AVR32
G lo b a l In te rru p t M a s k
In te r ru p t L e v e l 0 M a s k
In te r ru p t L e v e l 1 M a s k
In te r ru p t L e v e l 2 M a s k
In te r ru p t L e v e l 3 M a s k
E x c e p tio n M a s k
M o d e B it 0
M o d e B it 1
M o d e B it 2
R e s e rv e d
D e b u g S ta te
D e b u g S ta te M a s k
J a v a S ta te
J a v a H a n d le
R e s e rv e d
S e c u re S ta te
11
32000D–04/2011
Figure 2-7. The Status Register low halfword
B it 1 5 B it 0
R T - - - - - - - - L Q V N Z C B it n a m e
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 In itia l v a lu e
C a rry
Z e ro
S ig n
O v e r f lo w
S a tu r a tio n
Lock
R e s e rv e d
S c r a tc h
R e g is te r R e m a p E n a b le
SS - Secure State
This bit is indicates if the processor is executing in the secure state. For more details, see chap-
ter 4. The bit is initialized in an IMPLEMENTATION DEFINED way at reset.
H - Java Handle
This bit is included to support different heap types in the Java Virtual Machine. For more details,
see chapter 3. The bit is cleared at reset.
J - Java State
The processor is in Java state when this bit is set. The incoming instruction stream will be
decoded as a stream of Java bytecodes, not RISC opcodes. The bit is cleared at reset. This bit
should not be modified by the user as undefined behaviour may result.
D - Debug State
The processor is in debug state when this bit is set. The bit is cleared at reset and should only be
modified by debug hardware, the breakpoint instruction or the retd instruction. Undefined behav-
iour may result if the user tries to modify this bit manually.
12 AVR32
32000D–04/2011
AVR32
EM - Exception mask
When this bit is set, exceptions are masked. Exceptions are enabled otherwise. The bit is auto-
matically set when exception processing is initiated or Debug Mode is entered. Software may
clear this bit after performing the necessary measures if nested exceptions should be supported.
This bit is set at reset.
13
32000D–04/2011
R - Java register remap
When this bit is set, the addresses of the registers in the register file is dynamically changed.
This allows efficient use of the register file registers as a stack. For more details, see chapter 3..
The R bit is cleared at reset. Undefined behaviour may result if this bit is modified by the user.
T - Scratch bit
This bit is not set or cleared implicit by any instruction and the programmer can therefore use
this bit as a custom flag to for example signal events in the program. This bit is cleared at reset.
L - Lock flag
Used by the conditional store instruction. Used to support atomical memory access. Automati-
cally cleared by rete. This bit is cleared after reset.
Q - Saturation flag
The saturation flag indicates that a saturating arithmetic operation overflowed. The flag is sticky
and once set it has to be manually cleared by a csrf instruction after the desired action has been
taken. See the Instruction set description for details.
V - Overflow flag
The overflow flag indicates that an arithmetic operation overflowed. See the Instruction set
description for details.
N - Negative flag
The negative flag is modified by arithmetical and logical operations. See the Instruction set
description for details.
Z - Zero flag
The zero flag indicates a zero result after an arithmetic or logic operation. See the Instruction set
description for details.
C - Carry flag
The carry flag indicates a carry after an arithmetic or logic operation. See the Instruction set
description for details.
14 AVR32
32000D–04/2011
AVR32
The Compliance column describes if the register is Required, Optional or Unused in AVR32A
and AVR32B, see Table 2-6 on page 15 for legend.
15
32000D–04/2011
Table 2-7. System Registers (Continued)
Reg # Address Name Function Compliance
24 96 JAVA_LV1 Java Local Variable 1 OA OB
25 100 JAVA_LV2 Java Local Variable 2 OA OB
26 104 JAVA_LV3 Java Local Variable 3 OA OB
27 108 JAVA_LV4 Java Local Variable 4 OA OB
28 112 JAVA_LV5 Java Local Variable 5 OA OB
29 116 JAVA_LV6 Java Local Variable 6 OA OB
30 120 JAVA_LV7 Java Local Variable 7 OA OB
31 124 JTBA Java Trap Base Address OA OB
32 128 JBCR Java Write Barrier Control Register OA OB
33-63 132-252 Reserved Reserved for future use - -
64 256 CONFIG0 Configuration register 0 RA RB
65 260 CONFIG1 Configuration register 1 RA RB
66 264 COUNT Cycle Counter register RA RB
67 268 COMPARE Compare register RA RB
68 272 TLBEHI MMU TLB Entry High OA OB
69 276 TLBELO MMU TLB Entry Low OA OB
70 280 PTBR MMU Page Table Base Register OA OB
71 284 TLBEAR MMU TLB Exception Address Register OA OB
72 288 MMUCR MMU Control Register OA OB
73 292 TLBARLO MMU TLB Accessed Register Low OA OB
74 296 TLBARHI MMU TLB Accessed Register High OA OB
75 300 PCCNT Performance Clock Counter OA OB
76 304 PCNT0 Performance Counter 0 OA OB
77 308 PCNT1 Performance Counter 1 OA OB
78 312 PCCR Performance Counter Control Register OA OB
79 316 BEAR Bus Error Address Register OA OB
80 320 MPUAR0 MPU Address Register region 0 OA OB
81 324 MPUAR1 MPU Address Register region 1 OA OB
82 328 MPUAR2 MPU Address Register region 2 OA OB
83 332 MPUAR3 MPU Address Register region 3 OA OB
84 336 MPUAR4 MPU Address Register region 4 OA OB
85 340 MPUAR5 MPU Address Register region 5 OA OB
86 344 MPUAR6 MPU Address Register region 6 OA OB
87 348 MPUAR7 MPU Address Register region 7 OA OB
88 352 MPUPSR0 MPU Privilege Select Register region 0 OA OB
89 356 MPUPSR1 MPU Privilege Select Register region 1 OA OB
16 AVR32
32000D–04/2011
AVR32
17
32000D–04/2011
should be written to zero, making ACBA word aligned. Failing to do so may result in erroneous
behaviour.
RSR_SUP, RSR_INT0, RSR_INT1, RSR_INT2, RSR_INT3, RSR_EX, RSR_NMI - Return Status Registers
If a request for a mode change, for instance an interrupt request, is accepted when executing in
a context C, the Status Register values in context C are automatically stored in the Return Sta-
tus Register (RSR) associated with the interrupt context I. When the execution in the interrupt
state I is finished and the rets / rete instruction is encountered, the RSR associated with I is cop-
ied to SR, and the execution continues in the original context C.
RAR_SUP, RAR_INT0, RAR_INT1, RAR_INT2, RAR_INT3, RAR_EX, RAR_NMI - Return Address Registers
If a request for a mode change, for instance an interrupt request, is accepted when executing in
a context C, the re-entry address of context C is automatically stored in the Return Address Reg-
ister (RAR) associated with the interrupt context I. When the execution in the interrupt state I is
finished and the rets / rete instruction is encountered, a change-of-flow to the address in the
RAR associated with I, and the execution continues in the original context C. The calculation of
the re-entry addresses is described in Section 8. “Event Processing” on page 63.
18 AVR32
32000D–04/2011
AVR32
19
32000D–04/2011
MMUCR - MMU Control Register
Used to control the MMU and the TLB. The contents and functionality of the register is described
in detail in Section 5. “Memory Management Unit” on page 35.
20 AVR32
32000D–04/2011
AVR32
SS_RAR, SS_RSR - Secure State Return Address and Return Status Registers
Contains the address and status register of the sscall instruction that called secure state. Also
used when returning to nonsecure state with the retss instruction. Refer to Section 4. “Secure
state” on page 31 for details.
31 24 23 20 19 16 15 13 12 10 9 7 6 5 4 3 2 1 0
Processor
Processor ID - AT AR MMUT F J P O S D R
Revision
CONFIG1
31 26 25 20 19 16 15 13 12 10 9 6 5 3 2 0
21
32000D–04/2011
Table 2-8. CONFIG0 Fields (Continued)
Name Bit Description
Architecture type
Value Semantic
AT 15:13 0 AVR32A
1 AVR32B
Other Reserved
Architecture Revision. Specifies which revision of the AVR32
AR 12:10
architecture the processor implements.
Value Semantic
0 Revision 0
1 Revision 1
2 Revision 2
3 Revision 3
Other Reserved
MMU type
Value Semantic
0 None, using direct mapping and no segmentation
MMUT 9:7 1 ITLB and DTLB
2 Shared TLB
3 Memory Protection Unit
Other Reserved
Floating-point unit implemented
Value Semantic
F 6
0 No FPU implemented
1 FPU implemented
Java extension implemented
Value Semantic
J 5
0 No Java extension implemented
1 Java extension implemented
Performance counters implemented
Value Semantic
P 4
0 No Performance Counters implemented
1 Performance Counters implemented
On-Chip Debug implemented
Value Semantic
O 3
0 No OCD implemented
1 OCD implemented
22 AVR32
32000D–04/2011
AVR32
23
32000D–04/2011
Table 2-9. CONFIG1 Fields (Continued)
Name Bit Description
Number of sets in ICACHE
Value Semantic
0 1
1 2
2 4
3 8
4 16
5 32
6 64
ISET 19:16
7 128
8 256
9 512
10 1024
11 2048
12 4096
13 8192
14 16384
15 32768
Line size in ICACHE
Value Semantic
0 No ICACHE present
1 4 bytes
2 8 bytes
ILSZ 15:13
3 16 bytes
4 32 bytes
5 64 bytes
6 128 bytes
7 256 bytes
24 AVR32
32000D–04/2011
AVR32
25
32000D–04/2011
Table 2-9. CONFIG1 Fields (Continued)
Name Bit Description
Line size in DCACHE
Value Semantic
0 No DCACHE present
1 4 bytes
2 8 bytes
DLSZ 5:3
3 16 bytes
4 32 bytes
5 64 bytes
6 128 bytes
7 256 bytes
Associativity of DCACHE
Value Semantic
0 Direct mapped
1 2-way
2 4-way
DASS 2:0
3 8-way
4 16-way
5 32-way
6 64-way
7 128-way
26 AVR32
32000D–04/2011
AVR32
Figure 3-1. A large part of the instruction set is shared between the AVR RISC and the Java
Virtual Machine. The Java instruction set includes instructions with high semantic
contents while the AVR RISC instruction set complements Java’s set with tradi-
tional hardware near RISC instructions
Java AVR
27
32000D–04/2011
The AVR32 Java Virtual Machine software loads and controls the execution of the Java classes.
The bytecodes are executed in hardware, except for some instructions, for example the instruc-
tions that create or manipulate objects. These are trapped and executed in software within the
Java Virtual Machine.
Figure 3-2. Overview of the AVR32 Java Virtual Machine and the Java Extension Module.
The grey area represent the software parts of the virtual machine, while the white
box to the right represents the hardware module.
Header Data
AVR32 Java
Methods Meta Data Extension
Module
Constant Pool
Other
Trapped
Threads
Bytecodes
Frames
Stack PC, SP
Const. Pool
Local Variables
Pointer
Scheduler
Figure 3-3 on page 29 shows one example on how a Java program is executed. The processor
boots in AVR32 (RISC) state and it executes applications as a normal RISC processor. To
invoke a Java program, the Java Virtual Machine is called like any other application. The Java
Virtual Machine will execute an init routine followed by a class loader that parses the class and
initializes all registers necessary to start executing the Java program. The last instruction in the
28 AVR32
32000D–04/2011
AVR32
class loader is the “RETJ” instruction that sets the processor in the Java state. This means that
the instruction decoder now decodes Java opcodes instead of the normal AVR32 opcodes.
void main() {
function1 ();
application ();
Java Extension Module
ajvm(arguments)
retj
iconst_1
istore_0
iconst_2
Trap routines
return
mfsr R12, JECR
cp R12, 0x8
cleanup()
void cleanup() {
ret
}
application
29
32000D–04/2011
During execution of the Java program, the Java Extension Module will encounter some byte-
codes that are not supported in hardware. The instruction decoder will automatically recognize
these bytecodes and switch the processor back into RISC state and at the same time jump to a
predefined location where it will execute a software routine that performs the semantic of the
trapped bytecode. When finished, the routine ends with a “RETJ” instruction. This instruction will
make the AVR32 core return to Java state and the Java program will continue at the correct
location.
Detailed technical information about the Java Extension module is available in a separate Java
Technical Reference document.
30 AVR32
32000D–04/2011
AVR32
4. Secure state
Revision 3 of the AVR32 architecture introduces a secure execution state. This state is intended
to allow execution of a proprietary secret code alongside code of unknown origin and intent on
the same processor. For example, a company with a proprietary algorithm can program this
algorithm into the secure memory sections of the device, and resell the device with the pro-
grammed algorithm to an end customer. The end customer will not be able to read or modify the
preprogrammed code in any way. Examples of such preprogrammed code can be multimedia
codecs, digital signal processing algorithms or telecom software stacks. Whereas previous
approaches to this problem required the proprietary code and the end user application to exe-
cute on separate devices, the secure state allows integration of the two codes on the same
device, saving cost and increasing performance since inter-IC communication is no longer
required.
In order to keep the proprietary code secret, this code will execute in a “secure world”. The end
user application will execute in a “nonsecure world”. Code in the nonsecure world can request
services from the secure world by executing a special instruction, sscall. This instruction is exe-
cuted in the context of an API specified by the provider of the proprietary code. The sscall
instruction can be associated with arguments passed in registers or memory, and after execu-
tion of the requested algorithm, the secure world returns results to the requesting nonsecure
application in registers or in memory.
Hardware is implemented to divide the memory resources into two sections, one secure and one
non-secure section. The secure section of the memories can only be accessed (read, written or
executed) from code running in the secure world. The nonsecure section of the memories can
be read, written or executed from the nonsecure world, and read or written from the secure
world.
The customer can choose if his application will enable the secure state support or not. An
IMPLEMENTATION DEFINED mechanism, usually a Flash fuse, is used to enable or disable
secure state support. If this mechanism is programmed so as to disable the secure state, the
system will boot in nonsecure world, and its behavior will be identical to previous devices imple-
menting older revisions of the AVR32 architecture. If the system is set up to enable secure state
support, the system will boot in the secure state. This allows configuration and startup of the
secure world application before execution is passed to the nonsecure world.
31
32000D–04/2011
• When trying to access secure world memories from the nonsecure world, a bus error
exception will be raised, and the access will be aborted. Writes to secure system registers
from within the nonsecure world will simply be disregarded without any error indication.
• The On-Chip Debug (OCD) system is modified to prevent any leak of proprietary code or
data to the nonsecure world. This prevents hacking through the use of the OCD system.
Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0
PC PC PC PC PC PC PC PC PC
LR LR LR LR LR LR LR LR LR
SP_APP SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SEC
R12 R12 R12 R12 R12 R12 R12 R12 R12
R11 R11 R11 R11 R11 R11 R11 R11 R11
R10 R10 R10 R10 R10 R10 R10 R10 R10
R9 R9 R9 R9 R9 R9 R9 R9 R9
R8 R8 R8 R8 R8 R8 R8 R8 R8
INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7 INT0PC
R7
INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6 INT1PC
R6
FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5 FINTPC
R5
SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4
R3 R3 R3 R3 R3 R3 R3 R3 R3
R2 R2 R2 R2 R2 R2 R2 R2 R2
R1 R1 R1 R1 R1 R1 R1 R1 R1
R0 R0 R0 R0 R0 R0 R0 R0 R0
SR SR SR SR SR SR SR SR SR
SS_STATUS
SS_ADRF
SS_ADRR
SS_ADR0
SS_ADR1
SS_SP_SYS
SS_SP_APP
SS_RAR
SS_RSR
32 AVR32
32000D–04/2011
AVR32
Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0 Bit 31 Bit 0
PC PC PC PC PC PC PC PC PC
LR LR LR / LR_INT0 LR / LR_INT1 LR / LR_INT2 LR / LR_INT3 LR LR LR
SP_APP SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SYS SP_SEC
R12 R12 R12 R12 R12
R11 R11 R11 R11 R11
R10 R10 R10 R10 R10
R9 R9 R9 R9 R9
R8 R8 R8 R8 R8
INT0PC
R7 INT0PC
R7 banked banked banked banked INT0PC
R7 INT0PC
R7 INT0PC
R7
INT1PC
R6 INT1PC
R6 registers registers registers registers INT1PC
R6 INT1PC
R6 INT1PC
R6
(implementation (implementation (implementation (implementation
FINTPC
R5 FINTPC
R5 defined) defined) defined) defined) FINTPC
R5 FINTPC
R5 FINTPC
R5
SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4 SMPC
R4
R3 R3 R3 R3 R3
R2 R2 R2 R2 R2
R1 R1 R1 R1 R1
R0 R0 R0 R0 R0
SR SR SR SR SR SR SR SR SR
RSR_SUP RSR_INT0 RSR_INT1 RSR_INT2 RSR_INT3 RSR_EX RSR_NMI SS_RSR
RAR_SUP RAR_INT0 RAR_INT1 RAR_INT2 RAR_INT3 RAR_EX RAR_NMI SS_RAR
SS_STATUS
SS_ADRF
SS_ADRR
SS_ADR0
SS_ADR1
SS_SP_SYS
SS_SP_APP
SS_RAR
SS_RSR
33
32000D–04/2011
34 AVR32
32000D–04/2011
AVR32
0x00000000 0x00000000
The memory map has six different segments, named P0 through P4, and U0. The P-segments
are accessible in the privileged modes, while the U-segment is accessible in the unprivileged
mode.
Both the P1 and P2 segments are default segment translated to the physical address range
0x00000000 to 0x1FFFFFFF. The mapping between virtual addresses and physical addresses
is therefore implemented by clearing of MSBs in the virtual address. The difference between P1
and P2 is that P1 may be cached, depending on the cache configuration, while P2 is always
uncached. Because P1 and P2 are segment translated and not page translated, code for initial-
ization of MMUs and exception vectors are located in these segments. P1, being cacheable,
may offer higher performance than P2.
35
32000D–04/2011
The P3 space is also by default segment translated to the physical address range 0x00000000
to 0x1FFFFFFF. By enabling and setting up the MMU, the P3 space becomes page translated.
Page translation will override segment translation.
The P4 space is intended for memory mapping special system resources like the memory arrays
in caches. This segment is non-cacheable, non-translated.
The U0 segment is accessible in the unprivileged user mode. This segment is cacheable and
translated, depending upon the configuration of the cache and the memory management unit. If
accesses to other memory addresses than the ones within U0 is made in application mode, an
access error exception is issued.
The virtual address map is summarized in Table 5-1 on page 36.
0xDFFF_FFFF to Mapped,
110 P3 512 MB Privileged Yes
0xC000_0000 Cacheable
0xBFFF_FFFF to
101 P2 512 MB Privileged Yes Unmapped, Uncacheable
0xA000_0000
0x9FFF_FFFF to
100 P1 512 MB Privileged Yes Unmapped, Cacheable
0x8000_0000
0x7FFF_FFFF to Unprivileged
0xx P0 / U0 2 Gb No Mapped, Cacheable
0x0000_0000 Privileged
The segment translation can be disabled by clearing the S bit in the MMUCR. This will place all
the virtual memory space into a single 4 GB mapped memory space. Doing this will give all
access permission control to the AP bits in the TLB entry matching the virtual address, and allow
all virtual addresses to be translated. Segment translation is enabled by default.
The AVR32 architecture has two translations of addresses.
1. Segment translation (enabled by the MMUCR[S] bit)
2. Page translation (enabled by the MMUCR[E] bit)
Both these translations are performed by the MMU and they can be applied independent of each
other. This means that you can enable:
1. No translation. Virtual and physical addresses are the same.
2. Segment translation only. The virtual and physical addresses are the same for
addresses residing in the P0, P4 and U0 segments. P1, P2 and P3 are mapped to the
physical address range 0x00000000 to 0x1FFFFFFF.
3. Page translation only. All addresses are mapped as described by the TLB entries.
4. Both segment and page translations. P1 and P2 are mapped to the physical address
range 0x00000000 to 0x1FFFFFFF. U0, P0 and P3 are mapped as described by the
TLB entries. The virtual and physical addresses are the same for addresses residing in
the P4 segment.
The segment translation is by default turned on and the page translation is by default turned off
after reset. The segment translation is summarized in Figure 5-2 on page 37.
36 AVR32
32000D–04/2011
AVR32
0x20000000
0x00000000 0x00000000
37
32000D–04/2011
5.2.1 Virtual Memory Models
The MMU provides two different virtual memory models, selected by the Mode (M) bit in the
MMU Control Register:
• Shared virtual memory, where the same virtual address space is shared between all
processes
• Private virtual memory, where each process has its own virtual address space
In shared virtual memory, the virtual address uniquely identifies which physical address it should
be mapped to. Two different processes addressing the same virtual address will always access
the same physical address. In other words, the Virtual Page Number (VPN) section of the virtual
address uniquely specifies the Physical Frame Number (PFN) section in the physical address.
In private virtual memory, each process has its own virtual memory space. This is implemented
by using both the VPN and the Application Space Identifier (ASID) of the current process when
searching the TLB for a match. Each process has a unique ASID. Therefore, two different pro-
cesses accessing the same VPN won’t hit the same TLB entry, since their ASID is different.
Pages can be shared between processes in private virtual mode by setting the Global (G) bit in
the page table entry. This will disable the ASID check in the TLB search, causing the VPN sec-
tion uniquely to identify the PFN for the particular page.
31 10 9 8 7 0
VPN V I A S ID
TLBELO
31 10 9 8 7 6 4 3 2 1 0
PFN C G B AP SZ D W
PTBR
31 0
PTBR
TLBEAR
31 0
TLBEAR
MMUCR
31 26 25 20 19 14 13 8 7 5 4 3 2 1 0
IR P IL A DRP D LA - S N I M E
TLBAR LO / TLBARH I
31 0
TLBAR LO / TLBARHI
38 AVR32
32000D–04/2011
AVR32
39
32000D–04/2011
Table 5-2. Access permissions implied by the AP bits
AP Privileged mode Unprivileged mode
000 Read None
001 Read / Execute None
010 Read / Write None
011 Read / Write / Execute None
100 Read Read
101 Read / Execute Read / Execute
110 Read / Write Read / Write
111 Read / Write / Execute Read / Write / Execute
• SZ - Size of the page. The following page sizes are provided, see Table 5-3:
• D - Dirty bit. Set if the page has been written to, cleared otherwise. If the memory access is a
store and the D bit is cleared, an Initial Page Write exception is raised.
• W - Write through. If set, a write-through cache update policy should be used. Write-back
should be used otherwise. The bit is ignored if the cache only supports write-through or write-
back.
40 AVR32
32000D–04/2011
AVR32
• E - Enable. If set, the MMU translation is enabled. If cleared, the MMU translation is disabled
and the physical address is identical to the virtual address. Access permissions are not
checked and no MMU-related exceptions are issued if the MMU is disabled. If the MMU is
disabled, the segmented memory model is used.
41
32000D–04/2011
5.2.3 Page Table Organization
The MMU leaves the page table organization up to the OS software. Since the page table han-
dling and TLB handling is done in software, the OS is free to implement different page table
organizations. It is recommended, however, that the page table entries (PTEs) are of the format
shown in Figure 5-4. This allows the loaded PTE to be written directly into TLBELO, without the
need for reformatting. How the PTEs are indexed and organized in memory is left to the OS.
PFN C G B AP SZ D W
The D, W and AP[1] bits are not implemented in ITLBs, since they have no meaning there.
The AP[0] bits are not implemented in DTLBs, since they have no meaning there.
The A bit is the Accessed bit. This bit is set when the TLB entry is loaded with a new value using
the tlbw instruction. It is cleared whenever the TLB matching process finds a match in the spe-
cific TLB entry. The A bit is used to implement pseudo-LRU replacement algorithms.
When an address look-up is performed by the TLB, the address section is searched for an entry
matching the virtual address to be accessed. The matching process is described in chapter
5.2.5.
42 AVR32
32000D–04/2011
AVR32
if (VA in P4 space)
PerformAccess(non-cached);
else if (VA in P2 space)
PerformAccess(non-cached);
else if (VA in P1 space)
PerformAccess(cached, writeback);
else
// VA in P0, U0 or P3 space
if ( ! PagingEnabled)
PerformAccess(cached, writeback);
else
PerformPagedAccess(VA);
endif;
endif;
endif;
43
32000D–04/2011
The translation process performed by PerformTranslatedAccess( ) can be described as shown
in Table 5-7.
Table 5-7. PerformTranslatedAccess( ) pseudo-code example
match ← 0;
for (i=0; i<TLBentries; i++)
if ( Compare(TLB[i]VPN, VA, TLB[i]SZ, TLB[i]V) )
// VPN and VA matches for the given page size and entry valid
if ( SharedVirtualMemoryMode or
(PrivateVirtualMemoryMode and ( TLB[i]G or (TLB[i]ASID==TLBEHIASID) ) ) )
if (match == 1)
SignalException(TLBmultipleHit);
else
match ← 1;
TLB[i]A ← 1;
ptr ← i;
// pointer points to the matching TLB entry
endif;
endif;
endfor;
if (match == 0 )
SignalException(DTLBmiss, accesstype);
endif;
if (InApplicationMode)
if (TLB[ptr]AP[2] == 0)
SignalException(DTLBprotection, accesstype);
endif;
endif;
if (accesstype == write)
if (TLB[ptr]AP[1] == 0)
SignalException(DTLBprotection, accesstype);
endif;
if (TLB[ptr]D == 0)
// Initial page write
SignalException(DTLBmodified);
endif;
endif;
if (TLB[ptr]C == 1)
if (TLB[ptr]W == 1)
PerformAccess(cached, write-through);
else
PerformAccess(cached, write-back);
endif;
else
PerformAccess(non-cached);
endif;
44 AVR32
32000D–04/2011
AVR32
if (VA in P4 space)
PerformAccess(non-cached);
else if (VA in P2 space)
PerformAccess(non-cached);
else if (VA in P1 space)
PerformAccess(cached, writeback);
else
// VA in P0, U0 or P3 space
if ( ! PagingEnabled)
PerformAccess(cached, writeback);
else
PerformPagedAccess(VA);
endif;
endif;
endif;
45
32000D–04/2011
The translation process performed by PerformTranslatedAccess( ) can be described as as
shown in Table 5-9.
Table 5-9. PerformTranslatedAccess( ) pseudo-code example
match ← 0;
for (i=0; i<TLBentries; i++)
if ( Compare(TLB[i]VPN, VA, TLB[i]SZ, TLB[i]V) )
// VPN and VA matches for the given page size and entry valid
if ( SharedVirtualMemoryMode or
(PrivateVirtualMemoryMode and ( TLB[i]G or (TLB[i]ASID==TLBEHIASID) ) ) )
if (match == 1)
SignalException(TLBmultipleHit);
else
match ← 1;
TLB[i]A ← 1;
ptr ← i;
// pointer points to the matching TLB entry
endif;
endif;
endfor;
if (match == 0 )
SignalException(ITLBmiss);
endif;
if (InApplicationMode)
if (TLB[ptr]AP[2] == 0)
SignalException(ITLBprotection);
endif;
endif;
if (TLB[ptr]AP[0] == 0)
SignalException(ITLBprotection);
endif;
if (TLB[ptr]C == 1)
PerformAccess(cached);
else
PerformAccess(non-cached);
endif;
46 AVR32
32000D–04/2011
AVR32
47
32000D–04/2011
5.3.3 MMU exception handling
This chapter describes the software actions that must be performed for MMU-related excep-
tions. The hardware actions performed by the exceptions are described in detail in Section 8.3.1
“Description of events in AVR32A” on page 68.
48 AVR32
32000D–04/2011
AVR32
49
32000D–04/2011
50 AVR32
32000D–04/2011
AVR32
51
32000D–04/2011
tem Register space, their addresses are presented in “System registers” on page 14. They are
accessed with the mtsr and mfsr instructions.
The MPU interface registers are shown below. The suffix n can have the range 0-7, indicating
which region the register is associated with.
MPUPSRn
31 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
P15
P14
P13
P12
P11
P10
P9
P8
P7
P6
P5
P4
P3
P2
P1
P0
-
MPUCRA / MPUCRB
31 8 7 6 5 4 3 2 1 0
C7
C6
C5
C4
C3
C2
C1
C0
-
MPUBRA / MPUBRB
31 8 7 6 5 4 3 2 1 0
B7
B6
B5
B4
B3
B2
B1
B0
-
MPUAPRA / MPUAPRB
31 28 27 24 23 20 19 16 15 12 11 8 7 4 3 0
MPUCR
31 1 0
- E
52 AVR32
32000D–04/2011
AVR32
• Size - Size of the protection region. The possible sizes are shown in Table 6-1 on page 53.
• V - Valid. Set if the protection region is valid, cleared otherwise. This bit is written to 0 by a
reset. The region is not considered in the protection testing if the V bit is cleared.
53
32000D–04/2011
6.2.1.3 MPU Cacheable Register A / B- MPUCRA / MPUCRB
The MPUCR registers have one bit per region, indicating if the region is cacheable. If the corre-
sponding bit is set, the region is cacheable. The register is written to 0 upon reset.
AVR32UC implementations may optionally choose not to implement the MPUCR registers.
54 AVR32
32000D–04/2011
AVR32
55
32000D–04/2011
56 AVR32
32000D–04/2011
AVR32
7. Performance counters
7.1 Overview
A set of performance counters let users evaluate the performance of the system. This is useful
when scheduling code and performing optimizations. Two configurable event counters are pro-
vided in addition to a clock cycle counter. These three counters can be used to collect
information about for example cache miss rates, branch prediction hit rate and data hazard stall
cycles.
The three counters are implemented as 32-bit registers accessible through the system register
interface. They can be configured to issue an interrupt request in case of overflow, allowing a
software overflow counter to be implemented.
A performance counter control register is implemented in addition to the three counter registers.
This register controls which events to record in the counter, counter overflow interrupt enable
and other configuration data.
7.2 Registers
31 24 23 18 17 12 10 8 6 4 3 2 1 0
57
32000D–04/2011
The following fields exist in PCCR, see Table 7-1 on page 58.
58 AVR32
32000D–04/2011
AVR32
59
32000D–04/2011
7.4 Usage
The performance counters can be used to monitor several different events and perform different
measurements. Some of the most useful are explained below.
7.4.5 Fraction of execution time spent stalling due to instruction fetch misses
CONF0: 0x1 (Instruction fetch stall)
AIFML = PCNT0 / PCCNT
The fraction of execution time spent stalling due to instruction fetch misses mesures the ratio of
clock cycles spent waiting for an instruction to be fetched to the total number of execution
cycles.
60 AVR32
32000D–04/2011
AVR32
61
32000D–04/2011
62 AVR32
32000D–04/2011
AVR32
8. Event Processing
Due to various reasons, the CPU may be required to abort normal program execution in order to
handle special, high-priority events. When handling of these events is complete, normal program
execution can be resumed. Traditionally, events that are generated internally in the CPU are
called exceptions, while events generated by sources external to the CPU are called interrupts.
The possible sources of events are listed in Table 8-1 on page 67.
The AVR32 has a powerful event handling scheme. The different event sources, like Illegal
Opcode and external interrupt requests, have different priority levels, ensuring a well-defined
behaviour when multiple events are received simultaneously. Additionally, pending events of a
higher priority class may preempt handling of ongoing events of a lower priority class.
When an event occurs, the execution of the instruction stream is halted, and execution control is
passed to an event handler at an address specified in Table 8-1 on page 67. Most of the han-
dlers are placed sequentially in the code space starting at the address specified by EVBA, with
four bytes between each handler. This gives ample space for a jump instruction to be placed
there, jumping to the event routine itself. A few critical handlers have larger spacing between
them, allowing the entire event routine to be placed directly at the address specified by the
EVBA-relative offset generated by hardware. All external interrupt sources have autovectored
interrupt service routine (ISR) addresses. This allows the interrupt controller to directly specify
the ISR address as an address relative to EVBA. The address range reachable by this autovec-
tor offset is IMPLEMENTATION DEFINED. Implementations may require EVBA to be aligned in
an IMPLEMENTATION DEFINED way in order to support autovectoring.
The same mechanisms are used to service all different types of events, including external inter-
rupt requests, yielding a uniform event handling scheme.
If the application is executing in the secure state, the event handling is modified as explained in
“Event handling in secure state” on page 92. This is to protect from hacking secure code using
the event system.
63
32000D–04/2011
ing the appropriate bit. Each exception handler has a dedicated handler address, and
this address uniquely identifies the exception source.
3. The Mode bits are set to reflect the priority of the accepted event, and the correct regis-
ter file bank is selected. The address of the event handler, as shown in Table 8-1, is
loaded into the Program Counter.
The execution of the event handler routine then continues from the effective address calculated.
The rete instruction signals the end of the event. When encountered, the Return Status Register
and Return Address Register are popped from the system stack and restored to the Status Reg-
ister and Program Counter. If the rete instruction returns from INT0, INT1, INT2 or INT3,
registers R8 to R12 and LR are also popped from the system stack. The restored Status Regis-
ter contains information allowing the core to resume operation in the previous execution mode.
This concludes the event handling.
64 AVR32
32000D–04/2011
AVR32
sary state if other priority schemes are desired. It is the event source’s responsability to
ensure that their events are left pending until accepted by the CPU.
2. When a request is accepted, the Status Register and Program Counter of the current
context is stored in the Return Status Register and Return Address Register corre-
sponding to the new context. Saving the Status Register ensures that the core is
returned to the previous execution mode when the current event handling is completed.
When exceptions occur, both the EM and GM bits are set, and the application may
manually enable nested exceptions if desired by clearing the appropriate bit. Each
exception handler has a dedicated handler address, and this address uniquely identi-
fies the exception source.
3. The Mode bits are set correctly to reflect the priority of the accepted event, and the cor-
rect register file banks are selected. The address of the event handler, as shown in
Table 8-1, is loaded into the Program Counter.
The execution of the event routine then continues from the effective address calculated.
The rete instruction signals the end of the event. When encountered, the values in the Return
Status Register and Return Address Register corresponding to the event context are restored to
the Status Register and Program Counter. The restored Status Register contains information
allowing the core to resume operation in the previous execution mode. This concludes the event
handling.
65
32000D–04/2011
8.3 Entry points for events
Several different event handler entry points exists. For AVR32A, the reset routine is placed at
address 0x8000_0000. This places the reset address in the flash memory area. For AVR32B,
the reset routine entry address is always fixed to 0xA000_0000. This address resides in
unmapped, uncached space in order to ensure well-defined resets.
TLB miss exceptions and scall have a dedicated space relative to EVBA where their event han-
dler can be placed. This speeds up execution by removing the need for a jump instruction placed
at the program address jumped to by the event hardware. All other exceptions have a dedicated
event routine entry point located relative to EVBA. The handler routine address identifies the
exception source directly.
All external interrupt requests have entry points located at an offset relative to EVBA. This
autovector offset is specified by an external Interrupt Controller. The programmer must make
sure that none of the autovector offsets interfere with the placement of other code. The reach of
the autovector offset is IMPLEMENTATION DEFINED.
Special considerations should be made when loading EVBA with a pointer. Due to security con-
siderations, the event handlers should be located in the privileged address space, or in a
privileged memory protection region. In a system with MPU, the event routines could be placed
in a cacheable protection region. In a segmented AVR32B system, some segments of the virtual
memory space may be better suited than others for holding event handlers. This is due to differ-
ences in translateability and cacheability between segments. A cacheable, non-translated
segment may offer the best performance for event handlers, as this will eliminate any TLB
misses and speed up instruction fetch. The user may also consider to lock the event handlers in
the instruction cache.
If several events occur on the same instruction, they are handled in a prioritized way. The priority
ordering is presented in Table 8-1. If events occur on several instructions at different locations in
the pipeline, the events on the oldest instruction are always handled before any events on any
younger instruction, even if the younger instruction has events of higher priority than the oldest
instruction. An instruction B is younger than an instruction A if it was sent down the pipeline later
than A.
The addresses and priority of simultaneous events are shown in Table 8-1 on page 67
66 AVR32
32000D–04/2011
AVR32
The interrupt system requires that an interrupt controller is present outside the core in order to
prioritize requests and generate a correct offset if more than one interrupt source exists for each
priority level. An interrupt controller generating different offsets depending on interrupt request
source is referred to as autovectoring. Note that the interrupt controller should generate
autovector addresses that do not conflict with addresses in use by other events or regular pro-
gram code.
67
32000D–04/2011
The addresses of the interrupt routines are calculated by adding the address on the autovector
offset bus to the value of the Exception Vector Base Address (EVBA). The INT0, INT1, INT2,
INT3, and NMI signals indicate the priority of the pending interrupt. INT0 has the lowest priority,
and NMI the highest priority of the interrupts. Implementations may require that EVBA is aligned
in an IMPLEMENTATION DEFINED way in order to support autovectoring.
68 AVR32
32000D–04/2011
AVR32
69
32000D–04/2011
8.3.1.5 Bus Error Exception on Data Access
The Bus Error on Data Access exception is generated when the data bus detects an error condi-
tion. This exception is caused by events unrelated to the instruction stream, or by data written to
the cache write-buffers many cycles ago. Therefore, execution can not be resumed in a safe
way after this exception. The value placed in RAR_EX is unrelated to the operation that caused
the exception. The exception handler is responsible for performing the appropriate action.
*(--SPSYS) = PC of first non-issued instruction;
*(--SPSYS) = SR;
SR[R] = 0;
SR[J] = 0;
SR[M2:M0] = B’110;
SR[EM] = 1;
SR[GM] = 1;
PC = EVBA + 0x08;
70 AVR32
32000D–04/2011
AVR32
71
32000D–04/2011
*(--SPSYS) = PC of first noncompleted instruction;
*(--SPSYS) = SR;
SR[R] = 0;
SR[J] = 0;
SR[M2:M0] = B’100;
SR[I2M] = 1;
SR[I1M] = 1;
SR[I0M] = 1;
PC = EVBA + INTERRUPT_VECTOR_OFFSET;
72 AVR32
32000D–04/2011
AVR32
73
32000D–04/2011
8.3.1.13 ITLB Miss Exception
The ITLB Miss exception is generated when no TLB entry matches the instruction memory
address, or if the Valid bit in a matching entry is 0.
*(--SPSYS) = PC;
*(--SPSYS) = SR;
TLBEAR = FAILING_VIRTUAL_ADDRESS;
TLBEHI[VPN] = FAILING_PAGE_NUMBER;
TLBEHI[I] = 1;
SR[R] = 0;
SR[J] = 0;
SR[M2:M0] = B’110;
SR[EM] = 1;
SR[GM] = 1;
PC = EVBA + 0x50;
74 AVR32
32000D–04/2011
AVR32
75
32000D–04/2011
8.3.1.18 Data Read Address Exception
The Data Read Address Error exception is generated if the address of a data memory read has
an illegal alignment.
*(--SPSYS) = PC;
*(--SPSYS) = SR;
TLBEAR = FAILING_VIRTUAL_ADDRESS;
TLBEHI[VPN] = FAILING_PAGE_NUMBER;
SR[R] = 0;
SR[J] = 0;
SR[M2:M0] = B’110;
SR[EM] = 1;
SR[GM] = 1;
PC = EVBA + 0x34;
76 AVR32
32000D–04/2011
AVR32
77
32000D–04/2011
8.3.1.24 Privilege Violation Exception
If the application tries to execute privileged instructions, this exception is issued. The complete
list of priveleged instructions is shown in Table 8-2 on page 78. When entering the exception
routine, the address of the instruction that caused the exception is stored as the stacked return
address.
*(--SPSYS) = PC;
*(--SPSYS) = SR;
SR[R] = 0;
SR[J] = 0;
SR[M2:M0] = B’110;
SR[EM] = 1;
SR[GM] = 1;
PC = EVBA + 0x28;
Table 8-2. List of instructions which can only execute in privileged modes.
Privileged Instructions Comment
csrf - clear status register flag Privileged only when accessing upper half of status register
cache - perform cache operation
tlbr - read addressed TLB entry into
TLBEHI and TLBELO
tlbw - write TLB entry registers into
TLB
tlbs - search TLB for entry matching
TLBEHI[VPN]
mtsr - move to system register Unpriviledged when accessing JOSP and JECR
mfsr - move from system register Unpriviledged when accessing JOSP and JECR
mtdr - move to debug register
mfdr - move from debug register
rete- return from exception
rets - return from supervisor call
retd - return from debug mode
sleep - sleep
ssrf - set status register flag Privileged only when accessing upper half of status register
78 AVR32
32000D–04/2011
AVR32
79
32000D–04/2011
8.3.1.28 Supervisor call
Supervisor calls are signalled by the application code executing a supervisor call (scall) instruc-
tion. The scall instruction behaves differently depending on which context it is called from. This
allows scall to be called from other contexts than Application.
When the exception routine is finished, execution continues at the instruction following scall. The
rets instruction is used to return from supervisor calls.
If ( SR[M2:M0] == {B’000 or B’001} )
*(--SPSYS) = PC;
*(--SPSYS) = SR;
PC ← EVBA + 0x100;
SR[M2:M0] ← B’001;
else
LRCurrent Context ← PC + 2;
PC ← EVBA + 0x100;
80 AVR32
32000D–04/2011
AVR32
81
32000D–04/2011
8.3.2.4 TLB Multiple Hit Exception
TLB Multiple Hit exception is issued when multiple address matches occurs in the TLB, causing
an internal inconsistency.
This exception signals a critical error where the hardware is in an undefined state. All interrupts
are masked, and PC is loaded with EVBA + 0x04. MMU-related registers are updated with infor-
mation in order to identify the failing address and the failing TLB if multiple TLBs are present.
TLBEHI[ASID] is unchanged after the exception, and therefore identifies the ASID that caused
the exception.
RSR_EX = SR;
RAR_EX = PC of offending instruction;
TLBEAR = FAILING_VIRTUAL_ADDRESS;
TLBEHI[VPN] = FAILING_PAGE_NUMBER;
TLBEHI[I] = 0/1, depending on which TLB caused the error;
SR[R] = 0;
SR[J] = 0;
SR[M2:M0] = B’110;
SR[EM] = 1;
SR[GM] = 1;
PC = EVBA + 0x04;
82 AVR32
32000D–04/2011
AVR32
SR[GM] = 1;
PC = EVBA + 0x0C;
83
32000D–04/2011
8.3.2.9 INT2 Exception
The INT2 exception is generated when the INT2 input line to the core is asserted. The INT2
exception can be masked by the SR[GM] bit, and the SR[I2M] bit. Hardware automatically sets
the SR[I2M] bit when accepting an INT2 exception, inhibiting new INT2 requests when process-
ing an INT2 request.
The INT2 Exception handler address is calculated by adding EVBA to an interrupt vector offset
specified by an interrupt controller outside the core. The interrupt controller is responsible for
providing the correct offset.
Since the INT2 exception is unrelated to the instruction stream, the instructions in the pipeline
are allowed to complete. After finishing the INT2 exception routine, execution should continue at
the instruction following the last completed instruction in the instruction stream.
RSR_INT2 = SR;
RAR_INT2 = Address of first noncompleted instruction;
SR[R] = 0;
SR[J] = 0;
SR[M2:M0] = B’100;
SR[I2M] = 1;
SR[I1M] = 1;
SR[I0M] = 1;
PC = EVBA + INTERRUPT_VECTOR_OFFSET;
84 AVR32
32000D–04/2011
AVR32
85
32000D–04/2011
8.3.2.13 ITLB Miss Exception
The ITLB Miss exception is generated when no TLB entry matches the instruction memory
address, or if the Valid bit in a matching entry is 0.
RSR_EX = SR;
RAR_EX = PC;
TLBEAR = FAILING_VIRTUAL_ADDRESS;
TLBEHI[VPN] = FAILING_PAGE_NUMBER;
TLBEHI[I] = 1;
SR[R] = 0;
SR[J] = 0;
SR[M2:M0] = B’110;
SR[EM] = 1;
SR[GM] = 1;
PC = EVBA + 0x50;
86 AVR32
32000D–04/2011
AVR32
SR[EM] = 1;
SR[GM] = 1;
PC = EVBA + 0x1C;
87
32000D–04/2011
8.3.2.19 Data Write Address Exception
The Data Write Address Error exception is generated if the address of a data memory write has
an illegal alignment.
RSR_EX = SR;
RAR_EX = PC;
TLBEAR = FAILING_VIRTUAL_ADDRESS;
TLBEHI[VPN] = FAILING_PAGE_NUMBER;
SR[R] = 0;
SR[J] = 0;
SR[M2:M0] = B’110;
SR[EM] = 1;
SR[GM] = 1;
PC = EVBA + 0x38;
88 AVR32
32000D–04/2011
AVR32
89
32000D–04/2011
Table 8-3. List of instructions which can only execute in privileged modes.
Privileged Instructions Comment
csrf - clear status register flag Privileged only when accessing upper half of status register
cache - perform cache operation
tlbr - read addressed TLB entry into
TLBEHI and TLBELO
tlbw - write TLB entry registers into
TLB
tlbs - search TLB for entry matching
TLBEHI[VPN]
mtsr - move to system register Unpriviledged when accessing JOSP and JECR
mfsr - move from system register Unpriviledged when accessing JOSP and JECR
- move to debug register
mfdr - move from debug register
rete- return from exception
rets - return from supervisor call
retd - return from debug mode
sleep - sleep
ssrf - set status register flag Privileged only when accessing upper half of status register
90 AVR32
32000D–04/2011
AVR32
91
32000D–04/2011
8.4 Event priority
Several instructions may be in the pipeline at the same time, and several events may be issued
in each pipeline stage. This implies that several pending exceptions may be in the pipeline
simultaneously. Priorities must therefore be imposed, ensuring that the correct event is serviced
first. The priority scheme obeys the following rules:
1. If several instructions trigger events, the instruction furthest down the pipeline is ser-
viced first, even if upstream instructions have pending events of higher priority.
2. If this instruction has several pending events, the event with the highest priority is ser-
viced first. After this event has been serviced, all pending events are cleared and the
instruction is restarted.
Details about the timing of events is IMPLEMENTATION DEFINED, and given in the hardware
manual for the specific implementation.
92 AVR32
32000D–04/2011
AVR32
Reglist8 Reglist8 ∈ {R0-R3, R4-R7, R8-R9, R10, R11, R12, LR, PC}
Reglist16 Reglist16 ∈ {R0, R1, R2, ..., R12, LR, SP, PC}
ReglistCPH8 ReglistCPH8 ∈ {CR8, CR9, CR10, ..., CR15}
ReglistCPL8 ReglistCPL8 ∈ {CR0, CR1, CR2, ..., CR7}
ReglistCP8 ReglistCPD8 ∈ {CR0-CR1,CR2-CR3,CR4-CR5,CR6-CR7,CR8-CR9,
CR10-CR11,CR12-CR13,CR14-CR15}
SysRegName Name of source or destination system register.
cond3 cond3 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl}
cond4 cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
disp Displacement
disp:E Displacement of n bits. If the both compact and extended versions of
the instruction exists,
then use the extended version. The compact version is used by default.
imm Immediate value
imm:E Immediate of n bits. If the both compact and extended versions of the
instruction exists,
then use the extended version. The compact version is used by default.
sa Shift amount
bp Bit postion
w Width of a bit field
93
32000D–04/2011
[i:j] Denotes bit i to j in an immediate value.
The programmer is responsible for placing these operands in properly aligned register
pairs. This is also
specified in the "Operands" section in the detailed description of each instruction. Fail-
ure to do so will
result in an undefined behaviour.
9.1.3 Operations
ASR(x, n) SE(x, Bits(x) + n) >> n
Bits(x) Number of bits in operand x
LSR(x, n) x >> n
LSL(x, n) x << n
SATS(x, n) Signed Saturation ( x is treated as a signed value ):
If (x > (2n-1-1)) then (2n-1-1); elseif (x < -2n-1) then -2n-1; else x;
SATSU(x, n) Signed to Unsigned Saturation ( x is treated as a signed value ):
If (x > (2n-1)) then (2n-1-1); elseif ( x < 0 ) then 0; else x;
SATU(x, n) Unsigned Saturation ( x is treated as an unsigned value ):
If (x > (2n-1)) then (2n-1-1); else x;
SE(x, n) Sign Extend x to an n-bit value
SE(x) Identical to SE(x, 32)
ZE(x, n) Zero Extend x to an n-bit value
ZE(x) Identical to ZE(x, 32)
94 AVR32
32000D–04/2011
AVR32
95
32000D–04/2011
9.1.9 Branch conditions
96 AVR32
32000D–04/2011
AVR32
97
32000D–04/2011
9.2.9 One register and a register pair
15 13 12 9 8 6 5 4 3 1 0
1 0 1 Rp 1 0 0 Opc Rd/Rs Opc
98 AVR32
32000D–04/2011
AVR32
15 12 11 4 3 0
0 0 0 0 Opcode Rd
15 12 11 8 7 6 5 4 3 0
0 0 0 0 Opcode 0 0 X Y Rd
15 12 11 8 7 5 4 3 0
0 0 0 0 Opcode 1 0 0 Y Rd
99
32000D–04/2011
9.2.24 2 register operands with k5 immediate
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 5 4 0
0 0 0 1 Opcode 0 0 0 k5
15 13 12 11 8 7 6 0
k12 [11:8] CRd/CRs k12[7:0]
15 12 11 8 7 0
0 0 0 1 Opcode 0 0 0 0 0 0 0 0
15 0
Op5 k11
100 AVR32
32000D–04/2011
AVR32
15 0
k21[15:0]
15 0
k21[15:0]
15 0
k16
15 0
k16
15 0
k16
15 0
CP# Op[6] CRd CRx CRy
101
32000D–04/2011
9.2.36 Coprocessor load and store
31 29 28 26 25 24 20 19 16
1 1 1 0 1 0 Opc 1 1 0 1 0 Rp
15 13 12 11 8 7 6 0
CP # Opc CRd/CRs k8
15 13 12 11 10 9 8 7 0
CR CR CR CR CR CR CR CR
CP # ++/-- 0 Opcode 14- 13- 11- 9-8 7-6 5-4 3-2 1-0
15 13 12 11 8 7 6 4 3 0
CP# Opc CRs/CRd 0 Opc 0 0 0 0
15 13 12 11 9 8 7 6 5 4 3 0
CP# Opc CRs/CRd Opc k k i3
15 8 7 0
0 0 0 0 0 0 0 0 System Register Ad-
15 8 7 0
0 0 0 0 0 0 0 0 Op8
102 AVR32
32000D–04/2011
AVR32
15 5 4 0
0 0 0 0 0 0 0 0 0 0 0 Bit Number
15 0
R15 R14 R13 R12 R11 R10 R9 R8 R7 R6 R5 R4 R3 R2 R1 R0
15 14 13 12 11 0
0 0 0 Part k12
15 14 13 12 11 0
0 1 Part k12
15 0
k16
103
32000D–04/2011
9.2.48 Saturate
31 29 28 25 24 20 19 16
1 1 1 Opcode 1 1 0 1 1 Rd
15 12 11 10 9 5 4 0
0 0 0 0 0 0 s5 k5
15 9 8 4 3 0
Opcode k5 Rd
15 14 13 12 11 8 7 6 5 4 3 0
Opcode X Y Ri 0 0 k2 Rb
15 14 13 12 11 4 3 0
Opcode X Y k8 Rp
9.2.54 k3 immediate
15 13 12 7 6 4 3 0
1 1 0 1 0 1 1 0 1 k3 0 1 0 0
104 AVR32
32000D–04/2011
AVR32
15 14 0
b5[0] k15
15 12 11 8 7 4 3 0
0 0 1 0 0 0 1 1 1 1 1 Opc Rd
15 12 11 8 7 4 3 0
0 0 1 0 0 0 1 1 1 1 1 Opc Rd
15 12 11 8 7 4 3 0
0 0 1 0 0 0 1 1 1 1 1 Opc Rd
105
32000D–04/2011
9.3 Instruction Set Summary
106 AVR32
32000D–04/2011
AVR32
107
32000D–04/2011
9.3.4 DSP Operations
108 AVR32
32000D–04/2011
AVR32
109
32000D–04/2011
9.3.5 Logic Operations
110 AVR32
32000D–04/2011
AVR32
111
32000D–04/2011
9.3.7 Shift Operations
112 AVR32
32000D–04/2011
AVR32
113
32000D–04/2011
9.3.9 Data Transfer
114 AVR32
32000D–04/2011
AVR32
115
32000D–04/2011
Table 9-10. Load/Store Operations (Continued)
C Rp++, Rs Store with post-increment. *(Rp++) ← Rs[7:0] 1
C --Rp, Rs Store with pre-decrement. *(--Rp) ← Rs[7:0] 1
st.b C Rp[disp], Rs *(Rp+ZE(disp3)) ← Rs[7:0] 1
Store byte with displacement.
E Rp[disp], Rs *(Rp+SE(disp16)) ← Rs[7:0] 1
E Rb[Ri<<sa], Rs Indexed Store byte. *(Rb+(Ri << sa2)) ← Rs[7:0] 1
116 AVR32
32000D–04/2011
AVR32
9.3.10 System/Control
117
32000D–04/2011
Table 9-12. System/Control (Continued)
nop C No operation See Instruction Set Reference 1
pref E Rp[disp] Prefetch cache line See Instruction Set Reference 1
sleep E Op8 Enter SLEEP mode. See Instruction Set Reference 1
if (cond4)
Conditionally set register to true or Rd ← 1;
sr{cond4} C Rd 1
false. else
Rd ← 0;
ssrf C bp Set status register flag. SR[bp5] ← 1 1
sync E Op8 Flush write buffer See Instruction Set Reference 1
tlbr C Read TLB entry See Instruction Set Reference 1
tlbs C Search TLB for entry See Instruction Set Reference 1
tlbw C Write TLB entry See Instruction Set Reference 1
118 AVR32
32000D–04/2011
AVR32
119
32000D–04/2011
Table 9-13. Coprocessor Interface (Continued)
CP#, {--}Rp, Store multiple coprocessor double
stcm.d E See instruction set reference 1
ReglistCPD8 registers
CP#, {--}Rp, Store multiple coprocessor high
stcm.w E See instruction set reference 1
ReglistCPH8 registers
CP#, {--}Rp,
stcm.w E Store multiple coprocessor low registers See instruction set reference 1
ReglistCPL8
120 AVR32
32000D–04/2011
AVR32
Rd, Rx:<part>,
Packed Halfword Subtraction and
psubadds.{uh/sh} E Ry:<part> See instruction set reference 1
Addition with Saturation
psubh.{ub/sh} E Rd, Rx, Ry Packed Subtraction with halving See instruction set reference 1
psubs.{ub/sb/uh/sh} E Rd, Rx, Ry Packed Subtraction with Saturation See instruction set reference 1
Packed Halfword Subtraction with
psubx.h E Rd, Rx, Ry See instruction set reference 1
Crossed Operand
Packed Halfword Subtraction with
psubxh.sh E Rd, Rx, Ry See instruction set reference 1
Crossed Operand and Halving
Packed Halfword Subtraction with
psubxs.{uh/sh} E Rd, Rx, Ry See instruction set reference 1
Crossed Operand and Saturation
punpck{ub/sb}.h E Rd, Rs:<part> Unpack Bytes to Halfwords See instruction set reference 1
121
32000D–04/2011
9.4 Base Instruction Set Description
The following chapter describes the instructions in the base instruction set.
122 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
The absolute value of the contents to the register specified is written back to the register. If the
initial value equals the maximum negative value (0x80000000), the result will equal the initial
value.
Operation:
I. Rd ← |Rd|;
Syntax:
I. abs Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: (RES[31:0] == 0)
C: Not affected
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 0 1 0 0 Rd
123
32000D–04/2011
ACALL – Application Call
Architecture revision:
Architecture revision1 and higher.
Description
The ACALL instruction performs an application function call.
Operation:
I. LR ← PC + 2;
PC ← *(ACBA + (ZE(disp8)<<2));
Syntax:
I. acall disp
Operands:
I. disp ∈ {0, 4, ..., 1020}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 12 11 4 3 1 0
1 1 0 1 disp8/Label 0 0 0 0
Note:
ACBA must be word aligned. Failing to align ACBA correctly may lead to erronous be-
havior.
124 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Adds carry to the specified destination register.
Operation:
I. Rd ← Rd + C;
Syntax:
I. acr Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags
Q: Not affected
V: V ← RES[31] ∧ ¬Rd[31]
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0) ∧ Z
C: C ← ¬RES[31] ∧ Rd[31]
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 0 0 0 0 Rd
Example:
; Add a 32-bit variable (R0) to a 64-bit variable (R2:R1)
add R1, R0
acr R2
125
32000D–04/2011
ADC – Add with Carry
Architecture revision:
Architecture revision1 and higher.
Description
Adds carry and the two registers specified and stores the result in destination register.
Operation:
I. Rd ← Rx + Ry + C;
Syntax:
I. adc Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: V ← (Rx[31] ∧ Ry[31] ∧ ¬RES[31]) ∨ (¬Rx[31] ∧ ¬Ry[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0) ∧ Z
C: C ← Rx[31] ∧ Ry[31] ∨ Rx[31] ∧ ¬RES[31] ∨ Ry[31] ∧ ¬RES[31]
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 0 0 0 0 1 0 0 Rd
Example
; Add two 64-bit variables R1:R0 and R3:R2 and store the result in R1:R0
add R0, R2
adc R1, R1, R3
126 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Adds the two registers specified and stores the result in destination register. Format II allows
shifting of the second operand.
Operation:
I. Rd ← Rd + Rs;
II. Rd ← Rx + (Ry<< sa2);
Syntax:
I. add Rd, Rs
II. add Rd, Rx, Ry << sa
Operands:
I. {d, s} ∈ {0, 1, …, 15}
II. {d, x, y}∈ {0, 1, …, 15}
sa ∈ {0, 1, 2, 3}
Status Flags
Format I: OP1 = Rd, OP2 = Rs
Format II:OP1 = Rx, OP2 = Ry << sa2
Q: Not affected
V: V ← (OP1[31] ∧ OP2[31] ∧ ¬RES[31]) ∨ (¬OP1[31] ∧ ¬OP2[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← OP1[31] ∧ OP2[31] ∨ OP1[31] ∧ ¬RES[31] ∨ OP2[31] ∧ ¬RES[31]
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rs 0 0 0 0 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 0 0 0 0 0 Shift Amount Rd
127
32000D–04/2011
ADD{cond4} – Conditional Add
Architecture revision:
Architecture revision 2 and higher.
Description
Performs an addition and stores the result in destination register.
Operation:
I. if ( cond4)
Rd ← Rx + Ry;
Syntax:
I. add{cond4}Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 0 1 Ry
15 12 11 8 7 0
1 1 1 0 cond4 0 0 0 0 Rd
128 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Adds Rx and the absolute value of Ry and stores the result in destination register. Useful for cal-
culating the sum of absolute differences.
Operation:
I. Rd ← Rx + |Ry|;
Syntax:
I. addabs Rd, Rx, Ry
Operands:
I. {d, x, y}∈ {0, 1, …, 15}
Status Flags
Q: Not affected
V: Not affected
N: Not affected
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 1 1 1 0 0 1 0 0 Rd
129
32000D–04/2011
ADDHH.W– Add Halfwords into Word
Architecture revision:
Architecture revision1 and higher.
Description
Adds the two halfword registers specified and stores the result in the destination word-register.
The halfword registers are selected as either the high or low part of the operand registers.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
Rd ← operand1 + operand2;
Syntax:
I. addhh.wRd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
OP1 = operand1, OP2 = operand2
Q: Not affected
V: V ← (OP1[31] ∧ OP2[31] ∧ ¬RES[31]) ∨ (¬OP1[31] ∧ ¬OP2[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← OP1[31] ∧ OP2[31] ∨ OP1[31] ∧ ¬RES[31] ∨ OP2[31] ∧ ¬RES[31]
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 6 5 4 3 0
0 0 0 0 1 1 1 0 0 0 X Y Rd
Example:
addhh.wR10, R2:t, R3:b
will perform R10 ← SE(R2[31:16]) + SE(R3[15:0])
130 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a bitwise logical AND between the specified registers and stores the result in the desti-
nation register.
Operation:
I. Rd ← Rd ∧ Rs;
II. Rd ← Rx ∧ (Ry << sa5);
III. Rd ← Rx ∧ (Ry >> sa5);
Syntax:
I. and Rd, Rs
II. and Rd, Rx, Ry << sa
III. and Rd, Rx, Ry >> sa
Operands:
I. {d, s} ∈ {0, 1, …, 15}
II, III {d, x, y} ∈ {0, 1, …, 15}
sa ∈ {0, 1, …, 31}
Status Flags
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rs 0 0 1 1 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 1 0 Ry
15 9 8 4 3 0
0 0 0 0 0 0 0 sa5 Rd
131
32000D–04/2011
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 1 0 Ry
15 9 8 4 3 0
0 0 0 0 0 0 1 sa5 Rd
132 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Architecture revision:
Architecture revision 2 and higher.
Description
Performs a bitwise logical AND between the specified registers and stores the result in the desti-
nation register.
Operation:
I. if ( cond4)
Rd ← Rx ∧ Ry;
Syntax:
I. and{cond4}Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 0 1 Ry
15 12 11 8 7 0
1 1 1 0 cond4 0 0 1 0 Rd
133
32000D–04/2011
ANDH, ANDL – Logical AND into high or low half of register
Architecture revision:
Architecture revision1 and higher.
Description
Performs a bitwise logical AND between the high or the low halfword in the specified register and
a constant. The result is stored in the high or the low halfword of the destination register while
the other bits remain unchanged. The Clear Other Half (COH) parameter allows the other half to
be cleared.
Operation:
I. Rd[31:16] ← Rd[31:16] ∧ imm16;
II. Rd[31:16] ← Rd[31:16] ∧ imm16;
Rd[15:0] ← 0;
III. Rd[15:0] ← Rd[15:0] ∧ imm16;
IV. Rd[15:0] ← Rd[15:0] ∧ imm16;
Rd[31:16] ← 0;
Syntax:
I. andh Rd, imm
II. andh Rd, imm, COH
III. andl Rd, imm
IV. andl Rd, imm, COH
Operands:
I, II, III, IV.
d ∈ {0, 1, …, 15}
imm ∈ {0, 1, ..., 65535}
Status Flags:
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode
Format I, II:
31 29 28 26 25 24 20 19 16
1 1 1 0 0 1 COH 0 0 0 0 1 Rd
15 0
imm16
134 AVR32
32000D–04/2011
AVR32
15 0
imm16
135
32000D–04/2011
ANDN – Logical AND NOT
Architecture revision:
Architecture revision1 and higher.
Description
Performs a bitwise logical ANDNOT between the specified registers and stores the result in the
destination register.
Operation:
I. Rd ← Rd ∧ ¬Rs;
Syntax:
I. andn Rd, Rs
Operands:
I. {d, s} ∈ {0, 1, …, 15}
Status Flags
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode(s):
15 13 12 9 8 4 3 0
0 0 0 Rs 0 1 0 0 0 Rd
136 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Shifts all bits in a register to the right the amount of bits specified by the five least significant bits
in Ry or an immediate while keeping the sign.
Operation:
I. Rd ← ASR(Rx, Ry[4:0]);
II. Rd ← ASR(Rd, sa5);
III. Rd ← ASR(Rs, sa5);
Syntax:
I. asr Rd, Rx, Ry
II. asr Rd, sa
III. asr Rd, Rs, sa
Operands:
I. d, x, y ∈ {0, 1, …, 15}
II. d ∈ {0, 1, …, 15}
sa ∈ {0, 1, …, 31}
III. {d,s} ∈ {0, 1, …, 15}
sa ∈ {0, 1, …, 31}
Status Flags:
Format I: Shamt = Ry[4:0], Op = Rx
Format II: Shamt = sa5, Op = Rd
Format III: Shamt = sa5, Op = Rs
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: if (Shamt != 0) then
C ← Op[Shamt-1]
else
C←0
Opcode
137
32000D–04/2011
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 1 0 0 0 0 1 0 0 Rd
Format II:
15 13 12 9 8 5 4 3 0
1 0 1 Bit[4:1] 1 0 1 0 Bit[0] Rd
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 5 4 0
0 0 0 1 0 1 0 0 0 0 0 sa5
138 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
This instruction extracts and sign-extends the w5 bits in Rs starting at bit-offset bp5 to Rd.
Operation:
I. Rd ← SE(Rs[bp5+w5-1:bp5]);
Syntax:
I. bfexts Rd, Rs, bp5, w5
Operands:
I. {d, s} ∈ {0, 1, …, 15}
{bp5, w5} ∈ {0, 1, ..., 31}
Status Flags:
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← RES[31]
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rd 1 1 1 0 1 Rs
15 12 11 10 9 5 4 0
1 0 1 1 0 0 bp5 w5
Note:
If (w5 = 0) or if (bp5 + w5 > 32) the result is undefined.
139
32000D–04/2011
BFEXTU – Bitfield extract and zero-extend
Architecture revision:
Architecture revision1 and higher.
Description
This instruction extracts and zero-extends the w5 bits in Rs starting at bit-offset bp5 to Rd.
Operation:
I. Rd ← ZE(Rs[bp5+w5-1:bp5]);
Syntax:
I. bfextu Rd, Rs, bp5, w5
Operands:
I. {d, s} ∈ {0, 1, …, 15}
{bp5, w5} ∈ {0, 1, ..., 31}
Status Flags:
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← RES[31]
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rd 1 1 1 0 1 Rs
15 12 11 10 9 5 4 0
1 1 0 0 0 0 bp5 w5
Note:
If (w5 = 0) or if (bp5 + w5 > 32) the result is undefined.
140 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
This instruction inserts the lower w5 bits of Rs in Rd at bit-offset bp5.
Operation:
I. Rd[bp5+w5-1:bp5] ← Rs[w5-1:0];
Syntax:
I. bfins Rd, Rs, bp5, w5
Operands:
I. {d, s} ∈ {0, 1, …, 15}
{bp5, w5} ∈ {0, 1, ..., 31}
Status Flags:
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← RES[31]
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rd 1 1 1 0 1 Rs
15 12 11 10 9 5 4 0
1 1 0 1 0 0 bp5 w5
Note:
If (w5 = 0) or if (bp5 + w5 > 32) the result is undefined.
141
32000D–04/2011
BLD – Bit load from register to C and Z
Architecture revision:
Architecture revision1 and higher.
Description
Copy an arbitrary bit in a register to C and Z.
Operation:
I. C ← Rd[bp5];
Z ← Rd[bp5];
Syntax:
I. bld Rd, bp
Operands:
I. d ∈{0, 1, …, 15}
bp ∈ {0, 1, …, 31}
Status Flags
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Z ← Rd[bp5]
C: C ← Rd[bp5]
Opcode:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 0 1 1 0 1 1 Rd
15 5 4 0
0 0 0 0 0 0 0 0 0 0 0 Bit Position
142 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Branch if the specified condition is satisfied.
Operation:
I. if (cond3)
PC ← PC + (SE(disp8) << 1);
else
PC ← PC + 2;
II. if (cond4)
PC ← PC + (SE(disp21) << 1);
else
PC ← PC + 4;
Syntax:
I. br{cond3}disp
II. br{cond4}disp
Operands:
I. cond3 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl}
disp ∈ {-256, -254, ..., 254}
II. cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
disp ∈ {-2097152, -2097150, ..., 2097150}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 11 4 3 2 0
1 1 0 0 disp8 0 cond3
143
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
d21
1 1 1 disp21[20:1 0 1 0 0 [16] cond4
15 0
disp21[15:0]
144 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
If the on chip debug system is enabled, this instruction traps a software breakpoint for debugging. The breakpoint instruc-
tion will enter debug mode disabling all interrupts and exceptions. If the on chip debug system is not enabled, this
instruction will execute as a nop.
Operation:
I. if (SR[DM]==0)
RSR_DBG ← SR;
RAR_DBG ← address of first non-completed instruction;
SR[R] ← 1;
SR[J] ← 1;
SR[D] ← 1;
SR[M2:M0] ← B’110;
SR[DM] ← 1;
SR[EM] ← 1;
SR[GM] ← 1;
PC ← EVBA+0x1C;
else
PC ← PC + 2;
Syntax:
I. breakpoint
Operands:
None
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 0 0 1 1 1 0 0 1 1
Note:
If no on chip debug system is implemented, this instruction will execute as a "NOP".
145
32000D–04/2011
BREV – Bit Reverse
Architecture revision:
Architecture revision1 and higher.
Description
Bit-reverse the contents in the register.
Operation:
I. Rd[31:0] ← Rd[0:31];
Syntax:
I. brev Rd
Operands:
I. d ∈{0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Z ← (RES[31:0] == 0)
C: Not affected.
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 1 0 0 1 Rd
146 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Copy the C-flag to an arbitrary bit in a register.
Operation:
I. Rd[bp5] ← C;
Syntax:
I. bst Rd, bp
Operands:
I. d ∈ {0, 1, …, 15}
bp ∈ {0, 1, …, 31}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 1 Rd
15 5 4 0
0 0 0 0 0 0 0 0 0 0 0 Bit Position
147
32000D–04/2011
CACHE – Perform Cache control operation
Architecture revision:
Architecture revision1 and higher.
Description
Control cache operation.
Operation:
I. Issue a command to the cache
Syntax:
I. cache Rp[disp], Op5
Operands:
I. disp ∈ {-1024, -1023, ..., 1023}
p ∈ {0, 1, …, 15}
Op[4:3] Semantic
00 Instruction Cache
01 Data Cache or unified cache
10 Secondary Cache
11 Tertiary Cache
Op[2:0] Semantic
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
148 AVR32
32000D–04/2011
AVR32
Opcode:
31 20 19 16
1 1 1 1 0 1 0 0 0 0 0 1 Rp
15 0
Op5 disp11
Note:
This instruction can only be executed in a privileged mode. Execution from any other mode will trigger a Privilege Violation
exception.
149
32000D–04/2011
CASTS.{H,B} – Typecast to Signed Word
Architecture revision:
Architecture revision1 and higher.
Description
Sign extends the halfword or byte that is specified to word size. The result is stored back to the
specified register.
Operation:
I. Rd[31:16] ← Rd[15];
II. Rd[31:8] ← Rd[7];
Syntax:
I. casts.h Rd
II. casts.b Rd
Operands:
I, II. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← RES[31]
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 1 0 0 0 Rd
Format II:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 0 1 1 0 Rd
150 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Zero extends the halfword or byte that is specified to word size. The result is stored back to the
specified register.
Operation:
I. Rd[31:16] ← 0;
II. Rd[31:8] ← 0:
Syntax:
I. castu.h Rd
II. castu.b Rd
Operands:
I, II. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← RES[31]
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 0 1 1 1 Rd
Format II:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 0 1 0 1 Rd
151
32000D–04/2011
CBR – Clear Bit in Register
Architecture revision:
Architecture revision1 and higher.
Description
Clears a bit in the specified register. All other bits are unaffected.
Operation:
I. Rd[bp5] ← 0;
Syntax:
I. cbr Rd, bp
Operands:
I. d ∈ {0, 1, …, 15}
bp ∈ {0, 1, …, 31}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode:
15 13 12 9 8 5 4 3 0
1 0 1 Bit[4:1] 1 1 1 0 Bit[0] Rd
152 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Counts the number of binary zero bits before the first binary one bit in a register value. The value
returned from the operation can be used for doing normalize operations. If the operand is zero,
the value 32 is returned.
Operation:
I. temp ← 32;
for (i = 31; i >= 0; i--)
if (Rs[i] == 1) then
temp ← 31 - i;
break;
Rd ← temp;
Syntax:
I. clz Rd, Rs
Operands:
I. {d, s} ∈ {0, 1, …, 15}
Status Flags
Q: Not affected
V: Not affected
N: Not affected
Z: Z ← (RES[31:0] == 0)
C: C ← (RES[31:0] == 32)
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 0
0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0
153
32000D–04/2011
COM – One’s Compliment
Architecture revision:
Architecture revision1 and higher.
Description
Perform a one’s complement of specified register.
Operation:
I. Rd ← ¬Rd;
Syntax:
I. com Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 1 1 0 1 Rd
154 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Addresses a coprocessor and performs the specified operation on the specified registers.
Operation:
I. CP#(CRd) ← CP#(CRx) Op CP#(CRy);
Syntax:
I. cop CP#, CRd, CRx, CRy, Op
Operands:
I. # ∈ {0, 1, …, 7}
Op ∈ {0, 1, …, 127}
{d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Coprocessor-specific
V: Coprocessor-specific
N: Coprocessor-specific
Z: Coprocessor-specific
C: Coprocessor-specific
Opcode:
31 29 28 25 24 20 19 16
1 1 1 0 0 Op[6:5] 1 1 0 1 0 Op[4:1]
15 0
CP# Op[0] CRd CRx CRy
Example:
cop CP2, CR0, CR1, CR2, 0
155
32000D–04/2011
CP.B – Compare Byte
Architecture revision:
Architecture revision1 and higher.
Description
Performs a compare between the lowermost bytes in the two operands specified. The operation
is implemented by doing a subtraction without writeback of the difference. The operation sets the
status flags according to the result of the subtraction, but does not affect the operand registers.
Operation:
I. Rd[7:0] - Rs[7:0];
Syntax:
I. cp.b Rd, Rs
Operands:
I. {d, s} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: V ← (Rd[7] ∧ ¬Rs[7] ∧ ¬RES[7]) ∨ (¬Rd[7] ∧ Rs[7] ∧ RES[7])
N: N ← RES[7]
Z: Z ← (RES[7:0] == 0)
C: C ← ¬Rd[7] ∧ Rs[7] ∨ Rs[7] ∧ RES[7] ∨ ¬Rd[7] ∧ RES[7]
Opcode
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 0
0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0
156 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a compare between the lowermost halfwords in the two operands specified. The oper-
ation is implemented by doing a subtraction without writeback of the difference. The operation
sets the status flags according to the result of the subtraction, but does not affect the operand
registers.
Operation:
I. Rd[15:0] - Rs[15:0];
Syntax:
I. cp.h Rd, Rs
Operands:
I. {d, s} ∈ {0, 1, …, 15}
Status Flags:
Format I: OP1 = Rd, OP2 = Rs
Q: Not affected
V: V ← (OP1[15] ∧ ¬OP2[15] ∧ ¬RES[15]) ∨ (¬OP1[15] ∧ OP2[15] ∧ RES[15])
N: N ← RES[15]
Z: Z ← (RES[15:0] == 0)
C: C ← ¬OP1[15] ∧ OP2[15] ∨ OP2[15] ∧ RES[15] ∨ ¬OP1[15] ∧ RES[15]
Opcode
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 0
0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0
157
32000D–04/2011
CP.W – Compare Word
Architecture revision:
Architecture revision1 and higher.
Description
Performs a compare between the two operands specified. The operation is implemented by
doing a subtraction without writeback of the difference. The operation sets the status flags
according to the result of the subtraction, but does not affect the operand registers.
Operation:
I. Rd - Rs;
II. Rd - SE(imm6);
III. Rd - SE(imm21);
Syntax:
I. cp.w Rd, Rs
II. cp.w Rd, imm
III. cp.w Rd, imm
Operands:
I. {d, s} ∈ {0, 1, …, 15}
II. d ∈ {0, 1, …, 15}
imm ∈ {-32, -31, ..., 31}
III. d ∈ {0, 1, …, 15}
imm ∈ {-1048576, -104875, ..., 1048575}
Status Flags:
Format I: OP1 = Rd, OP2 = Rs
Format II: OP1 = Rd, OP2 = SE(imm6)
Format III:OP1 = Rd, OP2 = SE(imm21)
Q: Not affected
V: V ← (OP1[31] ∧ ¬OP2[31] ∧ ¬RES[31]) ∨ (¬OP1[31] ∧ OP2[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← ¬OP1[31] ∧ OP2[31] ∨ OP2[31] ∧ RES[31] ∨ ¬OP1[31] ∧ RES[31]
Opcode
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rs 0 0 0 1 1 Rd
Format II:
15 13 12 10 9 4 3 0
0 1 0 1 1 0 imm6 Rd
158 AVR32
32000D–04/2011
AVR32
Format III:
31 29 28 25 24 20 19 16
i21
1 1 1 imm21[20:17 0 0 1 0 [16] Rd
15 0
imm21[15:0
159
32000D–04/2011
CPC – Compare with Carry
Architecture revision:
Architecture revision1 and higher.
Description
Performs a compare between the two registers specified. The operation is executed by doing a
subtraction with carry (as borrow) without writeback of the difference. The operation sets the sta-
tus flags according to the result of the subtraction, but does not affect the operand registers.
Note that the zero flag status before the operation is included in the calculation of the new zero
flag. This instruction allows large compares (64, 128 or more bits).
Operation:
I. Rd - Rs - C;
II. Rd - C;
Syntax:
I. cpc Rd, Rs
II. cpc Rd
Operands:
I. {d, s} ∈ {0, 1, …, 15}
II. d ∈ {0, 1, …, 15}
Status Flags:
In format II, Rs referred to below equals zero.
Q: Not affected
V: V ← (Rd[31] ∧ ¬Rs[31] ∧ ¬RES[31]) ∨ (¬Rd[31] ∧ Rs[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0) ∧ Z
C: C ← ¬Rd[31] ∧ Rs[31] ∨ Rs[31] ∧ RES[31] ∨ ¬Rd[31] ∧ RES[31]
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 0
0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 0
Format II:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 0 0 1 0 Rd
160 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Clears the status register (SR) flag specified.
Operation:
I. SR[bp5] ← 0;
Syntax:
I. csrf bp
Operands:
I. bp ∈ {0, 1, …, 31}
Status Flags:
SR[bp5] ← 0, all other flags unchanged.
Opcode:
15 11 10 9 8 4 3 0
1 1 0 1 0 1 0 bp5 0 0 1 1
Note:
Privileged if bp5 > 15, ie. upper half of status register. An exception will be triggered if the upper
half of the status register is attempted changed in user mode.
161
32000D–04/2011
CSRFCZ – Copy Status Register Flag to C and Z
Architecture revision:
Architecture revision1 and higher.
Description
Copies the status register (SR) flag specified to C and Z.
Operation:
I. C ← SR[bp5];
Z ← SR[bp5];
Syntax:
I. csrfcz bp
Operands:
I. bp ∈ {0, 1, …, 31}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Z ← SR[bp5]
C: C ← SR[bp5]
Opcode:
15 11 10 9 8 4 3 0
1 1 0 1 0 0 0 bp5 0 0 1 1
Note:
Privileged if bp5 > 15, ie. upper half of status register. A Privilege Violation exception will be trig-
gered if the upper half of the status register is attempted read in user mode.
162 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a signed divide between the two 32-bit register specified. The quotient is returned in
Rd, the remainder in Rd+1. No exceptions are taken if dividing by 0. Result in Rd and Rd+1 is
UNDEFINED when dividing by 0. The sign of the remainder will be the same as the dividend,
and the quotient will be negative if the signs of Rx and Ry are opposite.
Operation:
I. Rd ← Rx / Ry;
Rd+1 ← Rx % Ry;
Syntax:
I. divs Rd, Rx, Ry
Operands:
I. d ∈ {0, 2, …, 14}
{x, y} ∈ {0, 1, …, 15}
Status Flags
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 1 1 0 0 0 0 0 0 Rd
163
32000D–04/2011
DIVU – Unsigned divide
Architecture revision:
Architecture revision1 and higher.
Description
Performs an unsigned divide between the two 32-bit register specified. The quotient is returned
in Rd, the remainder in Rd+1. No exceptions are taken if dividing by 0. Result in Rd and Rd+1 is
UNDEFINED when dividing by 0.
Operation:
I. Rd ← Rx / Ry;
Rd+1 ← Rx % Ry;
Syntax:
I. divu Rd, Rx, Ry
Operands:
I. d ∈ {0, 2, …, 14}
{x, y} ∈ {0, 1, …, 15}
Status Flags
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 1 1 0 1 0 0 0 0 Rd
164 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a bitwise logical Exclusive-OR between the specified registers and stores the result in
the destination register.
Operation:
I. Rd ← Rd ⊕ Rs;
II. Rd ← Rx ⊕ (Ry << sa5);
III. Rd ← Rx ⊕ (Ry >> sa5);
Syntax:
I. eor Rd, Rs
II. eor Rd, Rx, Ry << sa
III. eor Rd, Rx, Ry >> sa
Operands:
I. {d, s} ∈ {0, 1, …, 15}
II, III. {d, x, y} ∈ {0, 1, …, 15}
sa ∈ {0, 1, …, 31}
Status Flags
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rs 0 0 1 0 1 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 1 0 Ry
15 9 8 4 3 0
0 0 1 0 0 0 0 sa5 Rd
165
32000D–04/2011
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 1 0 Ry
15 9 8 4 3 0
0 0 1 0 0 0 1 sa5 Rd
166 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision 2 and higher.
Description
Performs a bitwise logical Exclusive-OR between the specified registers and stores the result in
the destination register.
Operation:
I. if ( cond4)
Rd ← Rx ⊕ Ry;
Syntax:
I. eor{cond4} Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 0 1 Ry
15 12 11 8 7 0
1 1 1 0 cond4 0 1 0 0 Rd
167
32000D–04/2011
EORH, EORL – Logical EOR into high or low half of register
Architecture revision:
Architecture revision1 and higher.
Description
Performs a bitwise logical Exclusive-OR between the high or low halfword in the specified regis-
ter and a constant. The result is stored in the destination register.
Operation:
I. Rd[31:16] ← Rd[31:16] ⊕ imm16
II. Rd[15:0] ← Rd[15:0] ⊕ imm16
Syntax:
I. eorh Rd, imm
II. eorl Rd, imm
Operands:
I, II. d ∈ {0, 1, …, 15}
imm ∈ {0, 1, ..., 65535}
Status Flags:
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode
Format I:
31 29 28 20 19 16
1 1 1 0 1 1 1 0 0 0 0 1 Rd
15 0
imm16
Format II:
31 29 28 20 19 16
1 1 1 0 1 1 0 0 0 0 0 1 Rd
15 0
imm16
168 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Special instruction to invalidate the return address stack. This instruction is used when the user
writes code that conflicts with the semantics required by the return address stack.
Operation:
I. Invalidate all entries in the return address stack.
Syntax:
I. frs
Operands:
I. none
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 1 0 1 0 0 0 0 1 1
Note:
On implementation without a return stack this instruction will execute as a "NOP".
169
32000D–04/2011
ICALL – Indirect Call to Subroutine
Architecture revision:
Architecture revision1 and higher.
Description
Call to a subroutine pointed to by the pointer residing in Rp.
Operation:
I. LR ← PC + 2;
PC ← Rd;
Syntax:
I. icall Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 1 0 0 0 1 Rd
170 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Increment the system register "Java Operand Stack Pointer" with value.
Operation:
I. if ( JOSP[3:0] + imm < 0 )
TRAP 4
else if (JOSP[3:0] + imm > 8 )
TRAP 3
else
JOSP ← JOSP + imm;
imm3 imm
100 -4
101 -3
110 -2
111 -1
000 1
001 2
010 3
011 4
Syntax:
I. incjosp imm
Operands:
I. imm ∈ {-4, -3, -2, -1, 1, 2, 3, 4}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 13 12 7 6 4 3 0
1 1 0 1 0 1 1 0 1 imm3 0 0 1 1
171
32000D–04/2011
Note:
When trapped, this instruction will destroy R12. It is the programmer’s responsibility to keep the
R12value if needed.
172 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Reads the doubleword memory location specified.
Operation:
I. Rd+1:Rd ← *(Rp);
Rp ← Rp + 8;
II. Rp ← Rp - 8;
Rd+1:Rd ← *(Rp);
III. Rd+1:Rd ← *(Rp);
IV. Rd+1:Rd ← *(Rp + (SE(disp16)));
V. Rd+1:Rd ← *(Rb + (Ri << sa2));
Syntax:
I. ld.d Rd, Rp++
II. ld.d Rd, --Rp
III. ld.d Rd, Rp
IV. ld.d Rd, Rp[disp]
V. ld.d Rd, Rb[Ri<<sa]
Operands:
I-V. d ∈ {0, 2, 4, …, 14}
p, b, i ∈ {0, 1, …, 15}
IV. disp ∈ {-32768, -32767, ..., 32767}
V. sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 6 5 4 3 1 0
1 0 1 Rp 1 0 0 0 0 Rd 1
173
32000D–04/2011
Format II:
15 13 12 9 8 6 5 4 3 1 0
1 0 1 Rp 1 0 0 0 1 Rd 0
Format III:
15 13 12 9 8 6 5 4 3 1 0
1 0 1 Rp 1 0 0 0 0 Rd 0
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rp 0 1 1 1 0 Rd 0
15 0
disp16
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 0 1 0 0 0 Shift Amount Rd
Note:
Format I and II: If Rd = Rp, the result is UNDEFINED.
If Rd = Rp+1, the result is UNDEFINED.
174 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Reads the byte memory location specified and sign-extends it.
Operation:
I. Rd ← SE( *(Rp + (SE(disp16))) );
II. Rd ← SE( *(Rb + (Ri << sa2)) );
Syntax:
I. ld.sb Rd, Rp[disp]
II. ld.sb Rd, Rb[Ri<<sa]
Operands:
I. d, p ∈ {0, 1, …, 15}
disp ∈ {-32768, -32767, ..., 32767}
II. d, b, i ∈ {0, 1, …, 15}
sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 0 0 1 0 Rd
15 0
disp16
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 1 1 0 0 0 Shift Amount Rd
175
32000D–04/2011
LD.SB{cond4} – Conditionally Load Sign-extended Byte
Architecture revision:
Architecture revision 2 and higher.
Description
Reads the byte memory location specified and sign-extends it if the given condition is satisfied.
Operation:
I. if (cond4)
Rd ← SE( *(Rp + (ZE(disp9))) );
Syntax:
I. ld.sb{cond4} Rd, Rp[disp]
Operands:
I. d, p ∈ {0, 1, …, 15}
disp ∈ {0, 1, ..., 511}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 1 1 Rd
15 12 11 8 7 6 5 4 3 0
cond4 0 1 1 disp9
176 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Reads the byte memory location specified and zero-extends it.
Operation:
I. Rd ← ZE( *(Rp) );
Rp ← Rp + 1;
II. Rp ← Rp - 1;
Rd ← ZE( *(Rp) );
III. Rd ← ZE( *(Rp + (ZE(disp3))) );
IV. Rd ← ZE( *(Rp + (SE(disp16))) );
V. Rd ← ZE( *(Rb + (Ri << sa2)) );
Syntax:
I. ld.ub Rd, Rp++
II. ld.ub Rd, --Rp
III. ld.ub Rd, Rp[disp]
IV. ld.ub Rd, Rp[disp]
V. ld.ub Rd, Rb[Ri<<sa]
Operands:
I-V. d, p, b, i ∈ {0, 1, …, 15}
III. disp ∈ {0, 1, ..., 7}
IV. disp ∈ {-32768, -32767, ..., 32767}
V. sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rp 1 0 0 1 1 Rd
177
32000D–04/2011
Format II:
15 13 12 9 8 4 3 0
0 0 0 Rp 1 0 1 1 1 Rd
Format III:
15 13 12 9 8 7 6 4 3 0
0 0 0 Rp 1 1 disp3 Rd
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 0 0 1 1 Rd
15 0
disp16
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 1 1 1 0 0 Shift Amount Rd
Note:
Format I and II: If Rd = Rp, the result is UNDEFINED.
178 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision 2 and higher.
Description
Reads the byte memory location specified and zero-extends it if the given condition is satisfied.
Operation:
I. if (cond4)
Rd ← ZE( *(Rp + (ZE(disp9))) );
Syntax:
I. ld.ub{cond4} Rd, Rp[disp]
Operands:
I. d, p ∈ {0, 1, …, 15}
disp ∈ {0, 1, ..., 511}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 1 1 Rd
15 12 11 8 7 6 5 4 3 0
cond4 1 0 0 disp9
179
32000D–04/2011
LD.SH – Load Sign-extended Halfword
Architecture revision:
Architecture revision1 and higher.
Description
Reads the halfword memory location specified and sign-extends it.
Operation:
I. Rd ← SE( *(Rp) );
Rp ← Rp + 2;
II. Rp ← Rp - 2;
Rd ← SE( *(Rp) );
III. Rd ← SE( *(Rp + (ZE(disp3) << 1)) );
IV. Rd ← SE( *(Rp + (SE(disp16)));
V. Rd ← SE( *(Rb + (Ri << sa2));
Syntax:
I. ld.sh Rd, Rp++
II. ld.sh Rd, --Rp
III. ld.sh Rd, Rp[disp]
IV. ld.sh Rd, Rp[disp]
V. ld.sh Rd, Rb[Ri<<sa]
Operands:
I-V. d, p, b, i ∈ {0, 1, …, 15}
III. disp ∈ {0, 2, ..., 14}
IV. disp ∈ {-32768, -32767, ..., 32767}
V. sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rp 1 0 0 0 1 Rd
180 AVR32
32000D–04/2011
AVR32
Format II:
15 13 12 9 8 4 3 0
0 0 0 Rp 1 0 1 0 1 Rd
Format III:
15 13 12 9 8 7 6 4 3 0
1 0 0 Rp 0 0 disp3 Rd
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 0 0 0 0 Rd
15 0
disp16
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 1 0 0 0 0 Shift Amount Rd
Note:
Format I and II: If Rd = Rp, the result is UNDEFINED.
181
32000D–04/2011
LD.SH{cond4} – Conditionally Load Sign-extended Halfword
Architecture revision:
Architecture revision 2 and higher.
Description
Reads the halfword memory location specified and sign-extends it if the given condition is satis-
fied.
Operation:
I. if (cond4)
Rd ← SE( *(Rp + (ZE(disp9<<1))) );
Syntax:
I. ld.sh{cond4} Rd, Rp[disp]
Operands:
I. d, p ∈ {0, 1, …, 15}
disp ∈ {0, 2, ..., 1022}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 1 1 Rd
15 12 11 8 7 6 5 4 3 0
cond4 0 0 1 disp9
182 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Reads the halfword memory location specified and zero-extends it.
Operation:
I. Rd ← ZE( *(Rp) );
Rp ← Rp + 2;
II. Rp ← Rp - 2;
Rd ← ZE( *(Rp) );
III. Rd ← ZE( *(Rp + (ZE(disp3) << 1)) );
IV. Rd ← ZE( *(Rp + (SE(disp16))) );
V. Rd ← ZE( *(Rb + (Ri << sa2)) );
Syntax:
I. ld.uh Rd, Rp++
II. ld.uh Rd, --Rp
III. ld.uh Rd, Rp[disp]
IV. ld.uh Rd, Rp[disp]
V. ld.uh Rd, Rb[Ri<<sa]
Operands:
I-V. d, p, b, i ∈ {0, 1, …, 15}
III. disp ∈ {0, 2, ..., 14}
IV. disp ∈ {-32768, -32767, ..., 32767}
V. sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rp 1 0 0 1 0 Rd
183
32000D–04/2011
Format II:
15 13 12 9 8 4 3 0
0 0 0 Rp 1 0 1 1 0 Rd
Format III:
15 13 12 9 8 7 6 4 3 0
1 0 0 Rp 0 1 disp3 Rd
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 0 0 0 1 Rd
15 0
disp16
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 1 0 1 0 0 Shift Amount Rd
Note:
Format I and II: If Rd = Rp, the result is UNDEFINED.
184 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision 2 and higher.
Description
Reads the halfword memory location specified and zero-extends it if the given condition is satis-
fied.
Operation:
I. if (cond4)
Rd ← ZE( *(Rp + (ZE(disp9<<1))) );
Syntax:
I. ld.uh{cond4} Rd, Rp[disp]
Operands:
I. d, p ∈ {0, 1, …, 15}
disp ∈ {0, 2, ..., 1022}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 1 1 Rd
15 12 11 8 7 6 5 4 3 0
cond4 0 1 0 disp9
185
32000D–04/2011
LD.W – Load Word
Architecture revision:
Architecture revision1 and higher.
Description
Format I to V: Reads the word memory location specified.
Format VI: This instruction extracts a specified byte from Ri. This value is zero-extended, shifted
left two positions and added to Rb to form an address. The contents of this address is loaded
into Rd. The instruction is useful for indexing tables.
Operation:
I. Rd ← *(Rp);
Rp ← Rp + 4;
II. Rp ← Rp - 4;
Rd ← *(Rp);
III. Rd ← *(Rp + (ZE(disp5) << 2));
IV. Rd ← *(Rp + (SE(disp16)));
V. Rd ← *(Rb + (Ri << sa2));
VI. If (part == b)
Rd ← *(Rb + (Ri[7:0] << 2) );
else if (part == l)
Rd ← *(Rb + (Ri[15:8] << 2) );
else if (part == u)
Rd ← *(Rb + (Ri[23:16] << 2) );
else
Rd ← *(Rb + (Ri[31:24] << 2) );
Syntax:
I. ld.w Rd, Rp++
II. ld.w Rd, --Rp
III. ld.w Rd, Rp[disp]
IV. ld.w Rd, Rp[disp]
V. ld.w Rd, Rb[Ri<<sa]
VI. ld.w Rd, Rb[Ri:<part> << 2]
Operands:
I-V. d, p, b, i ∈ {0, 1, …, 15}
III. disp ∈ {0, 4, ..., 124}
IV. disp ∈ {-32768, -32767, ..., 32767}
V. sa ∈ {0, 1, 2, 3}
VI. {d, b, i} ∈ {0, 1, …, 15}
part ∈ {t, u, l, b}
186 AVR32
32000D–04/2011
AVR32
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rp 1 0 0 0 0 Rd
Format II:
15 13 12 9 8 4 3 0
0 0 0 Rp 1 0 1 0 0 Rd
Format III:
15 13 12 9 8 4 3 0
0 1 1 Rp disp5 Rd
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rp 0 1 1 1 1 Rd
15 0
disp16
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 0 1 1 0 0 Shift Amount Rd
Format VI:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 6 5 4 3 0
0 0 0 0 1 1 1 1 1 0 X Y Rd
Note:
Format I and II: If Rd = Rp, the result is UNDEFINED.
187
32000D–04/2011
188 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision 2 and higher.
Description
Reads the word memory location specified if the given condition is satisfied.
Operation:
I. if (cond4)
Rd ← *(Rp + (ZE(disp9<<2)));
Syntax:
I. ld.w{cond4} Rd, Rp[disp]
Operands:
I. d, p ∈ {0, 1, …, 15}
disp ∈ {0, 4, ..., 2044}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 1 1 Rd
15 12 11 8 7 6 5 4 3 0
cond4 0 0 0 disp9
189
32000D–04/2011
LDC.{D,W} – Load Coprocessor
Architecture revision:
Architecture revision1 and higher.
Description
Reads the memory location specified into the addressed coprocessor.
Operation:
I. CP#(CRd+1:CRd) ← *(Rp + (ZE(disp8) << 2));
II. Rp ← Rp-8;
CP#(CRd+1:CRd) ← *(Rp);
III. CP#(CRd+1:CRd) ← *(Rb + (Ri << sa2));
IV. CP#(CRd) ← *(Rp + (ZE(disp8) << 2));
V. Rp ← Rp-4;
CP#(CRd) ← *(Rp);
VI. CP#(CRd) ← *(Rb + (Ri << sa2));
Syntax:
I. ldc.d CP#, CRd, Rp[disp]
II. ldc.d CP#, CRd, --Rp
III. ldc.d CP#, CRd, Rb[Ri<<sa]
IV. ldc.w CP#, CRd, Rp[disp]
V. ldc.w CP#, CRd, --Rp
VI. ldc.w CP#, CRd, Rb[Ri<<sa]
Operands:
I-VI. # ∈ {0, 1, …, 7}
I-II, IV-V.p ∈ {0, 1, …, 15}
I-III. d ∈ {0, 2, …, 14}
I, IV. disp ∈ {0, 4, …, 1020}
III, VI. {b, i} ∈ {0, 1, …, 15}
III, VI. sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
190 AVR32
32000D–04/2011
AVR32
Format I:
31 29 28 25 24 20 19 16
1 1 1 0 1 0 0 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CP # 1 CRd[3:1] 0 disp8
Format II:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rp
15 13 12 11 9 8 7 0
CP # 0 CRd[3:1] 0 0 1 0 1 0 0 0 0
Format III:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rp
15 13 12 11 9 8 7 6 5 4 3 0
CP # 1 CRd[3:1] 0 0 1 Sh amt Ri
Format IV:
31 29 28 25 24 20 19 16
1 1 1 0 1 0 0 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CP # 0 CRd k8
Format V:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CP # 0 CRd 0 1 0 0 0 0 0 0
Format VI:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rp
15 13 12 11 8 7 6 5 4 3 0
CP # 1 CRd 0 0 Sh amt Ri
Example:
ldc.d CP2, CR0, R2[0]
191
32000D–04/2011
LDC0.{D,W} – Load Coprocessor 0
Architecture revision:
Architecture revision1 and higher.
Description
Reads the memory location specified into coprocessor 0.
Operation:
I. CP0(CRd+1:CRd) ← *(Rp + (ZE(disp12) << 2));
II. CP0(CRd) ← *(Rp + (ZE(disp12) << 2));
Syntax:
I. ldc0.d CRd, Rp[disp]
II. ldc0.w CRd, Rp[disp]
Operands:
I,II p ∈ {0, 1, …, 15}
I. d ∈ {0, 2, …, 14}
II. d ∈ {0, 1, …, 15}
I, II. disp ∈ {0, 4, …, 16380}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 1 0 0 1 1 1 0 1 0 Rp
15 13 12 11 8 7 0
disp[11:8] CRd[3:1] 0 disp[7:0]
Format II:
31 29 28 25 24 20 19 16
1 1 1 1 0 0 0 1 1 0 1 0 Rp
15 12 11 8 7 0
disp[11:8] CRd disp[7:0]
Example:
ldc0.d CR0, R2[0]
192 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Reads the memory locations specified into the addressed coprocessor. The pointer register can
optionally be updated after the operation.
Operation:
I. Loadaddress ←Rp;
for (i = 7 to 0)
if ReglistCPD8[i] == 1 then
CP#(CR(2*i+1)) ←*(Loadaddress++);
CP#(CR(2*i)) ←*(Loadaddress++);
if Opcode[++] == 1 then
Rp ← Loadaddress;
II. Loadaddress ←Rp;
for (i = 7 to 0)
if ReglistCPH8[i] == 1 then
CP#(CRi+8) ←*(Loadaddress++);
if Opcode[++] == 1 then
Rp ← Loadaddress;
III. Loadaddress ←Rp;
for (i = 7 to 0)
if ReglistCPL8[i] == 1 then
CP#(CRi) ←*(Loadaddress++);
if Opcode[++] == 1 then
Rp ← Loadaddress;
Syntax:
I. ldcm.d CP#, Rp{++}, ReglistCPD8
II. ldcm.w CP#, Rp{++}, ReglistCPH8
III. ldcm.w CP#, Rp{++}, ReglistCPL8
Operands:
I-III. # ∈ {0, 1, …, 7}
p ∈ {0, 1, …, 15}
I. ReglistCPD8 ∈ {CR0-CR1,CR2-CR3,CR4-CR5,CR6-CR7,CR8-CR9,
CR10-CR11,CR12-CR13,CR14-CR15}
II. ReglistCPH8 ∈ {CR8, CR9, CR10, ..., CR15}
III. ReglistCPL8 ∈ {CR0, CR1, CR2, ..., CR7}
193
32000D–04/2011
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 0 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CR CR CR CR CR CR CR CR
CP# ++ 0 1 0 0 15-14 13-12 11-10 9-8 7-6 5-4 3-2 1-0
Format II:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 0 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CR CR CR CR CR CR CR CR
CP# ++ 0 0 0 1 15 14 13 12 11 10 9 8
Format III:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 0 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CR CR CR CR CR CR CR CR
CP# ++ 0 0 0 0 7 6 5 4 3 2 1 0
Example:
ldcm.w CP2, SP++, CR2-CR5
Note:
Emtpy ReglistCPL8/ReglistCPL8/ReglistCPD8 gives UNDEFINED result.
194 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a PC relative load of a register
Operation:
I. Rd ← *( (PC && 0xFFFF_FFFC) + (ZE(disp7) << 2));
Syntax:
I. lddpc Rd, PC[disp]
Operands:
I. d ∈ {0, 1, …, 15}
disp ∈ {0, 4, …, 508}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 13 12 11 10 4 3 0
0 1 0 0 1 disp7 Rd
195
32000D–04/2011
LDDSP – Load SP-relative with Displacement
Architecture revision:
Architecture revision1 and higher.
Description
Reads the value of a memory location referred to by the stack pointer register and a displace-
ment.
Operation:
I. Rd ← *( (SP && 0xFFFF_FFFC) + (ZE(disp7) << 2));
Syntax:
I. lddsp Rd, SP[disp]
Operands:
I. d ∈ {0, 1, …, 15}
disp ∈ {0, 4, …, 508}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 13 12 11 10 4 3 0
0 1 0 0 0 disp7 Rd
196 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
This instruction loads a byte or a halfword from memory and inserts it into the addressed byte or
halfword position in Rd. The other parts of Rd are unaffected.
Operation:
I. If (part == b)
Rd[7:0] ← *(Rp+SE(disp12));
else if (part == l)
Rd[15:8] ← *(Rp+SE(disp12));
else if (part == u)
Rd[23:16] ← *(Rp+SE(disp12));
else
Rd[31:24] ← *(Rp+SE(disp12));
II. If (part == b)
Rd[15:0] ← *(Rp+SE(disp12) << 1);
else
Rd[31:16] ← *(Rp+SE(disp12) << 1);
Syntax:
I. ldins.b Rd:<part>, Rp[disp]
II. ldins.h Rd:<part>, Rp[disp]
Operands:
I. {p, d} ∈ {0, 1, …, 15}
part ∈ {t, u, l, b}
disp ∈ {-2048, -2047, ..., 2047}
II. {p, d} ∈ {0, 1, …, 15}
part ∈ {t, b}
disp ∈ {-4096, -4094, ..., 4094}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
197
32000D–04/2011
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 0 1 Rd
15 14 13 12 11 0
0 1 part disp12
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 0 1 Rd
15 13 12 11 0
0 0 0 part disp12
198 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Loads the consecutive words pointed to by Rp into the registers specified in the instruction. The
PC can be loaded, resulting in a jump to the loaded target address. If PC is loaded, the return
value in R12 is tested and the flags are updated. The return value may optionally be set to -1, 0
or 1.
Operation:
I. Loadaddress ← Rp;
if Reglist16[PC] == 1 then
if Rp == PC then
Loadaddress ← SP;
PC ← *(Loadaddress++);
if Rp == PC then
if Reglist16[LR,R12] == B’00
R12 ← 0;
else if Reglist16[LR,R12] == B’01
R12 ← 1;
else
R12 ← −1;
Test R12 and update flags;
else
if Reglist16[LR] == 1
LR ← *(Loadaddress++);
if Reglist16[SP] == 1
SP ← *(Loadaddress++);
if Reglist16[R12] == 1
R12 ← *(Loadaddress++);
Test R12 and update flags;
else
if Reglist16[LR] == 1
LR ← *(Loadaddress++);
if Reglist16[SP] == 1
SP ← *(Loadaddress++);
if Reglist16[R12] == 1
R12 ← *(Loadaddress++);
for (i = 11 to 0)
if Reglist16[i] == 1 then
Ri ← *(Loadaddress++);
if Opcode[++] == 1 then
if Rp == PC then
SP ← Loadaddress;
else
Rp ← Loadaddress;
199
32000D–04/2011
Syntax:
I. ldm Rp{++}, Reglist16
Operands:
I. Reglist16 ∈ {R0, R1, R2, ..., R12, LR, SP, PC}
p ∈ {0, 1, …, 15}
Status Flags:
Flags are only updated if Reglist16[PC] == 1.
They are set as the result of the operation cp R12, 0.
Q: Not affected
V: V←0
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C←0
Opcode:
31 29 28 26 25 24 20 19 16
1 1 1 0 0 0 ++ 1 1 1 0 0 Rp
15 0
R15 R14 R13 R12 R11 R10 R9 R8 R7 R6 R5 R4 R3 R2 R1 R0
Note:
Emtpy Reglist16 gives UNDEFINED result.
If Rp is in Reglist16 and pointer is written back the result is UNDEFINED.
The R bit in the status register has no effect on this instruction.
200 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Loads the consecutive words pointed to by Rp into the registers specified in the instruction.The
target registers reside in the User Register Context, regardless of which context the instruction is
called from.
Operation:
I. Loadaddress ←Rp;
for (i = 15 to 0)
if Reglist16[i] == 1 then
Ri USER ←*(Loadaddress++);
if Opcode[++] == 1 then
Rp ← Loadaddress;
Syntax:
I. ldmts Rp{++}, Reglist16
Operands:
I. Reglist16 ∈ {R0, R1, R2, ..., R12, LR, SP}
p ∈ {0, 1, …, 15}
Status Flags:
Not affected.
Opcode:
31 29 28 26 25 24 20 19 16
1 1 1 0 0 1 ++ 1 1 1 0 0 Rp
15 0
R15 R14 R13 R12 R11 R10 R9 R8 R7 R6 R5 R4 R3 R2 R1 R0
Note:
This instruction is intended for performing task switches.
Emtpy Reglist16 gives UNDEFINED result.
PC in Reglist16 gives UNDEFINED result.
201
32000D–04/2011
LDSWP.{SH, UH, W} – Load and Swap
Architecture revision:
Architecture revision1 and higher.
Description
This instruction loads a halfword or a word from memory. If a halfword load is performed, the
loaded value is zero- or sign-extended. The bytes in the loaded value are shuffled and the result
is written back to Rd. The instruction can be used for performing loads from memories of differ-
ent endianness.
Operation:
I. temp[15:0] ← *(Rp+SE(disp12) << 1);
Rd ← SE(temp[7:0], temp[15:8]);
II. temp[15:0] ← *(Rp+SE(disp12) << 1);
Rd ← ZE(temp[7:0], temp[15:8]);
III. temp ← *(Rp+SE(disp12) << 2);
Rd ← (temp[7:0], temp[15:8], temp[23:16], temp[31:24]);
Syntax:
I. ldswp.shRd, Rp[disp]
II. ldswp.uhRd, Rp[disp]
III. ldswp.w Rd, Rp[disp]
Operands:
I, II. {d, p} ∈ {0, 1, …, 15}
disp ∈ {-4096, -4094, ..., 4094}
III. {d, p} ∈ {0, 1, …, 15}
disp ∈ {-8192, -8188, ..., 8188}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 0 1 Rd
15 12 11 0
0 0 1 0 disp12
202 AVR32
32000D–04/2011
AVR32
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 0 1 Rd
15 12 11 0
0 0 1 1 disp12
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 0 1 Rd
15 12 11 0
1 0 0 0 disp12
203
32000D–04/2011
LSL – Logical Shift Left
Architecture revision:
Architecture revision1 and higher.
Description
Shifts all bits in a register the amount of bits specified to the left. The shift amount can reside in
a register or be specified as an immediate. Zeros are shifted into the LSBs. The last bit that is
shifted out is placed in C.
Operation:
I. Rd ← LSL(Rx, Ry[4:0]);
II. Rd ← LSL(Rd, sa5);
III. Rd ← LSL(Rs, sa5);
Syntax:
I. lsl Rd, Rx, Ry
II. lsl Rd, sa
III. lsl Rd, Rs, sa
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
II. d ∈ {0, 1, …, 15}
sa ∈ {0, 1, …, 31}
III. {d,s} ∈ {0, 1, …, 15}
sa ∈ {0, 1, …, 31}
Status Flags:
Format I: Shamt = Ry[4:0], Op = Rx
Format II: Shamt = sa5, Op = Rd
Format III: Shamt = sa5, Op = Rs
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: if Shamt != 0
C ← Op[32-Shamt]
else
C←0
Opcode:
204 AVR32
32000D–04/2011
AVR32
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 1 0 0 1 0 1 0 0 Rd
Format II:
15 13 12 9 8 5 4 3 0
1 0 1 Bit[4:1] 1 0 1 1 Bit[0] Rd
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 5 4 0
0 0 0 1 0 1 0 1 0 0 0 sa5
205
32000D–04/2011
LSR – Logical Shift Right
Architecture revision:
Architecture revision1 and higher.
Description
Shifts all bits in a register the amount specified to the right. The shift amount may be specified by
a register or an immediate. Zeros are shifted into the MSB.
Operation:
I. Rd ← LSR(Rx, Ry[4:0]);
II. Rd ← LSR(Rd, sa5);
III. Rd ← LSR(Rs, sa5);
Syntax:
I. lsr Rd, Rx, Ry
II. lsr Rd, sa
III. lsr Rd, Rs, sa
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
II. d ∈ {0, 1, …, 15}
sa ∈ {0, 1, …, 31}
III. {d,s} ∈ {0, 1, …, 15}
sa ∈ {0, 1, …, 31}
Status Flags:
Format I: Shamt = Ry[4:0], Op = Rx
Format II: Shamt = sa5, Op = Rd
Format III: Shamt = sa5, Op = Rs
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: if Shamt != 0
C ← Op[Shamt-1]
else
C←0
206 AVR32
32000D–04/2011
AVR32
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 1 0 1 0 0 1 0 0 Rd
Format II:
15 13 12 9 8 5 4 3 0
1 0 1 Bit[4:0] 1 1 0 0 Bit[0] Rd
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 5 4 0
0 0 0 1 0 1 1 0 0 0 0 sa5
207
32000D–04/2011
MAC – Multiply Accumulate
Architecture revision:
Architecture revision1 and higher.
Description
Performs a Multiply-Accumulate operation and stores the result into the destination register.
Operation:
I. Rd ← (Rx × Ry) + Rd;
Syntax:
I. mac Rd, Rx, Ry
Operands:
{d, x, y} ∈ {0, 1, …, 15}
Status Flags
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 0 1 1 0 1 0 0 Rd
208 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two halfword registers specified and adds the result to the specified doubleword-
register. Only the 48 highest of the 64 possible bits in the doubleword accumulator are used. The
16 lowest bits are cleared. The halfword registers are selected as either the high or low part of
the operand registers.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
(Rd+1:Rd)[63:16] ← (operand1 × operand2)[31:0] + (Rd+1:Rd)[63:16];
Rd[15:0] ← 0;
Syntax:
I. machh.d Rd, Rx:<part>, Ry:<part>
Operands:
I. d ∈ {0, 2, 4, …, 14}
{x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 1 0 1 1 0 X Y Rd
Example:
machh.d R10, R2:t, R3:b will perform
(R11 : R10)[63:16] ← ( SE(R2[31:16]) × SE(R3[15:0]) ) + (R11 : R10)[63:16]
R10[15:0] ← 0
209
32000D–04/2011
MACHH.W – Multiply Halfwords and Accumulate in Word
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two halfword registers specified and adds the result to the specified word-register.
The halfword registers are selected as either the high or low part of the operand registers.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
Rd ← (operand1 × operand2) + Rd;
Syntax:
I. machh.w Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 1 0 0 1 0 X Y Rd
Example:
machh.w R10, R2:t, R3:b
will perform R10 ← ( SE(R2[31:16]) × SE(R3[15:0]) ) + R10
210 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a Multiply-Accumulate operation with signed numbers and stores the result into the
destination registers.
Operation:
I. acc ← (Rd+1:Rd);
prod ← (Rx × Ry);
res ← prod + acc;
(Rd+1:Rd) ← res;
Syntax:
I. macs.d Rd, Rx, Ry
Operands:
I. d ∈ {0, 2, 4, …, 14}
{x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 1 0 1 0 1 0 0 Rd
211
32000D–04/2011
MACSATHH.W – Multiply-Accumulate Halfwords with Saturation into Word
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two halfword registers specified, shifts the results one position to the left and
stores the result as a temporary word-sized product. If the two operands equals -1, the product
is saturated to the largest positive 32-bit fractional number. The halfword registers are selected
as either the high or low part of the operand registers. The temporary product is added with sat-
uration to Rd.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
If (operand1 == operand2 == 0x8000)
product ← 0x7FFF_FFFF;
else
product ← (operand1 × operand2) << 1;
Rd ← Sat(product + Rd);
Syntax:
I. macsathh.w Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Set if saturation occurred, or if the accumulation overflows, or previously set.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 1 1 0 1 0 X Y Rd
Example:
macsathh.wR10, R2:t, R3:b
will perform R10 ← Sat (Sat(( SE(R2[31:16]) × SE(R3[15:0]) ) << 1) + R10)
212 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a Multiply-Accumulate operation with unsigned numbers and stores the result into the
destination registers.
Operation:
I. acc ← (Rd+1:Rd);
prod ← (Rx × Ry);
res ← prod + acc;
(Rd+1:Rd) ← res;
Syntax:
I. macu.d Rd, Rx, Ry
Operands:
I. d ∈ {0, 2, 4, …, 14}
{x, y} ∈ {0, 1, …, 15}
Status Flags
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 1 1 1 0 1 0 0 Rd
213
32000D–04/2011
MACWH.D – Multiply Word with Halfword and Accumulate in Doubleword
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the word and halfword register specified and adds the result to the specified double-
word-register. The halfword register is selected as either the high or low part of Ry. Only the 48
highest of the 64 possible bits in the doubleword accumulator are used. The 16 lowest bits are
cleared.
Operation:
I. operand1 = Rx;
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
(Rd+1:Rd)[63:16] ← (operand1 × operand2)[47:0] + (Rd+1:Rd)[63:16];
Rd[15:0] ← 0;
Syntax:
I. macwh.d Rd, Rx, Ry:<part>
Operands:
I. d ∈ {0, 2, …, 14}
{x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 5 4 3 0
0 0 0 0 1 1 0 0 1 0 0 Y Rd
Example:
macwh.dR10, R2, R3:bwill perform
(R11:R10)[63:16] ← (R2 × SE(R3[15:0])) + (R11:R10)[63:16]
R10[15:0] ← 0
214 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Sets Rd equal to the signed maximum of Rx and Ry.
Operation:
I. If Rx > Ry
Rd ← Rx;
else
Rd ← Ry;
Syntax:
I. max Rd, Rx, Ry
Operands:
d, x, y ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 1 1 0 0 0 1 0 0 Rd
215
32000D–04/2011
MCALL – Subroutine Call
Architecture revision:
Architecture revision1 and higher.
Description
Subroutine call to a call destination specified in a location residing in memory.
Operation:
I. LR ← PC + 4
PC ← *((Rp & 0xFFFFFFFC) + (SE(disp16) << 2))
Syntax:
I. mcall Rp[disp]
Operands:
p ∈ {0, 1, …, 15}
disp ∈ {-131072, -131068,…, 131068}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 20 19 16
1 1 1 1 0 0 0 0 0 0 0 1 Rp
15 0
disp16
216 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a read-modify-write operation to clear an arbitrary bit in memory. The word to modify is pointed to
by a signed 17-bit address. This allows the instruction to address the upper 64KB and lower 64KB of mem-
ory. This instruction is part of the optional RMW instruction set.
Operation:
I. *(SE(imm15<<2)[bp5]) ← 0
Syntax:
I. memc imm, bp5
Operands:
bp5 ∈ {0, 1, …, 31}
imm ∈ {-65536, -65532,…, 65532}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 20 19 16
1 1 1 1 0 1 1 0 0 0 0 1 bp5[4:1]
15 14 0
b5[0] imm15
217
32000D–04/2011
MEMS – Set bit in memory
Architecture revision:
Architecture revision1 and higher.
Description
Performs a read-modify-write operation to set an arbitrary bit in memory. The word to modify is pointed to
by a signed 17-bit address. This allows the instruction to address the upper 64KB and lower 64KB of mem-
ory. This instruction is part of the optional RMW instruction set.
Operation:
I. *(SE(imm15<<2)[bp5]) ← 1
Syntax:
I. mems imm, bp5
Operands:
bp5 ∈ {0, 1, …, 31}
imm ∈ {-65536, -65532,…, 65532}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 20 19 16
1 1 1 1 1 0 0 0 0 0 0 1 bp5[4:1]
15 14 0
b5[0] imm15
218 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a read-modify-write operation to toggle an arbitrary bit in memory. The word to modify
is pointed to by a signed 17-bit address. This allows the instruction to address the upper 64KB
and lower 64KB of memory. This instruction is part of the optional RMW instruction set.
Operation:
I. *(SE(imm15<<2)[bp5]) ← ¬*(SE(k15<<2)[bp5])
Syntax:
I. memt imm, bp5
Operands:
bp5 ∈ {0, 1, …, 31}
imm ∈ {-65536, -65532,…, 65532}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 20 19 16
1 1 1 1 1 0 1 0 0 0 0 1 bp5[4:1]
15 14 0
b5[0] imm15
219
32000D–04/2011
MFDR – Move from Debug Register
Architecture revision:
Architecture revision1 and higher.
Description
The instruction copies the value in the specified debug register to the specified register in the
register file. Note that special timing concerns must be considered when operating on the debug
registers, see the Pipeline Chapter for details.
Operation:
I. Rd ← DebugRegister[DebugRegisterAddress << 2];
Syntax:
I. mfdr Rd, DebugRegisterNo
Operands:
I. DebugRegisterNo ∈ {0, 4, 8, ..., 1020}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 20 19 16
1 1 1 0 0 1 0 1 1 0 1 1 Rd
15 8 7 0
0 0 0 0 0 0 0 0 Debug Register Ad-
Note:
Debug registers are implementation defined. If accessing a debug register that does not exist,
the result is UNDEFINED.
This instruction can only be executed in a privileged mode. Execution from any other mode will
trigger a Privilege Violation exception.
220 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
The instruction copies the value in the specified system register to the specified register in the
register file. Note that special timing concerns must be considered when operating on the sys-
tem registers, see the Pipeline Chapter for details.
Operation:
I. Rd ← SystemRegister[SystemRegisterAddress << 2];
Syntax:
I. mfsr Rd, SystemRegisterAddress
Operands:
I. SystemRegisterAddress ∈ {0, 4, 8, ..., 1020}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 20 19 16
1 1 1 0 0 0 0 1 1 0 1 1 Rd
15 8 7 0
0 0 0 0 0 0 0 0 System Register Ad-
Note:
Some system registers are implementation defined. If accessing a system register that does not
exist, the result is UNDEFINED.
With the exception of accessing the JECR and JOSP system registers, this instruction can only
be executed in a privileged mode. Execution from any other mode will trigger a Privilege Viola-
tion exception.
JECR and JOSP can be accessed from all modes with this instruction.
221
32000D–04/2011
MIN – Return Minimum Value
Architecture revision:
Architecture revision1 and higher.
Description
Sets Rd equal to the signed minimum of Rx and Ry.
Operation:
I. If Rx < Ry
Rd ← Rx;
else
Rd ← Ry;
Syntax:
I. min Rd, Rx, Ry
Operands:
d, x, y ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Rd
15 12 11 4 3 0
0 0 0 0 1 1 0 1 0 1 0 0 Rd
222 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Moves a value into a register. The value may be an immediate or the contents of another regis-
ter. Note that Rd may specify PC, resulting in a jump. All flags are unchanged.
Operation:
I. Rd ← SE(imm8);
II. Rd ← SE(imm21);
III. Rd ← Rs;
Syntax:
I. mov Rd, imm
II. mov Rd, imm
III. mov Rd, Rs
Operands:
I. d ∈ {0, 1, …, 15}
imm ∈ {-128, -127, ..., 127}
II. d ∈ {0, 1, …, 15}
imm ∈ {-1048576, -104875, ..., 1048575}
III. d, s ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 11 4 3 0
0 0 1 1 imm8 Rd
Format II:
31 29 28 25 24 21 20 19 16
imm21
1 1 1 imm21[20:17 0 0 1 1 [16] Rd
15 0
imm21[15:0]
223
32000D–04/2011
Format III:
15 13 12 9 8 4 3 0
0 0 0 Rs 0 1 0 0 1 Rd
224 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Copies the contents of the source register or immediate to the destination register. The source
register is unchanged. All flags are unchanged.
Operation:
I. if ( cond4)
Rd ← Rs;
II. if ( cond4)
Rd ← SE(imm8);
Syntax:
I. mov{cond4} Rd, Rs
II. mov{cond4} Rd, imm
Operands:
I. {d, s} ∈ {0, 1, …, 15}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
II. d ∈ {0, 1, …, 15}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
imm ∈ {-128, -127, ..., 127}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 4 3 0
0 0 0 1 0 1 1 1 cond4 0 0 0 0
225
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
1 1 1 1 1 0 0 1 1 0 1 1 Rd
15 12 11 8 7 0
0 0 0 0 cond4 imm8
226 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision 2 and higher.
Description
Moves a value into the high halfword of a register. The low halfword is cleared. All flags are
unchanged.
Operation:
I. Rd ← imm16<<16;
Syntax:
I. movh Rd, imm
Operands:
I. d ∈ {0, 1, …, 15}
imm ∈ {0, 1, ..., 65535}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 1 1 1 0 0 0 0 0 1 Rd
15 0
imm16
227
32000D–04/2011
MTDR – Move to Debug Register
Architecture revision:
Architecture revision1 and higher.
Description
The instruction copies the value in the specified register to the specified debug register. Note
that special timing concerns must be considered when operating on the system registers, see
the Pipeline Chapter for details.
Operation:
I. DebugRegister[DebugRegisterAddress << 2] ← Rs;
Syntax:
I. mtdr DebugRegisterAddress, Rs
Operands:
I. DebugRegisterAddress ∈ {0, 4, 8, ..., 1020}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 20 19 16
1 1 1 0 0 1 1 1 1 0 1 1 Rs
15 8 7 0
0 0 0 0 0 0 0 0 Debug Register Ad-
Note:
The debug registers are implementation defined, and updates of these registers are handled in
an implementation specific way.
This instruction can only be executed in a privileged mode. Execution from any other mode will
trigger a Privilege Violation exception.
228 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
The instruction copies the value in the specified register to the specified system register. Note
that special timing concerns must be considered when operating on the system registers, see
the Implementation Manual for details.
Operation:
I. SystemRegister[SystemRegisterAddress << 2] ← Rs;
Syntax:
I. mtsr SystemRegisterAddress, Rs
Operands:
I. SystemRegisterAddress ∈ {0, 4, 8, ..., 1020}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 20 19 16
1 1 1 0 0 0 1 1 1 0 1 1 Rs
15 8 7 0
0 0 0 0 0 0 0 0 System Register Ad-
Note:
Some system registers are implementation defined. If writing a system register that does not
exist, or to a register that is read only, the instruction is executed but no registers are updated.
With the exception of accessing the JECR and JOSP system registers, this instruction can only
be executed in a privileged mode. Execution from any other mode will trigger a Privilege Viola-
tion exception. JECR and JOSP can be accessed from all modes with this instruction.
The instruction mtsr JOSP, Rx must be used with care. The programmer must ensure that no
change of flow instruction nor an INCJOSP instruction follows mtsr JOSP, Rx within a number of
instructions. This number of cycles is implementation defined. It should also be noted, that this is
true even if the instructions are not to be executed. For instance the sequence
mtsr JOSP, Rx
retj
incjosp
229
32000D–04/2011
will execute with an incorrect result. In practice this warning will only affect programmers writing
their own Java Virtual Machine based on the AVR32 Java Extension module.
230 AVR32
32000D–04/2011
AVR32
MUL – Multiply
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the specified operands and stores the result in the destination register.
Operation:
I. Rd ← Rd × Rs;
II. Rd ← Rx × Ry;
III. Rd ← Rs × SE(imm8)
Syntax:
I. mul Rd, Rs
II. mul Rd, Rx, Ry
III. mul Rd, Rs, imm
Operands:
I. {d, s} ∈ {0, 1, …, 15}
II. {d, x, y} ∈ {0, 1, …, 15}
III. {d, s} ∈ {0, 1, …, 15}
imm ∈ {-128, -127, ..., 127}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 4 3 0
1 0 1 Rs 1 0 0 1 1 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 0 1 0 0 1 0 0 Rd
231
32000D–04/2011
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 0
0 0 0 1 0 0 0 0 imm8
232 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two halfword registers specified and stores the result in the destination word-regis-
ter. The halfword registers are selected as either the high or low part of the operand registers.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
Rd ← operand1 × operand2;
Syntax:
I. mulhh.w Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 8 7 6 5 4 3 0
0 0 0 0 0 1 1 1 1 0 X Y Rd
Example:
mulhh.wR10, R2:t, R3:b
will perform R10 ← SE(R2[31:16]) × SE(R3[15:0])
233
32000D–04/2011
MULNHH.W – Multiply Halfword with Negated Halfword
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two halfword registers specified and stores the result in the destination word-regis-
ter. The halfword registers are selected as either the high or low part of the operand registers.
The result is negated.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
Rd ← - (operand1 × operand2);
Syntax:
I. mulnhh.w Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 8 7 6 5 4 3 0
0 0 0 0 0 0 0 1 1 0 X Y Rd
234 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the word register with the halfword register specified and stores the negated result in
the destination register pair. The halfword register is selected as either the high or low part of Ry.
Since the most significant part of the product is stored, no overflow will occur.
Operation:
I. operand1 = Rx;
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
(Rd+1:Rd)[63:16] ← - (operand1 × operand2);
Rd[15:0] ← 0;
Syntax:
I. mulnwh.d Rd, Rx, Ry:<part>
Operands:
I. d ∈ {0, 2, 4, …, 14}
{x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 5 4 3 0
0 0 0 0 0 0 1 0 1 0 0 Y Rd
235
32000D–04/2011
MULS.D – Multiply Signed
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two registers specified and stores the result in the destination registers.
Operation:
I. Rd+1:Rd ← Rx × Ry;
Syntax:
I. muls.d Rd, Rx, Ry
Operands:
I. d ∈ {0, 2, 4, …, 14}
{x, y} ∈ {0, 1, …, 15}
Status Flags
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 1 0 0 0 1 0 0 Rd
236 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two halfword registers specified, shifts the results one position to the left and
stores the sign-extended high halfword of the result in the destination word-register. If the two
operands equals -1, the result is saturated to the largest positive 16-bit fractional number. The
halfword registers are selected as either the high or low part of the operand registers.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
If (operand1 == operand2 == 0x8000)
Rd ← 0x7FFF;
else
Rd ← SE( (operand1 × operand2) >> 15 );
Syntax:
I. mulsathh.h Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Set if saturation occurred, or previously set.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 6 5 4 3 0
0 0 0 0 1 0 0 0 1 0 X Y Rd
Example:
mulsathh.h R10, R2:t, R3:b
will perform R10 ← SE( Sat(SE(R2[31:16]) × SE(R3[15:0]) ) >> 15 )
237
32000D–04/2011
MULSATHH.W – Multiply Halfwords with Saturation into Word
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two halfword registers specified, shifts the results one position to the left and
stores the result in the destination word-register. If the two operands equals -1, the result is sat-
urated to the largest positive 32-bit fractional number. The halfword registers are selected as
either the high or low part of the operand registers.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
If (operand1 == operand2 == 0x8000)
Rd ← 0x7FFF_FFFF;
else
Rd ← (operand1 × operand2) << 1;
Syntax:
I. mulsathh.w Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Set if saturation occurred, or previously set.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 6 5 4 3 0
0 0 0 0 1 0 0 1 1 0 X Y Rd
Example:
mulsathh.w R10, R2:t, R3:b
will perform R10 ← Sat( (SE(R2[31:16]) × SE(R3[15:0] )) << 1)
238 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two halfword registers specified, shifts the results one position to the left and
stores the result in the destination word-register. If the two operands equal -1, the result is satu-
rated to the largest positive 16-bit fractional number. The halfword registers are selected as
either the high or low part of the operand registers. The product is rounded.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
If (operand1 == operand2 == 0x8000)
Rd ← 0x7FFF;
else
Rd ← SE( ((operand1 × operand2) + 0x4000 ) >> 15 );
Syntax:
I. mulsatrndhh.h Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Set if saturation occurred, or previously set.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 6 5 4 3 0
0 0 0 0 1 0 1 0 1 0 X Y Rd
Example:
mulsatrndhh.h R10, R2:t, R3:b
will perform R10 ← SE( Sat( SE(R2[31:16]) × SE(R3[15:0]) ) + 0x4000) >> 15)
239
32000D–04/2011
MULSATRNDWH.W – Multiply Word and Halfword with Saturation and
Rounding into Word
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the word register with the halfword register specified, rounds the upper 32 bits of the
result and stores it in the destination word-register. The halfword register is selected as either
the high or low part of Ry. Since the most significant part of the product is stored, no overflow will
occur. If the two operands equals -1, the result is saturated to the largest positive 32-bit fractional
number.
Operation:
I. operand1 = Rx;
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
If ((operand1 == 0x8000_0000) && (operand2 == 0x8000))
Rd ← 0x7FFF_FFFF;
else
Rd ← SE( ((operand1 × operand2) + 0x4000 ) >> 15 );
Syntax:
I. mulsatrndwh.w Rd, Rx, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Set if saturation occurred, or previously set.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 5 4 3 0
0 0 0 0 1 0 1 1 1 0 0 Y Rd
Example:
mulsatrndwh.w R10, R2, R3b will perform R10 ← (Sat( R2[31:16] × SE(R3[15:0]) ) +
0x4000) >> 15
240 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the word register with the halfword register specified and stores the upper 32 bits of
the result in the destination word-register. The halfword register is selected as either the high or
low part of Ry. Since the most significant part of the product is stored, no overflow will occur. If
the two operands equal -1, the result is saturated to the largest positive 32-bit fractional number.
Operation:
I. operand1 = Rx;
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
If ((operand1 == 0x8000_0000) && (operand2 == 0x8000))
Rd ← 0x7FFF_FFFF;
else
Rd ← (operand1 × operand2) >> 15;
Syntax:
I. mulsatwh.w Rd, Rx, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Set if saturation occurred, or previously set.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 5 4 3 0
0 0 0 0 1 1 1 0 1 0 0 Y Rd
Example:
mulsatwh.wR10, R2, R3:b
will perform R10 ← Sat( R2 × SE(R3[15:0])) >> 15
241
32000D–04/2011
MULU.D – Multiply Unsigned
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the two registers specified and stores the result in the destination registers.
Operation:
I. Rd+1:Rd ← Rx × Ry;
Syntax:
I. mulu.d Rd, Rx, Ry
Operands:
I. d ∈ {0, 2, 4, …, 14}
{x, y} ∈ {0, 1, …, 15}
Status Flags
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Rd
15 12 11 4 3 0
0 0 0 0 0 1 1 0 0 1 0 0 Rd
242 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Multiplies the word register with the halfword register specified and stores result in the destina-
tion register pair. The halfword register is selected as either the high or low part of Ry. Since the
most significant part of the product is stored, no overflow will occur.
Operation:
I. operand1 = Rx;
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
(Rd+1:Rd)[63:16] ← operand1 × operand2;
Rd[15:0] ← 0;
Syntax:
I. mulwh.d Rd, Rx, Ry:<part>
Operands:
I. d ∈ {0, 2, 4, …, 14}
{x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 5 4 3 0
0 0 0 0 1 1 0 1 1 0 0 Y Rd
243
32000D–04/2011
MUSFR – Copy Register to Status Register
Architecture revision:
Architecture revision1 and higher.
Description
The instruction copies the lower 4 bits of the register Rs to the lower 4 bits of the status register.
Operation:
I. SR[3:0] ← Rs[3:0];
Syntax:
I. musfr Rs
Operands:
I. s ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 1 0 0 1 1 Rs
244 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
The instruction copies the value of the 4 lower bits of the status register into the register Rd. The
value is zero extended.
Operation:
I. Rd ← ZE(SR[3:0]);
Syntax:
I. mustr Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 1 0 0 1 0 Rd
245
32000D–04/2011
MVCR.{D,W} – Move Coprocessor Register to Register file
Architecture revision:
Architecture revision1 and higher.
Description
Addresses a coprocessor and moves the specified registers into the register file.
Operation:
I. (Rd+1:Rd) ← CP#(CRs+1:CRs);
II. Rd ← CP#(CRs);
Syntax:
I. mvcr.d CP#, Rd, CRs
II. mvcr.w CP#, Rd, CRs
Operands:
I. # ∈ {0, 1, …, 7}
{d, s} ∈ {0, 2, 4, …, 14}
II. # ∈ {0, 1, …, 7}
{d, s} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
Format I:
31 29 28 25 24 20 19 17 16
1 1 1 0 1 1 1 1 1 0 1 0 Rd 0
15 13 12 11 9 8 7 0
CP# 0 CRs 0 0 0 0 1 0 0 0 0
Format II:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rd
15 13 12 11 8 7 0
CP# 0 CRs 0 0 0 0 0 0 0 0
Example:
mvcr.d CP2, R0, CR2
246 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Moves the specified register into the addressed coprocessor.
Operation:
I. CP#(CRd+1:CRd) ← Rs+1:Rs;
II. CP#(CRd) ← Rs;
Syntax:
I. mvrc.d CP#, CRd, Rs
II. mvrc.w CP#, CRd, Rs
Operands:
I. # ∈ {0, 1, …, 7}
{d, s} ∈ {0, 2, 4, …, 14}
I. # ∈ {0, 1, …, 7}
{d, s} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
Format I:
31 29 28 25 24 20 19 17 16
1 1 1 0 1 1 1 1 1 0 1 0 Rs 0
15 13 12 11 9 8 7 0
CP# 0 CRd 0 0 0 1 1 0 0 0 0
Format II:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rs
15 13 12 11 8 7 0
CP# 0 CRd 0 0 1 0 0 0 0 0
Example:
mvrc.d CP2, CR0, R2
247
32000D–04/2011
NEG – Two’s Complement
Architecture revision:
Architecture revision1 and higher.
Description
Perform a two’s complement of specified register.
Operation:
I. Rd ← 0 -Rd;
Syntax:
I. neg Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: V ← Rd[31] ∧ RES[31]
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← Rd[31] ∨ RES[31]
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 0 0 1 1 Rd
248 AVR32
32000D–04/2011
AVR32
NOP – No Operation
Architecture revision:
Architecture revision1 and higher.
Description
Special instructions for "no operation" that does not create data depencencies in the pipeline
Operation:
I. none
Syntax:
I. nop
Operands:
I. none
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 1 0 0 0 0 0 0 1 1
249
32000D–04/2011
OR – Logical OR with optional logical shift
Architecture revision:
Architecture revision1 and higher.
Description
Performs a bitwise logical OR between the specified registers and stores the result in the desti-
nation register.
Operation:
I. Rd ← Rd ∨ Rs;
II. Rd ← Rx ∨ (Ry << sa5);
III. Rd ← Rx ∨ (Ry >> sa5);
Syntax:
I. or Rd, Rs
II. or Rd, Rx, Ry << sa
III. or Rd, Rx, Ry >> sa
Operands:
I. {d, s} ∈ {0, 1, …, 15}
II, III. {d, x, y} ∈ {0, 1, …, 15}
sa ∈ {0, 1, …, 31}
Status Flags:
Q: Not affected.
V: Not affected.
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rs 0 0 1 0 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 1 0 Ry
15 9 8 4 3 0
0 0 0 1 0 0 0 sa5 Rd
250 AVR32
32000D–04/2011
AVR32
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 1 0 Ry
15 9 8 4 3 0
0 0 0 1 0 0 1 sa5 Rd
251
32000D–04/2011
OR{cond4} – Conditional logical OR
Architecture revision:
Architecture revision 2 and higher.
Description
Performs a bitwise logical OR between the specified registers and stores the result in the desti-
nation register.
Operation:
I. if ( cond4)
Rd ← Rx ∨ Ry;
Syntax:
I. or{cond4} Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 0 1 Ry
15 12 11 8 7 0
1 1 1 0 cond4 0 0 1 1 Rd
252 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a bitwise logical OR between the high or low word in the specified register and a con-
stant. The result is stored in the destination register.
Operation:
I. Rd[31:16] ← Rd[31:16] ∨ imm16;
II. Rd[15:0] ← Rd[15:0] ∨ imm16;
Syntax:
I. orh Rd, imm
II. orl Rd, imm
Operands:
I, II. d ∈ {0, 1, …, 15}
imm ∈ {0, 1, ..., 65535}
Status Flags:
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode
Format I:
31 29 28 20 19 16
1 1 1 0 1 0 1 0 0 0 0 1 Rd
15 0
imm16
Format II:
31 29 28 20 19 16
1 1 1 0 1 0 0 0 0 0 0 1 Rd
15 0
imm16
253
32000D–04/2011
PABS.{SB/SH} – Packed absolute value
Architecture revision:
Architecture revision1 and higher.
Description
Compute the absolute values of four packed signed bytes (pabs.sb) or two packed signed half-
words (pabs.sh) from the source register and store the results as packed bytes or halfwords in
the destination register.
Operation:
I. Rd[31:24] ← | Rs[31:24] |; Rd[23:16] ← | Rs[23:16] |;
Rd[15:8] ← | Rs[15:8] |; Rd[7:0] ← | Rs[7:0] |;
II. Rd[31:16] ← | Rs[31:16] |;
Rd[15:0] ← | Rs[15:0] |;
Syntax:
I. pabs.sb Rd, Rs
II. pabs.sh Rd, Rs
Operands:
I, II. {d, s} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 20 19 16
1 1 1 0 0 0 0 0 0 0 0 0 Rs
15 4 3 0
0 0 1 0 0 0 1 1 1 1 1 0 Rd
Format II:
31 20 19 16
1 1 1 0 0 0 0 0 0 0 0 0 Rs
15 4 3 0
0 0 1 0 0 0 1 1 1 1 1 1 Rd
254 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Pack the four signed halfwords located in the two source registers into four bytes in the destina-
tion register. Each of the signed halfwords are saturated to unsigned (packsh.ub) or signed bytes
(packsh.sb).
Operation:
I. Rd[31:24] ← SATSU(Rx[31:16], 8); Rd[23:16] ← SATSU(Rx[15:0], 8);
Rd[15:8] ← SATSU(Ry[31:16], 8); Rd[7:0] ← SATSU(Ry[15:0], 8);
II. Rd[31:24] ← SATS(Rx[31:16], 8); Rd[23:16] ← SATS(Rx[15:0], 8);
Rd[15:8] ← SATS(Ry[31:16], 8); Rd[7:0] ← SATS(Ry[15:0], 8);
Syntax:
I. packsh.ub Rd, Rx, Ry
II. packsh.sb Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Flag set if saturation occured in one or more of the partial operations.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 1 0 0 1 1 0 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 1 0 0 1 1 0 1 Rd
255
32000D–04/2011
256 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Pack the two words given in the source registers into two halfwords in the destination register.
Each of the words are saturated to signed halfwords before being packed.
Operation:
I. Rd[31:16] ← SATS(Rx, 16);
Rd[15:0] ← SATS(Ry, 16);
Syntax:
I. packw.sh Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Flag set if saturation occured in one or more of the partial operations.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 1 0 0 0 1 1 1 Rd
257
32000D–04/2011
PADD.{B/H} – Packed Addition
Architecture revision:
Architecture revision1 and higher.
Description
Perform addition of four pairs of packed bytes (padd.b) or two pairs of halfwords (padd.h). Upon
overflow any additional bits are discarded and the result is wrapped around.
Operation:
I. Rd[31:24] ← Rx[31:24] + Ry[31:24]; Rd[23:16] ← Rx[23:16] + Ry[23:16];
Rd[15:8] ← Rx[15:8] + Ry[15:8]; Rd[7:0] ← Rx[7:0] + Ry[7:0];
II. Rd[31:16] ← Rx[31:16] + Ry[31:16];
Rd[15:0] ← Rx[15:0] + Ry[15:0];
Syntax:
I. padd.b Rd, Rx, Ry
II. padd.h Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 0 0 0 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 0 0 0 0 Rd
258 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Perform addition of four pairs of packed unsigned bytes (paddh.ub) or two pairs of packed signed
halfwords (paddh.sh) with a halving of the result to prevent any overflows from occuring.
Operation:
I. Rd[31:24] ← LSR(ZE(Rx[31:24], 9) + ZE(Ry[31:24], 9), 1) ;
Rd[23:16] ← LSR(ZE(Rx[23:16], 9) + ZE(Ry[23:16], 9), 1);
Rd[15:8] ← LSR(ZE(Rx[15:8], 9) + ZE(Ry[15:8], 9), 1);
Rd[7:0] ← LSR(ZE(Rx[7:0], 9) + ZE(Ry[7:0], 9), 1);
II. Rd[31:16] ← ASR(SE(Rx[31:16], 17) + SE(Ry[31:16], 17), 1);
Rd[15:0] ← ASR(SE(Rx[15:0], 17) + SE(Ry[15:0], 17), 1);
Syntax:
I. paddh.ub Rd, Rx, Ry
II. paddh.sh Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 0 1 1 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 1 1 0 0 Rd
259
32000D–04/2011
PADDS.{UB/SB/UH/SH} – Packed Addition with Saturation
Architecture revision:
Architecture revision1 and higher.
Description
Perform addition of four pairs of packed bytes or two pairs of halfwords. The result is saturated to
either unsigned bytes (padds.ub), signed bytes (padds.sb), unsigned halfwords (padds.uh) or
signed halfwords (padds.sh).
Operation:
I. Rd[31:24] ← SATU(ZE(Rx[31:24], 9) + ZE(Ry[31:24], 9), 8) ;
Rd[23:16] ← SATU(ZE(Rx[23:16], 9) + ZE(Ry[23:16], 9), 8);
Rd[15:8] ← SATU(ZE(Rx[15:8], 9) + ZE(Ry[15:8], 9), 8);
Rd[7:0] ← SATU(ZE(Rx[7:0], 9) + ZE(Ry[7:0], 9), 8);
II. Rd[31:24] ← SATS(SE(Rx[31:24], 9) + SE(Ry[31:24], 9), 8);
Rd[23:16] ← SATS(SE(Rx[23:16], 9) + SE(Ry[23:16], 9), 8);
Rd[15:8] ← SATS(SE(Rx[15:8], 9) + SE(Ry[15:8], 9), 8);
Rd[7:0] ← SATS(SE(Rx[7:0], 9) + SE(Ry[7:0], 9), 8);
III. Rd[31:16] ← SATU(ZE(Rx[31:16], 17) + ZE(Ry[31:16], 17), 16);
Rd[15:0] ← SATU(ZE(Rx[15:0], 17) + ZE(Ry[15:0], 17), 16);
IV. Rd[31:16] ← SATS(SE(Rx[31:16], 17) + SE(Ry[31:16], 17), 16);
Rd[15:0] ← SATS(SE(Rx[15:0], 17) + SE(Ry[15:0], 17), 16);
Syntax:
I. padds.ub Rd, Rx, Ry
II. padds.sb Rd, Rx, Ry
III. padds.uh Rd, Rx, Ry
IV. padds.sh Rd, Rx, Ry
Operands:
I, II, III, IV.{d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Flag set if saturation occured in one or more of the partial operations.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
260 AVR32
32000D–04/2011
AVR32
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 0 1 0 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 0 0 1 0 Rd
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 1 0 0 0 Rd
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 0 1 0 0 Rd
261
32000D–04/2011
PADDSUB.H – Packed Halfword Addition and Subtraction
Architecture revision:
Architecture revision1 and higher.
Description
Perform an addition and subtraction on the same halfword operands which are selected from the
source registers. The two halfword results are packed into the destination register without per-
forming any saturation.
Operation:
Syntax:
I. paddsub.h Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 6 5 4 3 0
0 0 1 0 0 0 0 1 0 0 X Y Rd
262 AVR32
32000D–04/2011
AVR32
Description
Perform an addition and subtraction on the same signed halfword operands which are selected
from the source registers. The halfword results are halved in order to prevent any overflows from
occuring
Operation:
Syntax:
I. paddsubh.sh Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 6 5 4 3 0
0 0 1 0 0 0 1 0 1 0 X Y Rd
263
32000D–04/2011
PADDSUBS.{UH/SH} – Packed Halfword Addition and Subtraction with Sat-
uration
Architecture revision:
Architecture revision1 and higher.
Description
Perform an addition and subtraction on the same halfword operands which are selected from the
source registers. The resulting halfwords are saturated to unsigned halfwords (paddsubs.uh) or
signed halfwords (paddsubs.sh) and then packed together in the destination register.
Operation:
I. If (Rx-part == t) then operand1 = Rx[31:16] else operand1 = Rx[15:0];
If (Ry-part == t) then operand2 = Ry[31:16] else operand2 = Ry[15:0];
Rd[31:16] ← SATU(ZE(operand1, 17) + ZE(operand2, 17), 16);
Rd[15:0] ← SATSU(ZE(operand1, 17) - ZE(operand2, 17), 16);
II. If (Rx-part == t) then operand1 = Rx[31:16] else operand1 = Rx[15:0];
If (Ry-part == t) then operand2 = Ry[31:16] else operand2 = Ry[15:0];
Rd[31:16] ← SATS(SE(operand1, 17) + SE(operand2, 17), 16);
Rd[15:0] ← SATS(SE(operand1, 17) - SE(operand2, 17), 16);
Syntax:
I. paddsubs.uh Rd, Rx:<part>, Ry:<part>
II. paddsubs.sh Rd, Rx:<part>, Ry:<part>
Operands:
I,II. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Flag set if saturation occured in one or more of the partial operations.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 6 5 4 3 0
0 0 1 0 0 0 1 0 0 0 X Y Rd
264 AVR32
32000D–04/2011
AVR32
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 6 5 4 3 0
0 0 1 0 0 0 0 1 1 0 X Y Rd
265
32000D–04/2011
PADDX.H – Packed Halfword Addition with Crossed Operand
Architecture revision:
Architecture revision1 and higher.
Description
Add together the top halfword of Rx with the bottom halfword of Ry and the bottom halfword of
Rx with the top halfword of Ry. The resulting halfwords are packed together in the destination
register without performing any saturation.
Operation:
I. Rd[31:16] ← Rx[31:16] + Ry[15:0] ;
Rd[15:0] ← Rx[15:0] + Ry[31:16];
Syntax:
I. paddx.h Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 0 0 1 0 Rd
266 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Add together the top halfword of Rx with the bottom halfword of Ry and the bottom halfword of
Rx with the top halfword of Ry. The resulting halfwords are halved in order to avoid any overflow
and then packed together in the destination register.
Operation:
I. Rd[31:16] ← ASR(SE(Rx[31:16], 17) + SE(Ry[15:0], 17), 1);
Rd[15:0] ← ASR(SE(Rx[15:0], 17) + SE(Ry[31:16], 17), 1);
Syntax:
I. paddxh.sh Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 1 1 1 0 Rd
267
32000D–04/2011
PADDXS.{UH/SH} – Packed Halfword Addition with Crossed Operand and
Saturation
Architecture revision:
Architecture revision1 and higher.
Description
Add together the top halfword of Rx with the bottom halfword of Ry and the bottom halfword of
Rx with the top halfword of Ry. The resulting halfwords are saturated to unsigned halfwords
(paddxh.uh) or signed halfwords (paddxh.sh) and then packed together in the destination regis-
ter.
Operation:
I. Rd[31:16] ← SATU(ZE(Rx[31:16], 17) + ZE(Ry[15:0], 17), 16) ;
Rd[15:0] ← SATU(ZE(Rx[15:0], 17) + ZE(Ry[31:16], 17), 16);
II. Rd[31:16] ← SATS(SE(Rx[31:16], 17) + SE(Ry[15:0], 17), 16) ;
Rd[15:0] ← SATS(SE(Rx[15:0], 17) + SE(Ry[31:16], 17), 16);
Syntax:
I. paddxs.uh Rd, Rx, Ry
II. paddxs.sh Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Flag set if saturation occured in one or more of the partial operations.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 1 0 1 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 0 1 1 0 Rd
268 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Perform an arithmetic shift right on each of the packed bytes or halfwords in the source register.
Operation:
I. Rd[31:24] ← ASR(Rs[31:24], sa3);
Rd[23:16] ← ASR(Rs[23:16], sa3);
Rd[15:8] ← ASR(Rs[15:8], sa3);
Rd[7:0] ← ASR(Rs[7:0], sa3);
II. Rd[31:16] ← ASR(Rs[31:16], sa4);
Rd[15:0] ← ASR(Rs[15:0], sa4);
Syntax:
I. pasr.b Rd, Rs, sa
II. pasr.h Rd, Rs, sa
Operands:
I, II. {d, s} ∈ {0, 1, …, 15}
I. sa ∈ {0, 1, …, 7}
II. sa ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 19 18 16
1 1 1 Rs 0 0 0 0 0 0 sa3
15 4 3 0
0 0 1 0 0 1 0 0 0 0 0 1 Rd
269
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 sa4
15 4 3 0
0 0 1 0 0 1 0 0 0 1 0 0 Rd
270 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Computes the average of pairs of packed unsigned bytes (pavg.ub) or packed signed halfwords
(pavg.sh). The averages are computed by adding two values together while also adding in a
rounding factor in the least significant bit. The result is then halved by shifting it one position to
the right.
Operation:
I. Rd[31:24] ← LSR(ZE(Rx[31:24], 9) + ZE(Ry[31:24], 9) + 1, 1);
Rd[23:16] ← LSR(ZE(Rx[23:16], 9) + ZE(Ry[23:16], 9) + 1, 1);
Rd[15:8] ← LSR(ZE(Rx[15:8], 9) + ZE(Ry[15:8], 9) + 1, 1);
Rd[7:0] ← LSR(ZE(Rx[7:0], 9) + ZE(Ry[7:0], 9) + 1, 1);
II. Rd[31:16] ← ASR(SE(Rx[31:16], 17) + SE(Ry[31:16], 17) + 1, 1);
Rd[15:0] ← ASR(SE(Rx[15:0], 17) + SE(Ry[15:0], 17) + 1, 1);
Syntax:
I. pavg.ub Rd, Rx, Ry
II. pavg.sh Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 1 1 0 0 Rd
271
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 1 1 0 1 Rd
272 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Perform a logical shift left on each of the packed bytes or halfwords in the source register and
store the result to the destination register.
Operation:
I. Rd[31:24] ← LSL(Rs[31:24], sa3);
Rd[23:16] ← LSL(Rs[23:16], sa3);
Rd[15:8] ← LSL(Rs[15:8], sa3);
Rd[7:0] ← LSL(Rs[7:0], sa3);
II. Rd[31:16] ← LSL(Rs[31:16], sa4);
Rd[15:0] ← LSL(Rs[15:0], sa4);
Syntax:
I. plsl.b Rd, Rs, sa
II. plsl.h Rd, Rs, sa
Operands:
I, II. {d, s} ∈ {0, 1, …, 15}
I. sa ∈ {0, 1, …, 7}
II. sa ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 19 18 16
1 1 1 Rs 0 0 0 0 0 0 sa3
15 4 3 0
0 0 1 0 0 1 0 0 0 0 1 0 Rd
273
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 sa4
15 4 3 0
0 0 1 0 0 1 0 0 0 1 0 1 Rd
274 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Perform a logical shift right on each of the packed bytes or halfwords in the source register and
store the result to the destination register.
Operation:
I. Rd[31:24] ← LSR(Rs[31:24], sa3);
Rd[23:16] ← LSR(Rs[23:16], sa3);
Rd[15:8] ← LSR(Rs[15:8], sa3);
Rd[7:0] ← LSR(Rs[7:0], sa3);
II. Rd[31:16] ← LSR(Rs[31:16], sa4);
Rd[15:0] ← LSR(Rs[15:0], sa4);
Syntax:
I. plsr.b Rd, Rs, sa
II. plsr.h Rd, Rs, sa
Operands:
I, II. {d, s} ∈ {0, 1, …, 15}
I. sa ∈ {0, 1, …, 7}
II. sa ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 19 18 16
1 1 1 Rs 0 0 0 0 0 0 sa3
15 4 3 0
0 0 1 0 0 1 0 0 0 0 1 1 Rd
275
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 sa4
15 4 3 0
0 0 1 0 0 1 0 0 0 1 1 0 Rd
276 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Compute the maximum values of pairs of packed unsigned bytes (pmax.ub) or packed signed
halfwords (pmax.sh).
Operation:
I. If ( Rx[31:24] > Ry[31:24] ) then Rd[31:24] ← Rx[31:24] else Rd[31:24] ← Ry[31:24] ;
If ( Rx[23:16] > Ry[23:16] ) then Rd[23:16] ← Rx[23:16] else Rd[23:16] ← Ry[23:16] ;
If ( Rx[15:8] > Ry[15:8] ) then Rd[15:8] ← Rx[15:8] else Rd[15:8] ← Ry[15:8] ;
If ( Rx[7:0] > Ry[7:0] ) then Rd[7:0] ← Rx[7:0] else Rd[7:0] ← Ry[7:0] ;
II. If ( Rx[31:16] > Ry[31:16] ) then Rd[31:16] ← Rx[31:16] else Rd[31:16] ← Ry[31:16] ;
If ( Rx[15:0] > Ry[15:0] ) then Rd[15:0] ← Rx[15:0] else Rd[15:0] ← Ry[15:0] ;
Syntax:
I. pmax.ub Rd, Rx, Ry
II. pmax.sh Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Format I:
Q: Not affected.
V: ( Rx[7:0] > Ry[7:0] )
N: ( Rx[15:8] > Ry[15:8] )
Z: ( Rx[23:16] > Ry[23:16] )
C: ( Rx[31:24] > Ry[31:24] )
Format II:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: ( Rx[15:0] > Ry[15:0] )
C: ( Rx[31:16] > Ry[31:16] )
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 1 0 0 0 Rd
277
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 1 0 0 1 Rd
278 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Compute the minimum values of pairs of packed unsigned bytes (pmin.ub) or packed signed
halfwords (pmin.sh).
Operation:
I. If ( Rx[31:24] < Ry[31:24] ) then Rd[31:24] ← Rx[31:24] else Rd[31:24] ← Ry[31:24] ;
If ( Rx[23:16] < Ry[23:16] ) then Rd[23:16] ← Rx[23:16] else Rd[23:16] ← Ry[23:16] ;
If ( Rx[15:8] < Ry[15:8] ) then Rd[15:8] ← Rx[15:8] else Rd[15:8] ← Ry[15:8] ;
If ( Rx[7:0] < Ry[7:0] ) then Rd[7:0] ← Rx[7:0] else Rd[7:0] ← Ry[7:0] ;
II. If ( Rx[31:16] < Ry[31:16] ) then Rd[31:16] ← Rx[31:16] else Rd[31:16] ← Ry[31:16] ;
If ( Rx[15:0] < Ry[15:0] ) then Rd[15:0] ← Rx[15:0] else Rd[15:0] ← Ry[15:0] ;
Syntax:
I. pmin.ub Rd, Rx, Ry
II. pmin.sh Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Format I:
Q: Not affected.
V: ( Rx[7:0] < Ry[7:0] )
N: ( Rx[15:8] < Ry[15:8] )
Z: ( Rx[23:16] < Ry[23:16] )
C: ( Rx[31:24] < Ry[31:24] )
Format II:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: ( Rx[15:0] < Ry[15:0] )
C: ( Rx[31:16] < Ry[31:16] )
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 1 0 1 0 Rd
279
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 1 0 1 1 Rd
280 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Fetch the system registers LV0 to LV7 used in Java state from the current method frame. The
register FRAME (equal to R9) is used as pointer register.
Operation:
I. temp ←FRAME;
JAVA_LV0 ←*(temp--);
JAVA_LV1 ←*(temp--);
JAVA_LV2 ←*(temp--);
JAVA_LV3 ←*(temp--);
JAVA_LV4 ←*(temp--);
JAVA_LV5 ←*(temp--);
JAVA_LV6 ←*(temp--);
JAVA_LV7 ←*(temp--);
Syntax:
I. popjc
Operands:
I. none
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 1
281
32000D–04/2011
POPM – Pop Multiple Registers from Stack
Architecture revision:
Architecture revision1 and higher.
Description
Loads the consecutive words pointed to by SP into the registers specified in the instruction. The
PC can be loaded, resulting in a jump to the loaded value. If PC is popped, the return value in
R12 is tested and the flags are updated. R12 can optionally be updated with -1, 0 or 1. The k bit
in the instruction coding is used to optionally let the POPM instruction update the return register
R12 with the values -1, 0 or 1.
Operation:
I. if Reglist8[PC] ∧ k == B’1
PC ← *(SP++)
if Reglist8[LR:R12] == B’00
R12 ← 0;
else if Reglist8[LR:R12] == B’01
R12 ← 1;
else
R12 ← −1;
Test R12 and update flags;
else
if Reglist8[PC] == 1 then
PC ← *(SP++);
if Reglist8[LR] == 1 then
LR ← *(SP++);
if Reglist8[R12] == 1 then
R12 ←*(SP++);
if Reglist8[PC] == 1 then
Test R12 and update flags;
if Reglist8[5] == 1 then
R11 ←*(SP++);
if Reglist8[4] == 1 then
R10 ←*(SP++);
if Reglist8[3] == 1 then
R9 ← *(SP++);
R8 ← *(SP++);
if Reglist8[2] == 1 then
R7 ← *(SP++);
R6 ← *(SP++);
R5 ← *(SP++);
R4 ← *(SP++);
if Reglist8[1] == 1 then
R3 ← *(SP++);
282 AVR32
32000D–04/2011
AVR32
R2 ← *(SP++);
R1 ← *(SP++);
R0 ← *(SP++);
Syntax:
I. popm Reglist8 {, R12 = {-1, 0, 1}}
If the optional R12 = {-1, 0, 1} parameter is specified, PC must be in Reglist8.
If the optional R12 = {-1, 0, 1} parameter is specified, LR should NOT be in Reglist8.
Operands:
I. Reglist8 ∈ {R0- R3, R4-R7, R8-R9, R10,R11, R12, LR, PC}
Status Flags:
Flags are only updated if Reglist8[PC] == 1.
They are set as the result of the operation cp R12, 0
Q: Not affected
V: V←0
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C←0
Opcode:
15 3 2 0
1 1 0 1 PC LR 12 11 10 9-8 7-4 3-0 k 0 1 0
Note:
Emtpy Reglist8 gives UNDEFINED result.
The R bit in the status register has no effect on this instruction.
283
32000D–04/2011
PREF – Cache Prefetch
Architecture revision:
Architecture revision1 and higher.
Description
This instruction allows the programmer to explicitly state that the cache should prefetch the
specified line. The memory system treats this instruction in an implementation-dependent man-
ner, and implementations without cache treats the instruction as a NOP. A prefetch instruction
never reduces the performance of the system. If the prefetch instruction performs an action that
would lower the system performance, it is treated as a NOP. For example, if the prefetch instruc-
tion is about to generate an addressing exception, the instruction is cancelled and no exception
is taken.
Operation:
I. Prefetch cache line containing the address (Rp + SE(disp16)).
Syntax:
pref Rp[disp]
Operands:
I. p ∈ {0, 1, …, 15}
disp ∈ {-32768, -32767, ..., 32767}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 20 19 16
1 1 1 1 0 0 1 0 0 0 0 1 Rp
15 0
disp16
284 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Compute the Sum of Absolute Differences (SAD) of four pairs of packed unsigned bytes from the
source registers and store the result in the destination register.
Operation:
I. Rd ← | Rx[31:24] - Ry[31:24] | + | Rx[23:16] - Ry[23:16] | +
| Rx[15:8] - Ry[15:8] | + | Rx[7:0] - Ry[7:0] |;
Syntax:
I. psad Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 1 0 0 0 0 0 0 Rd
285
32000D–04/2011
PSUB.{B/H} – Packed Subtraction
Architecture revision:
Architecture revision1 and higher.
Description
Perform subtraction of four pairs of packed bytes (psub.b) or two pairs of halfwords (psub.h).
Upon overflow any additional bits are discarded and the result is wrapped around.
Operation:
I. Rd[31:24] ← Rx[31:24] - Ry[31:24]; Rd[23:16] ← Rx[23:16] - Ry[23:16];
Rd[15:8] ← Rx[15:8] - Ry[15:8]; Rd[7:0] ← Rx[7:0] - Ry[7:0];
II. Rd[31:16] ← Rx[31:16] - Ry[31:16];
Rd[15:0] ← Rx[15:0] - Ry[15:0];
Syntax:
I. psub.b Rd, Rx, Ry
II. psub.h Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 0 0 0 1 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 0 0 0 1 Rd
286 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Perform an subtraction and addition on the same halfword operands which are selected from the
source registers. The two halfword results are packed into the destination register without per-
forming any saturation.
Operation:
Syntax:
I. psubadd.h Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 6 5 4 3 0
0 0 1 0 0 0 0 1 0 1 X Y Rd
287
32000D–04/2011
PSUBADDH.SH – Packed Signed Halfword Subtraction and Addition with
Halving
Architecture revision:
Architecture revision1 and higher.
Description
Perform a subtraction and addition on the same halfword operands which are selected from the
source registers. The halfword results are halved in order to prevent any overflows from occuring
Operation:
Syntax:
I. psubaddh.sh Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 6 5 4 3 0
0 0 1 0 0 0 1 0 1 1 X Y Rd
288 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Perform a subtraction and addition on the same halfword operands which are selected from the
source registers. The resulting halfwords are saturated to unsigned halfwords (psubadds.uh) or
signed halfwords (psubadds.sh) and then packed together in the destination register.
Operation:
I. If (Rx-part == t) then operand1 = Rx[31:16] else operand1 = Rx[15:0];
If (Ry-part == t) then operand2 = Ry[31:16] else operand2 = Ry[15:0];
Rd[31:16] ← SATSU(ZE(operand1, 17) - ZE(operand2, 17), 16);
Rd[15:0] ← SATU(ZE(operand1, 17) + ZE(operand2, 17), 16);
II. If (Rx-part == t) then operand1 = Rx[31:16] else operand1 = Rx[15:0];
If (Ry-part == t) then operand2 = Ry[31:16] else operand2 = Ry[15:0];
Rd[31:16] ← SATS(SE(operand1, 17) - SE(operand2, 17), 16 );
Rd[15:0] ← SATS(SE(operand1, 17) + SE(operand2, 17), 16);
Syntax:
I. psubadds.uh Rd, Rx:<part>, Ry:<part>
II. psubadds.sh Rd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
Q: Flag set if saturation occured in one or more of the partial operations.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 6 5 4 3 0
0 0 1 0 0 0 1 0 0 1 X Y Rd
289
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 6 5 4 3 0
0 0 1 0 0 0 0 1 1 1 X Y Rd
290 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Perform subtraction of four pairs of packed unsigned bytes (psub.ub) or two pairs of signed half-
words (psub.sh) with a halfing of the result to prevent any overflows from occuring.
Operation:
I. Rd[31:24] ← LSR(ZE(Rx[31:24], 9) - ZE(Ry[31:24], 9), 1);
Rd[23:16] ← LSR(ZE(Rx[23:16], 9) - ZE(Ry[23:16], 9), 1);
Rd[15:8] ← LSR(ZE(Rx[15:8], 9) - ZE(Ry[15:8], 9), 1);
Rd[7:0] ← LSR(ZE(Rx[7:0], 9) - ZE(Ry[7:0], 9), 1);
II. Rd[31:16] ← ASR(SE(Rx[31:16], 17) - SE(Ry[31:16], 17), 1);
Rd[15:0] ← ASR(SE(Rx[15:0], 17) - SE(Ry[15:0], 17), 1);
Syntax:
I. psubh.ub Rd, Rx, Ry
II. psubh.sh Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 0 1 1 1 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 1 1 0 1 Rd
291
32000D–04/2011
PSUBS.{UB/SB/UH/SH} – Packed Subtraction with Saturation
Architecture revision:
Architecture revision1 and higher.
Description
Perform subtraction of four pairs of packed bytes or two pairs of halfwords. The result is satu-
rated to either unsigned bytes (psubs.ub), signed bytes (psubs.sb), unsigned halfwords
(psubs.uh) or signed halfwords (psubs.sh).
Operation:
I. Rd[31:24] ← SATSU(ZE(Rx[31:24], 9) - ZE(Ry[31:24], 9), 8) ;
Rd[23:16] ← SATSU(ZE(Rx[23:16], 9) - ZE(Ry[23:16], 9), 8);
Rd[15:8] ← SATSU(ZE(Rx[15:8], 9) - ZE(Ry[15:8], 9), 8);
Rd[7:0] ← SATSU(ZE(Rx[7:0], 9) - ZE(Ry[7:0], 9), 8);
II. Rd[31:24] ← SATS(SE(Rx[31:24], 9) - SE(Ry[31:24], 9), 8);
Rd[23:16] ← SATS(SE(Rx[23:16], 9) - SE(Ry[23:16], 9), 8);
Rd[15:8] ← SATS(SE(Rx[15:8], 9) - SE(Ry[15:8], 9), 8);
Rd[7:0] ← SATS(SE(Rx[7:0], 9) - SE(Ry[7:0], 9), 8);
III. Rd[31:16] ← SATSU(ZE(Rx[31:16], 17) - ZE(Ry[31:16], 17), 16);
Rd[15:0] ← SATSU(ZE(Rx[15:0], 17) - ZE(Ry[15:0], 17), 16);
IV. Rd[31:16] ← SATS(SE(Rx[31:16], 17) - SE(Ry[31:16], 17), 16);
Rd[15:0] ← SATS(SE(Rx[15:0], 17) - SE(Ry[15:0], 17), 16);
Syntax:
I. psubs.ub Rd, Rx, Ry
II. psubs.sb Rd, Rx, Ry
III. psubs.uh Rd, Rx, Ry
IV. psubs.sh Rd, Rx, Ry
Operands:
I, II, III, IV.{d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Flag set if saturation occured in one or more of the partial operations.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 0 1 0 1 Rd
292 AVR32
32000D–04/2011
AVR32
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 1 1 0 0 1 1 Rd
Format III:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 1 0 0 1 Rd
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 0 1 0 1 Rd
293
32000D–04/2011
PSUBX.H – Packed Halfword Subtraction with Crossed Operand
Architecture revision:
Architecture revision1 and higher.
Description
Subtract the bottom halfword of Ry from the top halfword of Rx and the top halfword of Ry from
the bottom halfword of Rx. The resulting halfwords are packed together in the destination regis-
ter without performing any saturation.
Operation:
I. Rd[31:16] ← Rx[31:16] - Ry[15:0] ;
Rd[15:0] ← Rx[15:0] - Ry[31:16];
Syntax:
I. psubx.h Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 0 0 1 1 Rd
294 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Subtract the bottom halfword of Ry from the top halfword of Rx and the top halfword of Ry from
the bottom halfword of Rx. The resulting halfwords are halved in order to avoid any overflow and
then packed together in the destination register.
Operation:
I. Rd[31:16] ← ASR(SE(Rx[31:16], 17) - SE(Ry[15:0], 17), 1);
Rd[15:0] ← ASR(SE(Rx[15:0], 17) - SE(Ry[31:16], 17), 1);
Syntax:
I. psubxh.sh Rd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 1 1 1 1 Rd
295
32000D–04/2011
PSUBXS.{UH/SH} – Packed Halfword Subtraction with Crossed Operand
and Saturation
Architecture revision:
Architecture revision1 and higher.
Description
Subtract the bottom halfword of Ry from the top halfword of Rx and the top halfword of Ry from
the bottom halfword of Rx. The resulting halfwords are saturated to unsigned halfwords
(psubxh.uh) or signed halfwords (psubxh.sh) and then packed together in the destination regis-
ter.
Operation:
I. Rd[31:16] ← SATSU(ZE(Rx[31:16], 17) - ZE(Ry[15:0], 17), 16) ;
Rd[15:0] ← SATSU(ZE(Rx[15:0], 17) - ZE(Ry[31:16], 17), 16);
II. Rd[31:16] ← SATS(SE(Rx[31:16], 17) - SE(Ry[15:0], 17), 16) ;
Rd[15:0] ← SATS(SE(Rx[15:0], 17) - SE(Ry[31:16], 17), 16);
Syntax:
I. psubxs.uh Rd, Rx, Ry
II. psubxs.sh Rd, Rx, Ry
Operands:
I, II. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Flag set if saturation occured in one or more of the partial operations.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 1 0 1 1 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 4 3 0
0 0 1 0 0 0 0 0 0 1 1 1 Rd
296 AVR32
32000D–04/2011
AVR32
297
32000D–04/2011
PUNPCK{SB/UB}.H – Unpack bytes to halfwords
Architecture revision:
Architecture revision1 and higher.
Description
Unpack two unsigned bytes (punpckub.h) or two signed bytes (punpcksb.h) from the source reg-
ister to two packed halfwords in the destination register.
Operation:
I. If ( Rs-part == top ) then
Rd[31:16] ← ZE(Rs[31:24], 16); Rd[15:0] ← ZE(Rs[23:16], 16);
else
Rd[31:16] ← ZE(Rs[15:8], 16); Rd[15:0] ← ZE(Rs[7:0], 16);
II. If ( Rs-part == top ) then
Rd[31:16] ← SE(Rs[31:24], 16); Rd[15:0] ← SE(Rs[23:16], 16);
else
Rd[31:16] ← SE(Rs[15:8], 16); Rd[15:0] ← SE(Rs[7:0], 16);
Syntax:
I. punpckub.h Rd, Rs:<part>
II. punpcksb.h Rd, Rs:<part>
Operands:
I, II. {d, s} ∈ {0, 1, …, 15}
part ∈ {t, b}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 16
1 1 1 Rs 0 0 0 0 0 0 0 0 0
15 5 4 3 0
0 0 1 0 0 1 0 0 1 0 0 k Rd
298 AVR32
32000D–04/2011
AVR32
Format II:
31 29 28 25 24 16
1 1 1 Rs 0 0 0 0 0 0 0 0 0
15 5 4 3 0
0 0 1 0 0 1 0 0 1 0 1 k Rd
299
32000D–04/2011
PUSHJC – Push Java Context to Frame
Architecture revision:
Architecture revision1 and higher.
Description
Stores the system registers LV0 to LV7 used in Java state to designated place on the current
method frame. FRAME (equal to R9) is used as pointer register.
Operation:
I. temp ←FRAME;
*(temp--) ←JAVA_LV0;
*(temp--) ←JAVA_LV1;
*(temp--) ←JAVA_LV2;
*(temp--) ←JAVA_LV3;
*(temp--) ←JAVA_LV4;
*(temp--) ←JAVA_LV5;
*(temp--) ←JAVA_LV6;
*(temp--) ←JAVA_LV7;
Syntax:
I. pushjc
Operands:
I. none
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 1 0 0 1 0 0 0 1 1
300 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Stores the registers specified in the instruction into consecutive words pointed to by SP.
Operation:
I. if Reglist8[0] == 1 then
*(--SP) ←R0;
*(--SP) ←R1;
*(--SP) ←R2;
*(--SP) ←R3;
if Reglist8[1] == 1 then
*(--SP) ←R4;
*(--SP) ←R5;
*(--SP) ←R6;
*(--SP) ←R7;
if Reglist8[2] == 1 then
*(--SP) ←R8;
*(--SP) ←R9;
if Reglist8[3] == 1 then
*(--SP) ←R10;
if Reglist8[4] == 1 then
*(--SP) ←R11;
if Reglist8[5] == 1 then
*(--SP) ←R12;
if Reglist8[6] == 1 then
*(--SP) ←LR;
if Reglist8[7] == 1 then
*(--SP) ←PC;
Syntax:
I. pushm Reglist8
Operands:
I. Reglist8 ∈ {R0- R3, R4-R7, R8-R9, R10,R11, R12, LR, PC}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
301
32000D–04/2011
Opcode:
15 13 12 11 4 3 0
1 1 0 1 PC LR 12 11 10 9-8 7-4 3-0 0 0 0 1
Note:
Emtpy Reglist8 gives UNDEFINED result.
The R bit in the status register has no effect on this instruction.
302 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
PC-relative call of subroutine
Operation:
I. LR ← PC + 2
PC ← PC + (SE(disp10)<<1)
II. LR ← PC + 4
PC ← PC + (SE(disp21)<<1)
Syntax:
I. rcall PC[disp]
II. rcall PC[disp]
Operands:
I. disp ∈ {-1024, -1022, ..., 1022}
II. disp ∈ {-2097152, -2097150, ..., 2097150}
Status Flags
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 11 4 3 2 1 0
1 1 0 0 disp10[7:0] 1 1 d10[9:8]
Format II:
31 29 28 25 24 21 20 19 16
K21
1 1 1 disp21[20:17] 0 1 0 1 [16] 0 0 0 0
15 0
disp21[15:0]
303
32000D–04/2011
RET{cond4} – Conditional Return from Subroutine
Architecture revision:
Architecture revision1 and higher.
Description
Return from subroutine if the specified condition is true. Values are moved into the return regis-
ter, the return value is tested, and flags are set.
Operation:
I. If (cond4)
If (Rs != {LR, SP, PC})
R12 ← Rs;
else if (Rs == LR)
R12 ← -1;
else if (Rs == SP)
R12 ← 0;
else
R12 ← 1;
Test R12 and set flags;
PC ← LR;
Syntax:
I. ret{cond4} Rs
Operands:
I. cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
s ∈{0, 1, …, 15}
Status Flags:
Flags are set as result of the operation CP R12, 0.
Q: Not affected
V: V←0
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C←0
Opcode:
15 13 12 9 8 7 4 3 0
0 1 0 1 1 1 1 0 cond4 Rs
304 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Return from debug mode.
Operation:
I. SR ← RSR_DBG
PC ← RAR_DBG
Syntax:
I. retd
Operands:
None
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 0 0 0 1 0 0 0 1 1
Note:
This instruction can only be executed in a privileged mode. Execution from any other mode will
trigger a Privilege Violation exception.
305
32000D–04/2011
RETE – Return from event handler
Architecture revision:
Architecture revision1 and higher.
Description
Returns from an exception or interrupt. SREG[L] is cleared to support atomical memory access
with the stcond instruction. This instruction can only be executed in INT0-INT3, EX and NMI
modes. Execution in Application or Supervisor modes will trigger a Privilege Violation exception.
Operation:
I. If (microarchitecture == AVR32A)
SR ← *(SPSYS++)
PC ← *(SPSYS++)
If ( SR[M2:M0] == {B’010, B’011, B’100, B’101} )
LR ← *(SPSYS++)
R12 ← *(SPSYS++)
R11 ← *(SPSYS++)
R10 ← *(SPSYS++)
R9 ← *(SPSYS++)
R8 ← *(SPSYS++)
SREG[L] ← 0;
else
SR ← RSRCurrent Context
PC ← RARCurrent Context
SREG[L] ← 0;
Syntax:
I RETE
Operands:
None
Status Flags
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
306 AVR32
32000D–04/2011
AVR32
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 0 0 0 0 0 0 0 1 1
307
32000D–04/2011
RETJ – Return from Java trap
Architecture revision:
Architecture revision1 and higher.
Description
Returns from a Java trap.
Operation:
I. PC ← LR;
J ← 1;
R ← 0;
if ( SR[M2:M0] == B’001 )
GM ← 0;
Syntax:
I retj
Operands:
None
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 0 0 0 1 1 0 0 1 1
308 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Returns from a supervisor call.
Operation:
I. If ( SR[M2:M0] == B’000 )
Issue Privilege Violation Exception;
else if ( SR[M2:M0] == B’001 )
If (microarchitecture == AVR32A)
SR ← *(SPSYS++)
PC ← *(SPSYS++)
else
SR ← RSRSUP;
PC ← RARSUP;
else
PC ← LRCurrent Context
Syntax:
I RETS
Operands:
None
Status Flags
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 0 0 0 0 1 0 0 1 1
309
32000D–04/2011
RETSS – Return from Secure State
Architecture revision:
Architecture revision 3 and higher.
Description
Returns from Secure State.
Operation:
I. If ( SR[SS] == 0 )
Issue Privilege Violation Exception;
else
SR ← SS_RSR
PC ← SS_RAR
Syntax:
I RETSS
Operands:
None
Status Flags
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 1 0 1 1 0 0 0 1 1
310 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Jump the specified amount relative to the Program Counter .
Operation:
I. PC ← PC + (SE(disp10)<<1);
Syntax:
I. rjmp PC[disp]
Operands:
I. disp ∈ {-1024, -1022, ..., 1022}
Status Flags
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 13 12 11 4 3 2 1 0
1 1 0 0 disp10[7:0] 1 0 disp10[9:8]
311
32000D–04/2011
ROL – Rotate Left through Carry
Architecture revision:
Architecture revision1 and higher.
Description
Shift all bits in Rd one place to the left. The C flag is shifted into the LSB. The MSB is shifted into
the C flag.
Operation:
I. C´ ← Rd[31];
Rd ← Rd << 1;
Rd[0] ← C;
C ← C´;
Syntax:
I. rol Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: Not affected
N: N ← Res[31]
Z: Z ← (RES[31:0] == 0)
C: C ← Rd[31]
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 1 1 1 1 Rd
312 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Shift all bits in Rd one place to the right. The C flag is shifted into the MSB. The LSB is shifted
into the C flag.
Operation:
I. C´ ← Rd[0];
Rd ← Rd >> 1;
Rd[31] ← C;
C ← C´;
Syntax:
I. ror Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: Not affected
N: N ← Res[31]
Z: Z ← (RES[31:0] == 0)
C: C ← Rd[0]
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 1 0 0 0 0 Rd
313
32000D–04/2011
RSUB – Reverse Subtract
Architecture revision:
Architecture revision1 and higher.
Description
Performs a subtraction and stores the result in destination register. Similar to sub, but the minu-
end and subtrahend are interchanged.
Operation:
I. Rd ← Rs - Rd;
II. Rd ← SE(imm8) - Rs;
Syntax:
I. rsub Rd, Rs
II. rsub Rd, Rs, imm
Operands:
I. {d, s} ∈ {0, 1, …, 15}
II. {d, s} ∈ {0, 1, …, 15}
imm ∈ {-128, -127, ..., 127}
Status Flags:
Format I: OP1 = Rs, OP2 = Rd
Format II: OP1 = SE(imm8), OP2 = Rs
Q: Not affected
V: V ← (OP1[31] ∧ ¬OP2[31] ∧ ¬RES[31]) ∨ (¬OP1[31] ∧ OP2[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← ¬OP1[31] ∧ OP2[31] ∨ OP2[31] ∧ RES[31] ∨ ¬OP1[31] ∧ RES[31]
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rs 0 0 0 1 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 0 0 0 0 Rd
15 12 11 8 7 0
0 0 0 1 0 0 0 1 imm8
314 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Architecture revision:
Architecture revision 2 and higher.
Description
Performs a subtraction and stores the result in destination register. Similar to sub, but the minu-
end and subtrahend are interchanged.
Operation:
I. if ( cond4)
Rd ← SE(imm8) - Rd;
Syntax:
I. rsub{cond4} Rd, imm
Operands:
I. d ∈ {0, 1, …, 15}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
imm ∈ {-128, -127, ..., 127}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 1 1 0 1 1 1 0 1 1 Rd
15 12 11 8 7 0
0 0 0 0 cond4 imm8
315
32000D–04/2011
SATADD.H – Saturated Add of Halfwords
Architecture revision:
Architecture revision1 and higher.
Description
Adds the two halfword registers specified and stores the result in destination register. The result
is saturated if it overflows the range representable with 16 bits. If saturation occurs, the Q flag is
set.
Operation:
I. temp ← ZE(Rx[15:0]) + ZE(Ry[15:0]));
if (Rx[15] ∧ Ry[15] ∧ ¬temp[15]) ∨ (¬Rx[15] ∧ ¬Ry[15] ∧ temp[15]) then
if Rx[15] == 0 then
Rd ← 0x00007fff;
else
Rd ← 0xffff8000;
else
Rd ← SE(temp[15:0]);
Syntax:
I. satadd.hRd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Q ← (Rx[15] ∧ Ry[15] ∧ ¬temp[15]) ∨ (¬Rx[15] ∧ ¬Ry[15] ∧ temp[15]) ∨ Q
V: V ← (Rx[15] ∧ Ry[15] ∧ ¬temp[15]) ∨ (¬Rx[15] ∧ ¬Ry[15] ∧ temp[15])
N: N ← Rd[15]
Z: Z ← if (Rd[15:0] == 0)
C: C←0
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 0 1 0 1 1 0 0 Rd
316 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Adds the two registers specified and stores the result in destination register. The result is satu-
rated if a two’s complement overflow occurs. If saturation occurs, the Q flag is set.
Operation:
I. temp ← Rx + Ry;
if (Rx[31] ∧ Ry[31] ∧ ¬temp[31]) ∨ (¬Rx[31] ∧ ¬Ry[31] ∧ temp[31]) then
if Rx[31] == 0 then
Rd ← 0x7fffffff;
else
Rd ← 0x8000000;
else
Rd ← temp;
Syntax:
I. satadd.wRd, Rx, Ry
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
Status Flags:
Q: Q ← (Rx[31] ∧ Ry[31] ∧ ¬temp[31]) ∨ (¬Rx[31] ∧ ¬Ry[31] ∧ temp[31]) ∨ Q
V: V ← (Rx[31] ∧ Ry[31] ∧ ¬temp[31]) ∨ (¬Rx[31] ∧ ¬Ry[31] ∧ temp[31])
N: N ← Rd[31]
Z: Z ← (Rd[31:0] == 0)
C: C←0
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 0 0 0 1 1 0 0 Rd
317
32000D–04/2011
SATRNDS – Saturate with Rounding Signed
Architecture revision:
Architecture revision1 and higher.
Description
This instruction considers the value in (Rd>>sa)[bp-1:0] as a signed value. Rounding is per-
formed after the shift. If the value in (Rd>>sa)[31:bp] is not merely a sign-extention of this value,
overflow has occurred and saturation is performed to the maximum signed positive or negative
value. If saturation occurs, the Q flag is set. An arithmetic shift is performed on Rd. If bp equals
zero, no saturation is performed.
Operation:
I. Temp ← Rd >> sa
if (sa != 0)
Rnd = Rd[sa-1]
Temp = Temp + Rnd;
if ((Temp == SE( Temp[bp-1:0])) || (bp == 0) )
Rd ← Temp;
else
if (Temp[31] == 1)
Rd ← -2bp-1;
else
Rd ← 2bp-1 - 1;
Syntax:
I. satrnds Rd >> sa, bp
Operands:
I. d ∈ {0, 1, …, 15}
{sa, bp} ∈ {0, 1, …, 31}
Status Flags:
Q: Set if saturation occurred or Q was already set, cleared otherwise.
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
31 29 28 25 24 20 19 16
1 1 1 1 0 0 1 1 1 0 1 1 Rd
15 12 11 10 9 5 4 0
0 0 0 0 0 0 bp sa
318 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
This instruction considers the value in (Rd>>sa)[bp-1:0] as a unsigned value. Rounding is per-
formed after the shift. If the value in (Rd>>sa)[31:bp] is not merely a zero extention of this value,
overflow has occurred and saturation is performed to the maximum unsigned positive value or
zero. If saturation occurs, the Q flag is set. An arithmetic shift is performed on Rd. If bp equals
zero, no saturation is performed.
Operation:
I. Temp ← Rd >> sa
if (sa != 0)
Rnd = Rd[sa-1]
Temp = Temp + Rnd;
If ((Temp == ZE( Temp[bp-1:0])) || (bp == 0) )
Rd ← Temp;
else
if (Temp[31] == 1)
Rd ← 0x0000_0000;
else
Rd ← 2bp - 1;
Syntax:
I. satrndu Rd >> sa, bp
Operands:
I. d ∈ {0, 1, …, 15}
{sa, bp} ∈ {0, 1, …, 31}
Status Flags:
Q: Set if saturation occurred or Q was already set, cleared otherwise.
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
31 29 28 25 24 20 19 16
1 1 1 1 0 0 1 1 1 0 1 1 Rd
15 12 11 10 9 5 4 0
0 0 0 0 0 1 bp sa
319
32000D–04/2011
SATS – Saturate Signed
Architecture revision:
Architecture revision1 and higher.
Description
This instruction considers the value in (Rd>>sa)[bp-1:0] as a signed value. If the value in
(Rd>>sa)[31:bp] is not merely a sign-extention of this value, overflow has occurred and satura-
tion is performed to the maximum signed positive or negative value. If saturation occurs, the Q
flag is set. An arithmetic shift is performed on Rd. If bp equals zero, no saturation is performed.
Operation:
I. Temp ← Rd >> sa
If ((Temp == SE( Temp[bp-1:0])) || (bp == 0))
Rd ← Temp;
else
if (Temp[31] == 1)
Rd ← -2bp-1;
else
Rd ← 2bp-1 - 1;
Syntax:
I. sats Rd >> sa, bp
Operands:
I. d ∈ {0, 1, …, 15}
{sa, bp} ∈ {0, 1, …, 31}
Status Flags:
Q: Set if saturation occurred or Q was already set, cleared otherwise.
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
31 29 28 25 24 20 19 16
1 1 1 1 0 0 0 1 1 0 1 1 Rd
15 12 11 10 9 5 4 0
0 0 0 0 0 0 bp sa
320 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Performs a subtraction of the specified halfwords and stores the result in destination register.
The result is saturated if it overflows the range representable with 16 bits. If saturation occurs,
the Q flag is set.
Operation:
I. temp ← ZE(Rx[15:0]) - ZE(Ry[15:0]) ;
if (Rx[15] ∧ ¬Ry[15] ∧ ¬temp[15]) ∨ (¬Rx[15] ∧ Ry[15] ∧ temp[15]) then
if Rx[15]==0 then
Rd ← 0x00007fff;
else
Rd ← 0xffff8000;
else
Rd ← SE(temp[15:0]);
Syntax:
I. satsub.hRd, Rx, Ry
Operands:
I. {d, s} ∈ {0, 1, …, 15}
Status Flags:
Q: Q ← (Rx[15] ∧ ¬Ry[15] ∧ ¬temp[15]) ∨ (¬Rx[15] ∧ Ry[15] ∧ temp[15]) ∨ Q
V: V ← (Rx[15] ∧ ¬Ry[15] ∧ ¬temp[15]) ∨ (¬Rx[15] ∧ Ry[15] ∧ temp[15])
N: N ← Rd[15]
Z: Z ← (Rd[15:0] == 0)
C: C←0
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 0 1 1 1 1 0 0 Rd
321
32000D–04/2011
SATSUB.W – Saturated Subtract of Words
Architecture revision:
Architecture revision1 and higher.
Description
Performs a subtraction and stores the result in destination register. The result is saturated if a
two’s complement overflow occurs. If saturation occurs, the Q flag is set.
Operation:
I. temp ← Rx - Ry;
II. temp ← Rs - SE(imm16));
Syntax:
I. satsub.w Rd, Rx, Ry
II. satsub.w Rd, Rs, imm
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
II. {d, s} ∈ {0, 1, …, 15}
imm ∈ {-32768, -32767, ..., 32767}
Status Flags:
Format I: OP1 = Rx, OP2 = Ry
Format II: OP1 = Rs, OP2 = SE(imm16)
Q: Q ← (OP1[31] ∧ ¬OP2[31] ∧ ¬temp[31]) ∨ (¬OP1[31] ∧ OP2[31] ∧ temp[31]) ∨
Q
V: V ← (OP1[31] ∧ ¬OP2[31] ∧ ¬temp[31]) ∨ (¬OP1[31] ∧ OP2[31] ∧ temp[31])
N: N ← Rd[31]
Z: Z ← (Rd[31:0] == 0)
C: C←0
Opcode:
322 AVR32
32000D–04/2011
AVR32
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 0 0 1 1 1 0 0 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 1 1 0 1 Rd
15 0
imm16
323
32000D–04/2011
SATU – Saturate Unsigned
Architecture revision:
Architecture revision1 and higher.
Description
This instruction considers the value in (Rd>>sa)[bp-1:0] as a unsigned value. If the value in
(Rd>>sa)[31:bp] is not merely a zero extention of this value, overflow has occurred and satura-
tion is performed to the maximum unsigned positive value or zero. If saturation occurs, the Q flag
is set. An arithmetic shift is performed on Rd. If bp equals zero, no saturation is performed.
Operation:
I. Temp ← Rd >> sa
If ((Temp == ZE( Temp[bp-1:0])) || (bp == 0) )
Rd ← Temp;
else
if (Temp[31] == 1)
Rd ← 0x0000_0000;
else
Rd ← 2bp - 1;
Syntax:
I. satu Rd >> sa, bp
Operands:
I. d ∈ {0, 1, …, 15}
{sa, bp} ∈ {0, 1, …, 31}
Status Flags:
Q: Set if saturation occurred or Q was already set, cleared otherwise.
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
31 29 28 25 24 20 19 16
1 1 1 1 0 0 0 1 1 0 1 1 Rd
15 12 11 10 9 5 4 0
0 0 0 0 0 1 bp sa
324 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Subtracts a specified register and the value of the carry bit from a destination register and stores
the result in the destination register.
Operation:
I. Rd ← Rx - Ry - C;
Syntax:
I. sbc Rd, Rx, Ry
Operands:
I. {x, y, d} ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: V ← (Rx[31] ∧ ¬Ry[31] ∧ ¬RES[31]) ∨ (¬Rx[31] ∧ Ry[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0) ∧ Z
C: C ← ¬Rx[31] ∧ Ry[31] ∨ Ry[31] ∧ RES[31] ∨ ¬Rx[31] ∧ RES[31]
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 0 0 0 1 0 1 0 0 Rd
325
32000D–04/2011
SBR – Set Bit in Register
Architecture revision:
Architecture revision1 and higher.
Description
Sets a bit in the specified register. All other bits are unaffected.
Operation:
I. Rd[bp5] ← 1;
Syntax:
I. sbr Rd, bp
Operands:
I. d ∈ {0, 1, …, 15}
bp ∈ {0, 1, …, 31}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Z←0
C: Not affected
Opcode:
15 13 12 9 8 5 4 3 0
1 0 1 bp[4:1] 1 1 0 1 bp[0] Rd
326 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
The scall instruction performs a supervisor routine call. The behaviour of the instruction is
dependent on the mode it is called from, allowing scall to be executed from all contexts. Scall
jumps to a dedicated entry point relative to EVBA. Scall can use the same call convention as
regular subprogram calls.
Operation:
I. If ( SR[M2:M0] == {B’000 or B’001} )
If (microarchitecture == AVR32A)
*(--SPSYS) ← PC + 2;
*(--SPSYS) ← SR;
PC ← EVBA + 0x100;
SR[M2:M0] ← B’001;
else
RARSUP ← PC + 2;
RSRSUP ← SR;
PC ← EVBA + 0x100;
SR[M2:M0] ← B’001;
else
LRCurrent Context ← PC + 2;
PC ← EVBA + 0x100;
Syntax:
I. scall
Operands:
I. none
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 1 0 0 1 1 0 0 1 1
327
32000D–04/2011
SCR – Subtract Carry from Register
Architecture revision:
Architecture revision1 and higher.
Description
Subtracts carry from the specified destination register.
Operation:
I. Rd ← Rd - C;
Syntax:
I. scr Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: V ← (Rd[31] ∧ ¬RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0) ∧ Z
C: C ← ¬Rd[31] ∧ RES[31]
Opcode:
15 13 12 4 3 0
0 1 0 1 1 1 0 0 0 0 0 1 Rd
Example
; Subtract a 32-bit variable (R0) from a 64-bit variable (R2:R1)
sub R1, R0
scr R2
328 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Sets the system in the sleep mode specified by the implementation defined Op8 operand. The
semantic of Op8 is IMPLEMENTATION DEFINED. If bit 7 in Op8 is one, SR[GM] will be cleared
when entering sleep mode.
Operation:
I. Set the system in the specified sleep mode.
Syntax:
I. sleep Op8
Operands:
I. Op8 ∈ {0, 1, …, 255}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
31 29 28 25 24 20 19 16
1 1 1 0 1 0 0 1 1 0 1 1 0 0 0 0
15 8 7 0
0 0 0 0 0 0 0 0 Op8
Note:
The sleep instruction is a privileged instruction, and will trigger a Privilege Violation exception if
executed in user mode.
329
32000D–04/2011
SR{cond4} – Set Register Conditionally
Architecture revision:
Architecture revision1 and higher.
Description
Sets the register specified to 1 if the condition specified is true, clear the register otherwise.
Operation:
I. if (cond4)
Rd ← 1;
else
Rd ← 0;
Syntax:
I. sr{cond4} Rd
Operands:
I. cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
d ∈ {0, 1, ..., 15}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 13 12 9 8 7 4 3 0
0 1 0 1 1 1 1 1 cond4 Rd
330 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision 3 and higher.
Description
The sscall instruction performs a secure state call. Sscall can use the same call convention as
regular subprogram calls.
Operation:
I.
SS_RAR ← PC;
SS_RSR ← SR;
If (microarchitecture == AVR32A)
PC ← 0x8000_0004;
else)
PC ← 0xA000_0004;
SR[SS] ← 1;
SR[GM] ← 1;
if (SR[M2:M0] == 0)
SR[M2:M0] ← 001;
Syntax:
I. sscall
Operands:
I. none
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 1 0 1 0 1 0 0 1 1
331
32000D–04/2011
SSRF – Set Status Register Flag
Architecture revision:
Architecture revision1 and higher.
Description
Sets the status register (SR) flag specified.
Operation:
I. SR[bp5] ← 1;
Syntax:
I. ssrf bp
Operands:
I. bp ∈ {0, 1, …, 31}
Status Flags:
SR[bp5] ← 1, all other flags unchanged.
Opcode:
15 11 10 9 8 4 3 0
1 1 0 1 0 0 1 bp5 0 0 1 1
Note:
Privileged if bp5 > 15, ie. upper half of status register. An exception will be triggered if the upper
half of the status register is attempted changed in user mode.
332 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
The source register is stored to the byte memory location referred to by the pointer address.
Operation:
I. *(Rp) ← Rs[7:0];
Rp ← Rp + 1;
II. Rp ← Rp - 1;
*(Rp) ← Rs[7:0];
III. *(Rp + ZE(disp3)) ← Rs[7:0];
IV. *(Rp + SE(disp16)) ← Rs[7:0];
V. *(Rb + (Ri << sa2)) ← Rs[7:0];
Syntax:
I. st.b Rp++, Rs
II. st.b --Rp, Rs
III. st.b Rp[disp], Rs
IV. st.b Rp[disp], Rs
V. st.b Rb[Ri << sa], Rs
Operands:
I, II. {s , p} ∈ {0, 1, …, 15}
III. {s , p} ∈ {0, 1, …, 15}
disp ∈ {0, 1, ..., 7}
IV. {s , p} ∈ {0, 1, …, 15}
disp ∈ {-32768, -32767, ..., 32767}
V. {b, i, s} ∈ {0, 1, …, 15}
sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rp 0 1 1 0 0 Rs
333
32000D–04/2011
Format II:
15 13 12 9 8 4 3 0
0 0 0 Rp 0 1 1 1 1 Rs
Format III:
15 13 12 9 8 7 6 4 3 0
1 0 1 Rp 0 1 disp3 Rs
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 0 1 1 0 Rs
15 0
disp16
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 1 0 1 1 0 0 Shift Amount Rs
Note:
For formats I. and II., if Rp = Rs the result will be UNDEFINED.
334 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision 2 and higher.
Description
The source register is stored to the byte memory location referred to by the pointer address if the
given condition is satisfied.
Operation:
I. if (cond4)
*(Rp + ZE(disp9)) ← Rs[7:0];
Syntax:
I. st.b{cond4} Rp[disp], Rs
Operands:
I. s, p ∈ {0, 1, …, 15}
disp ∈ {0, 1, ..., 511}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 1 1 Rd
15 12 11 8 7 6 5 4 3 0
cond4 1 1 1 disp9
335
32000D–04/2011
ST.D – Store Doubleword
Architecture revision:
Architecture revision1 and higher.
Description
The source registers are stored to the doubleword memory location referred to by the pointer
address.
Operation:
I. *(Rp) ← Rs+1:Rs;
Rp ← Rp + 8;
II. Rp ← Rp - 8;
*(Rp) ← Rs+1:Rs;
III. *(Rp) ← Rs+1:Rs;
IV. *(Rp + SE(disp16)) ← Rs+1:Rs;
V. *(Rb + (Ri << sa2)) ← Rs+1:Rs;
Syntax:
I. st.d Rp++, Rs
II. st.d --Rp, Rs
III. st.d Rp, Rs
IV. st.d Rp[disp], Rs
V. st.d Rb[Ri << sa], Rs
Operands:
I, II, III. p ∈ {0, 1, …, 15}
s ∈ {0, 2, …, 14}
IV. p ∈ {0, 1, …, 15}
s ∈ {0, 2, …, 14}
disp ∈ {-32768, -32767, ..., 32767}
V. {b, i} ∈ {0, 1, …, 15}
s ∈ {0, 2, …, 14}
sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
336 AVR32
32000D–04/2011
AVR32
Format I:
15 13 12 9 8 6 5 4 3 1 0
1 0 1 Rp 1 0 0 1 0 Rs 0
Format II:
15 13 12 9 8 6 5 4 3 1 0
1 0 1 Rp 1 0 0 1 0 Rs 1
Format III:
15 13 12 9 8 4 3 0
1 0 1 Rp 1 0 0 0 1 Rs 1
Format IV:
31 29 28 25 24 20 19 17 16
1 1 1 Rp 0 1 1 1 0 Rs 1
15 0
disp16
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 1 0 0 0 0 0 Shift Amount Rs
Note:
For formats I. and II., if Rp == Rs the result will be UNDEFINED.
337
32000D–04/2011
ST.H – Store Halfword
Architecture revision:
Architecture revision1 and higher.
Description
The source register is stored to the halfword memory location referred to by the pointer address.
Operation:
I. *(Rp) ← Rs[15:0];
Rp ← Rp + 2;
II. Rp ← Rp - 2;
*(Rp) ← Rs[15:0];
III. *(Rp + ZE(disp3 << 1)) ← Rs[15:0];
IV. *(Rp + SE(disp16)) ← Rs[15:0];
V. *(Rb + (Ri << sa2)) ← Rs[15:0];
Syntax:
I. st.h Rp++, Rs
II. st.h --Rp, Rs
III. st.h Rp[disp], Rs
IV. st.h Rp[disp], Rs
V. st.h Rb[Ri << sa], Rs
Operands:
I, II. {s , p} ∈ {0, 1, …, 15}
III. {s , p} ∈ {0, 1, …, 15}
disp ∈ {0, 2, ..., 14}
IV. {s , p} ∈ {0, 1, …, 15}
disp ∈ {-32768, -32767, ..., 32767}
V. {b, i, s} ∈ {0, 1, …, 15}
sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rp 0 1 0 1 1 Rs
338 AVR32
32000D–04/2011
AVR32
Format II:
15 13 12 9 8 4 3 0
0 0 0 Rp 0 1 1 1 0 Rs
Format III:
15 13 12 9 8 7 6 4 3 0
1 0 1 Rp 0 0 disp3 Rs
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 0 1 0 1 Rs
15 0
disp16
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 1 0 1 0 0 0 Shift Amount Rs
Note:
For formats I. and II., if Rp == Rs the result will be UNDEFINED.
339
32000D–04/2011
ST.H{cond4} – Conditionally Store Halfword
Architecture revision:
Architecture revision 2 and higher.
Description
The source register is stored to the halfword memory location referred to by the pointer address
if the given condition is satisfied.
Operation:
I. if (cond4)
*(Rp + ZE(disp9<<1)) ← Rs[15:0];
Syntax:
I. st.h{cond4} Rp[disp], Rs
Operands:
I. s, p ∈ {0, 1, …, 15}
disp ∈ {0, 2, ..., 1022}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 1 1 Rs
15 12 11 8 7 6 5 4 3 0
cond4 1 1 0 disp9
340 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
The source register is stored to the word memory location referred to by the pointer address.
Operation:
I. *(Rp) ← Rs;
Rp ← Rp + 4;
II. Rp ← Rp - 4;
*(Rp) ← Rs;
III. *(Rp + ZE(disp4 << 2)) ← Rs;
IV. *(Rp + SE(disp16)) ← Rs;
V. *(Rb + (Ri << sa2)) ← Rs;
Syntax:
I. st.w Rp++, Rs
II. st.w --Rp, Rs
III. st.w Rp[disp], Rs
IV. st.w Rp[disp], Rs
V. st.w Rb[Ri << sa], Rs
Operands:
I, II. {s , p} ∈ {0, 1, …, 15}
III. {s , p} ∈ {0, 1, …, 15}
disp ∈ {0, 4, ..., 60}
IV. {s , p} ∈ {0, 1, …, 15}
disp ∈ {-32768, -32767,…, 32767}
V. {b, i, s} ∈ {0, 1, …, 15}
sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rp 0 1 0 1 0 Rs
341
32000D–04/2011
Format II:
15 13 12 9 8 4 3 0
0 0 0 Rp 0 1 1 0 1 Rs
Format III:
15 13 12 9 8 7 4 3 0
1 0 0 Rp 1 disp4 Rs
Format IV:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 0 1 0 0 Rs
15 0
disp16
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rb 0 0 0 0 0 Ri
15 12 11 8 7 6 5 4 3 0
0 0 0 0 1 0 0 1 0 0 Shift Amount Rs
Note:
For formats I. and II., if Rp == Rs the result will be UNDEFINED.
342 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision 2 and higher.
Description
The source register is stored to the word memory location referred to by the pointer address if
the given condition is satisfied.
Operation:
I. if (cond4)
*(Rp + ZE(disp9<<2)) ← Rs;
Syntax:
I. st.w{cond4} Rp[disp], Rs
Operands:
I. s, p ∈ {0, 1, …, 15}
disp ∈ {0, 4, ..., 2044}
cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 1 1 Rd
15 12 11 8 7 6 5 4 3 0
cond4 1 0 1 disp9
343
32000D–04/2011
STC.{D,W} – Store Coprocessor
Architecture revision:
Architecture revision1 and higher.
Description
Stores the source register value to the location specified by the addressing mode.
Operation:
I. *(Rp + (ZE(disp8) << 2)) ← CP#(CRd+1:CRd);
II. *(Rp) ← CP#(CRd+1:CRd);
Rp ← Rp+8;
III. *(Rb + (Ri << sa2)) ← CP#(CRd+1:CRd);
IV. *(Rp + (ZE(disp8) << 2)) ← CP#(CRd);
V. *(Rp) ← CP#(CRd);
Rp ← Rp+4;
VI. *(Rb + (Ri << sa2)) ← CP#(CRd);
Syntax:
I. stc.d CP#, Rp[disp], CRs
II. stc.d CP#, Rp++, CRs
III. stc.d CP#, Rb[Ri<<sa], CRs
IV. stc.w CP#, Rp[disp], CRs
V. stc.w CP#, Rp++, CRs
VI. stc.w CP#, Rb[Ri<<sa], CRs
Operands:
I-VI. # ∈ {0, 1, …, 7}
I-II, IV-V.s ∈ {0, 1, …, 15}
I-III. s ∈ {0, 2, …, 14}
I, IV. disp ∈ {0, 4, …, 1020}
III, VI. {b, i} ∈ {0, 1, …, 15}
III, VI. sa ∈ {0, 1, 2, 3}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
344 AVR32
32000D–04/2011
AVR32
Format I:
31 29 28 25 24 20 19 16
1 1 1 0 1 0 1 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CP # 1 CRs[3:1] 0 disp8
Format II:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rp
15 13 12 11 9 8 7 0
CP # 0 CRs[3:1] 0 0 1 1 1 0 0 0 0
Format III:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rp
15 13 12 11 9 8 7 6 5 4 3 0
CP # 1 CRs[3:1] 0 1 1 Sh amt Ri
Format IV:
31 29 28 25 24 20 19 16
1 1 1 0 1 0 1 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CP # 0 CRs disp8
Format V:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CP # 0 CRs 0 1 1 0 0 0 0 0
Format VI:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 1 1 1 0 1 0 Rp
15 13 12 11 8 7 6 5 4 3 0
CP # 1 CRs 1 0 Sh amt Ri
Example:
stc.d CP2, R2[0], CR0
345
32000D–04/2011
STC0.{D,W} – Store Coprocessor 0 Register
Architecture revision:
Architecture revision1 and higher.
Description
Stores the coprocessor 0 source register value to the location specified by the addressing mode.
Operation:
I. *(Rp + (ZE(disp12) << 2)) ← CP#(CRd+1:CRd);
II. *(Rp + (ZE(disp12) << 2)) ← CP#(CRd);
Syntax:
I. stc0.d Rp[disp], CRs
II. stc0.w Rp[disp], CRs
Operands:
I-II. p ∈ {0, 1, …, 15}
I. s ∈ {0, 2, …, 14}
II. s ∈ {0, 1, …, 15}
I, IV. disp ∈ {0, 4, …, 16380}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 1 0 1 1 1 1 0 1 0 Rp
15 12 11 8 7 0
disp[11:8] CRs[3:1] 0 disp[7:0]
Format II:
31 29 28 25 24 20 19 16
1 1 1 1 0 1 0 1 1 0 1 0 Rp
15 12 11 8 7 0
disp[11:8] CRs disp[7:0]
Example:
stc0.d R2[0], CR0
346 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Writes multiple registers in the addressed coprocessor into the specified memory locations.
Operation:
I. Storeaddress ←Rp;
if Opcode[--] == 1 then
for (i = 0 to 7)
if ReglistCPD8[i] == 1 then
*(--Storeaddress) ←CP#(CR(2*i));
*(--Storeaddress) ←CP#(CR(2*i+1));
Rp ← Storeaddress;
else
for (i = 7 to 0)
if ReglistCPD8[i] == 1 then
*(Storeaddress++) ←CP#(CR(2*i+1));
*(Storeaddress++) ←CP#(CR(2*i));
II Storeaddress ←Rp;
if Opcode[--] == 1 then
for (i = 0 to 7)
if ReglistCPH8[i] == 1 then
*(--Storeaddress) ←CP#(CRi+8);
Rp ← Storeaddress;
else
for (i = 7 to 0)
if ReglistCPH8[i] == 1 then
*(Storeaddress++) ←CP#(CRi+8);
III Storeaddress ←Rp;
if Opcode[--] == 1 then
for (i = 0 to 7)
if ReglistCPL8[i] == 1 then
*(--Storeaddress) ←CP#(CRi);
Rp ← Storeaddress;
else
for (i = 7 to 0)
if ReglistCPL8[i] == 1 then
*(Storeaddress++) ←CP#(CRi);
347
32000D–04/2011
Syntax:
I. stcm.d CP#, {--}Rp, ReglistCPD8
II. stcm.w CP#, {--}Rp, ReglistCPH8
III. stcm.w CP#, {--}Rp, ReglistCPL8
Operands:
I-III. # ∈ {0, 1, …, 7}
p ∈ {0, 1, …, 15}
I. ReglistCPD8 ∈ {CR0-CR1,CR2-CR3,CR4-CR5,CR6-CR7,CR8-CR9,
CR10-CR11,CR12-CR13,CR14-CR15}
II. ReglistCPH8 ∈ {CR8, CR9, CR10, ..., CR15}
III. ReglistCPL8 ∈ {CR0, CR1, CR2, ..., CR7}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 0 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CR CR CR CR CR CR CR CR
CP# -- 0 1 0 1 15-14 13-12 11-10 9-8 7-6 5-4 3-2 1-0
Format II:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 0 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CR CR CR CR CR CR CR CR
CP# -- 0 0 1 1 15 14 13 12 11 10 9 8
Format III:
31 29 28 25 24 20 19 16
1 1 1 0 1 1 0 1 1 0 1 0 Rp
15 13 12 11 8 7 0
CR CR CR CR CR CR CR CR
CP# -- 0 0 1 0 7 6 5 4 3 2 1 0
Example:
stcm.w CP2, --SP, CR2-CR5
Note:
Emtpy ReglistCPH8/ReglistCPL8/ReglistCPD8 gives UNDEFINED result.
348 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
The source register is stored to the word memory location referred to by the pointer address if
SREG[L] is set. Also, SREG[L] is copied to SREG[Z] to indicate a success or failure of the oper-
ation. This instruction is used for atomical memory access.
Operation:
I. SREG[Z] ← SREG[L];
If SREG[L]
*(Rp + SE(disp16)) ← Rs;
Syntax:
I. stcond Rp[disp], Rs
Operands:
I. {s , p} ∈ {0, 1, …, 15}
disp ∈ {-32768, -32767, ..., 32767}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: SREG[Z] ← SREG[L].
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 0 1 1 1 Rs
15 0
disp16
Note:
349
32000D–04/2011
STDSP – Store Stack-Pointer Relative
Architecture revision:
Architecture revision1 and higher.
Description
Stores the source register value to the memory location referred to specified by the Stack Pointer
and the displacement.
Operation:
I. *( (SP && 0xFFFF_FFFC) + (ZE(disp7) << 2) ) ← Rs;
Syntax:
I. stdsp SP[disp], Rs
Operands:
I. disp ∈ {0, 4, ..., 508}
s ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
15 13 12 11 10 4 3 0
0 1 0 1 0 disp7 Rs
350 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
The selected halfwords of the source registers are combined and stored to the word memory
location referred to by the pointer address.
Operation:
If (Rx-part == t) then high-part = Rx[31:16] else high-part = Rx[15:0];
If (Ry-part == t) then low-part = Ry[31:16] else low-part = Ry[15:0];
Syntax:
I. sthh.w Rp[disp], Rx:<part>, Ry:<part>
II. sthh.w Rb[Ri << sa], Rx:<part>, Ry:<part>
Operands:
I. {p, x, y} ∈ {0, 1, …, 15}
disp ∈ {0, 4, ..., 1020}
part ∈ {b,t}
II. {b, i, x, y} ∈ {0, 1, …, 15}
sa ∈ {0, 1, 2, 3}
part ∈ {b,t}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 1 0 Ry
15 14 13 12 11 4 3 0
1 1 X Y disp8 Rp
351
32000D–04/2011
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 1 0 Ry
15 14 13 12 11 8 7 6 5 4 3 0
1 0 X Y Ri 0 0 sa2 Rb
352 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Stores the registers specified to the consecutive memory locations pointed to by Rp. Both regis-
ters in the register file and some of the special-purpose registers can be stored.
I. Storeaddress ← Rp;
if Opcode[--] == 1 then
for (i = 0 to 15)
if Reglist16[i] == 1 then
*(--Storeaddress) ←Ri;
Rp ← Storeaddress;
else
for (i = 15 to 0)
if Reglist16[i] == 1 then
*(Storeaddress++) ←Ri;
Syntax:
I. stm {--}Rp, Reglist16
Operands:
I. Reglist16 ∈ {R0, R1, R2, ..., R12, LR, SP, PC}
p ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 26 25 24 20 19 16
1 1 1 0 1 0 -- 1 1 1 0 0 Rp
15 0
R15 R14 R13 R12 R11 R10 R9 R8 R7 R6 R5 R4 R3 R2 R1 R0
Note:
Emtpy Reglist16 gives UNDEFINED result.
If Rp is in Reglist16 and pointer is written back the result is UNDEFINED
The R bit in the status register has no effect on this instruction.
353
32000D–04/2011
STMTS – Store Multiple Registers for Task Switch
Architecture revision:
Architecture revision1 and higher.
Description
Stores the registers specified to the consecutive memory locations pointed to by Rp. The regis-
ters specified all reside in the application context.
I. Storeaddress ← Rp;
if Opcode[--] == 1 then
for (i = 0 to 15)
if Reglist16[i] == 1 then
*(--Storeaddress) ←RiApp;
Rp ← Storeaddress;
else
for (i = 15 to 0)
if Reglist16[i] == 1 then
*(Storeaddress++) ←RiApp;
Syntax:
I. stmts {--}Rp, Reglist16
Operands:
I. Reglist16 ∈ {R0, R1, R2, ..., R12, LR, SP}
p ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 26 25 24 20 19 16
1 1 1 0 1 1 -- 1 1 1 0 0 Rp
15 0
R15 R14 R13 R12 R11 R10 R9 R8 R7 R6 R5 R4 R3 R2 R1 R0
Note:
Emtpy Reglist16 gives UNDEFINED result.
PC in Reglist16 gives UNDEFINED result.
354 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
This instruction swaps the bytes in a halfword or a word in the register file and stores the result to
memory. The instruction can be used for performing stores to memories of different endianness.
Operation:
I. temp[15:0] ← (Rs[7:0], Rs[15:8]);
*(Rp+SE(disp12) << 1) ← temp[15:0];
II. temp[31:0] ← (Rs[7:0], Rs[15:8], Rs[23:16], Rs[31:24]);
*(Rp+SE(disp12) << 2) ← temp[31:0];
Syntax:
I. stswp.h Rp[disp], Rs
II. stswp.w Rp[disp], Rs
Operands:
I. {s, p} ∈ {0, 1, …, 15}
disp ∈ {-4096, -4094, ..., 4094}
II. {s, p} ∈ {0, 1, …, 15}
disp ∈ {-8192, -8188 ..., 8188}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
Format I:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 0 1 Rs
15 12 11 0
1 0 0 1 disp12
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rp 1 1 1 0 1 Rs
15 12 11 0
1 0 1 0 disp12
355
32000D–04/2011
SUB – Subtract (without Carry)
Architecture revision:
Architecture revision1 and higher.
Description
Performs a subtraction and stores the result in destination register.
Operation:
I. Rd ← Rd - Rs;
II. Rd ← Rx - (Ry << sa2);
III. if (Rd == SP)
Rd ← Rd - SE(imm8 << 2);
else
Rd ← Rd - SE(imm8);
IV. Rd ← Rd - SE(imm21);
V. Rd ← Rs - SE(imm16);
Syntax:
I. sub Rd, Rs
II. sub Rd, Rx, Ry << sa
III. sub Rd, imm
IV. sub Rd, imm
V. sub Rd, Rs, imm
Operands:
I-V. {d, s, x, y} ∈ {0, 1, …, 15}
II. sa ∈ {0, 1, 2, 3}
III. if (Rd == SP)
imm ∈{-512, -508, ..., 508}
else
imm ∈{-128, -127, ..., 127}
IV. imm ∈{-1048576, -104875, ..., 1048575}
V. imm ∈ {-32768, -32767, ..., 32767}
Status Flags:
Format I: OP1 = Rd, OP2 = Rs
Format II:OP1 = Rx, OP2 = Ry << sa2
Format III: OP1 = Rd, if (Rd==SP) OP2 = SE(imm8<<2) else OP2 = SE(imm8)
Format IV: OP1 = Rd, OP2 = SE(imm21)
Format V: OP1 = Rs, OP2 = SE(imm16)
Q: Not affected
V: V ← (OP1[31] ∧ ¬OP2[31] ∧ ¬RES[31]) ∨ (¬OP1[31] ∧ OP2[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← ¬OP1[31] ∧ OP2[31] ∨ OP2[31] ∧ RES[31] ∨ ¬OP1[31] ∧ RES[31]
356 AVR32
32000D–04/2011
AVR32
Opcode:
Format I:
15 13 12 9 8 4 3 0
0 0 0 Rs 0 0 0 0 1 Rd
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 8 7 6 5 4 3 0
0 0 0 0 0 0 0 1 0 0 Shift Amount Rd
Format III:
15 13 12 11 4 3 0
0 0 1 0 imm8 Rd
Format IV:
31 29 28 25 24 21 20 19 16
imm21
1 1 1 imm21[20:17 0 0 0 1 [16] Rd
15 0
imm21[15:0]
Format V:
31 29 28 25 24 20 19 16
1 1 1 Rs 0 1 1 0 0 Rd
15 0
imm16
357
32000D–04/2011
SUB{cond4} – Conditional Subtract
Architecture revision:
Format I in Architecture revision1 and higher.
Format II in Architecture revision 2 and higher.
Description
Subtracts a value from a given register and stores the result in destination register if cond4 is
true.
Operation:
I. If (cond4) then
Rd ← Rd - imm8;
Update flags if opcode[f] field is cleared
II. If (cond4) then
Rd ← Rx - Ry;
Syntax:
I. sub{f}{cond4} Rd, imm
II. sub{cond4} Rd, Rx, Ry
Operands:
I. cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
d ∈ {0, 1, …, 15}
imm ∈ {-128, -127, ..., 127}
II. cond4 ∈ {eq, ne, cc/hs, cs/lo, ge, lt, mi, pl, ls, gt, le, hi, vs, vc, qs, al}
{d, x, y} ∈ {0, 1, …, 15}
Status Flag:
K = SE(imm8)
Flags only affected if format I and (cond4) is true and F parameter is given
Q: Not affected
V: V ← (Rd[31] ∧ ¬K[31] ∧ ¬RES[31]) ∨ (¬Rd[31] ∧ K[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← ¬Rd[31] ∧ K[31] ∨ K[31] ∧ RES[31] ∨ RES[31] ∧ ¬Rd[31]
Opcode:
Format I:I
31 29 28 26 25 24 20 19 16
1 1 1 1 0 1 F 1 1 0 1 1 Rd
15 12 11 8 7 0
0 0 0 0 cond4 imm8
358 AVR32
32000D–04/2011
AVR32
Format II:
31 29 28 25 24 20 19 16
1 1 1 Rx 1 1 1 0 1 Ry
15 12 11 8 7 0
1 1 1 0 cond4 0 0 0 1 Rd
Example:
subfeq R3, 5 performs R3 ← R3 - 5 and sets flags accordingly if Z flag set.
subeq R5, 7 performs R5 ← R5 - 5 if Z flag set. Flags are not affected.
359
32000D–04/2011
SUBHH.W– Subtract Halfwords into Word
Architecture revision:
Architecture revision1 and higher.
Description
Subtracts the two halfword registers specified and stores the result in the destination word-regis-
ter. The halfword registers are selected as either the high or low part of the operand registers.
Operation:
I. If (Rx-part == t) then operand1 = SE(Rx[31:16]) else operand1 = SE(Rx[15:0]);
If (Ry-part == t) then operand2 = SE(Ry[31:16]) else operand2 = SE(Ry[15:0]);
Rd ← operand1 - operand2;
Syntax:
I. subhh.wRd, Rx:<part>, Ry:<part>
Operands:
I. {d, x, y} ∈ {0, 1, …, 15}
part ∈ {t,b}
Status Flags:
OP1 = operand1, OP2 = operand2
Q: Not affected
V: V ← (OP1[31] ∧ ¬OP2[31] ∧ ¬RES[31]) ∨ (¬OP1[31] ∧ OP2[31] ∧ RES[31])
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: C ← ¬OP1[31] ∧ OP2[31] ∨ OP2[31] ∧ RES[31] ∨ ¬OP1[31] ∧ RES[31]
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 6 5 4 3 0
0 0 0 0 1 1 1 1 0 0 X Y Rd
Example:
subhh.wR10, R2:t, R3:b
will perform R10 ← SE(R2[31:16]) - SE(R3[15:0])
360 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Swaps different parts of a register.
Operation:
I. Temp ← Rd;
Rd[31:24] ← Temp[7:0];
Rd[23:16] ← Temp[15:8];
Rd[15:8] ← Temp[23:16];
Rd[7:0] ← Temp[31:24];
Syntax:
I. swap.b Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 1 0 1 1 Rd
361
32000D–04/2011
SWAP.BH – Swap Bytes in Halfword
Architecture revision:
Architecture revision1 and higher.
Description
Swaps different parts of a register.
Operation:
I. Temp ← Rd;
Rd[31:24] ← Temp[23:16];
Rd[23:16] ← Temp[31:24];
Rd[15:8] ← Temp[7:0];
Rd[7:0] ← Temp[15:8];
Syntax:
I. swap.bhRd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 1 1 0 0 Rd
362 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Swaps different parts of a register.
Operation:
I. Temp ← Rd;
Rd[31:16] ← Temp[15:0];
Rd[15:0] ← Temp[31:16];
Syntax:
I. swap.h Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 1 0 1 0 Rd
363
32000D–04/2011
SYNC – Synchronize memory
Architecture revision:
Architecture revision1 and higher.
Description
Finish all pending memory accesses and empties write buffers. The semantic of Op8 is IMPLE-
MENTATION DEFINED.
Operation:
I. Finishes all pending memory operations.
Syntax:
I. sync Op8
Operands:
I. 0 ≤ Op8 ≤ 255
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
31 29 28 25 24 20 19 16
1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0
15 8 7 0
0 0 0 0 0 0 0 0 Op8
364 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Read the contents of the addressed ITLB or DTLB Entry into TLBEHI and TLBELO.
Operation:
I. if (TLBEHI[I] == 1)
{TLBEHI, TLBELO} ←ITLB[MMUCR[IRP]];
else
{TLBEHI, TLBELO} ←DTLB[MMUCR[DRP]];
Syntax:
I. tlbr
Operands:
None
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 0 0 1 0 0 0 0 1 1
Note:
This instruction can only be executed in a privileged mode.
365
32000D–04/2011
TLBS – Search TLB For Entry
Architecture revision:
Architecture revision1 and higher.
Description
Search the addressed TLB for an entry matching TLB Entry High and Low (TLBEHI/TLBELO)
registers. Return a pointer to the entry in MMUCR[IRP] or MMUCR[DRP] if a match found, oth-
erwise set the Not Found bit in the MMU control register, MMUCR[N].
Operation:
I. MMUCR[N] ←1;
if (TLBEHI[I] == 1)
TlbToSearch ←ITLB;
else
TlbToSearch ←DTLB;
endif;
for (i = 0 to TLBToSearchEntries-1)
if ( Compare(TlbToSearch[i]VPN, VA, TlbToSearch[i]SZ, TlbToSearch[i]V) )
// VPN and VA matches for the given page size and entry valid
if ( SharedVMM or
(PrivateVMM and ( TlbToSearch[i]G or (TlbToSearch[i]ASID==TLBEHI[ASID]) ) ) )
ptr ← i;
MMUCR[N] ←0;
endif;
endif;
endfor;
if (TLBEHI[I] == 1)
MMUCR[IRP] ←ptr;
else
MMUCR[DRP] ←ptr;
endif;
Syntax:
I. tlbs
Operands:
None
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
366 AVR32
32000D–04/2011
AVR32
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 1
Note:
This instruction can only be executed in a privileged mode.
367
32000D–04/2011
TLBW – Write TLB Entry
Architecture revision:
Architecture revision1 and higher.
Description
Write the contents of the TLB Entry High and Low (TLBEHI/TLBELO) registers into the
addressed TLB entry.
Operation:
I. if (TLBEHI[I] == 1)
ITLB[MMUCR[IRP]] ← {TLBEHI, TLBELO};
else
ITLB[MMUCR[DRP]] ← {TLBEHI, TLBELO};
Syntax:
I. tlbw
Operands:
None
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Not affected.
C: Not affected.
Opcode:
15 9 8 4 3 0
1 1 0 1 0 1 1 0 0 1 1 0 0 0 1 1
Note:
This instruction can only be executed in a privileged mode.
368 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
If any of the bytes 0,1,2,3 in the word is zero, the SR[Z] flag is set.
Operation:
I. if (Rd[31:24] == 0 ∨
Rd[23:16] == 0 ∨
Rd[15:8] == 0 ∨ Rd[7:0] == 0 )
SR[Z] ← 1;
else
SR[Z] ← 0;
Syntax:
I. tnbz Rd
Operands:
I. d ∈ {0, 1, …, 15}
Status Flags:
Q: Not affected.
V: Not affected.
N: Not affected.
Z: Z ← (Rd[31:24] == 0 ∨ Rd[23:16] == 0 ∨ Rd[15:8] == 0 ∨ Rd[7:0] == 0 )
C: Not affected.
Opcode:
15 13 12 9 8 4 3 0
0 1 0 1 1 1 0 0 1 1 1 0 Rd
369
32000D–04/2011
TST – Test Register
Architecture revision:
Architecture revision1 and higher.
Description
Test register. Used to check if a subset of a register includes one or more set bits. No writeback
of the result is performed, but the flags are set.
Operation:
I. Rd ∧ Rs;
Syntax:
I. tst Rd, Rs
Operands:
I. {d,s} ∈ {0, 1, …, 15}
Status Flags
Q: Not affected
V: Not affected
N: N ← RES[31]
Z: Z ← (RES[31:0] == 0)
C: Not affected
Opcode(s)
15 13 12 9 8 4 3 0
0 0 0 Rs 0 0 1 1 1 Rd
370 AVR32
32000D–04/2011
AVR32
Architecture revision:
Architecture revision1 and higher.
Description
Reads a word from memory pointed to by Rx into register Rd, and writes the value of register Ry
to memory. This instruction can be used to implement binary semaphores (mutexes). The stcond
instruction should be used to implement counting semaphores.
Operation:
I. Temp ← *(Rx);
*(Rx) ← Ry;
Rd ← Temp;
Syntax:
I. xchg Rd, Rx, Ry
Operands:
I. {d,x,y} ∈ {0, 1, …, 14}
Status Flags:
Q: Not affected
V: Not affected
N: Not affected
Z: Not affected
C: Not affected
Opcode:
31 29 28 25 24 20 19 16
1 1 1 Rx 0 0 0 0 0 Ry
15 12 11 4 3 0
0 0 0 0 1 0 1 1 0 1 0 0 Rd
Note:
If R15 is used as Rd, Rx or Ry, the result is UNDEFINED.
If Rd = Ry, the result is UNDEFINED.
If Rd = Rx, the result is UNDEFINED.
371
32000D–04/2011
372 AVR32
32000D–04/2011
AVR32
1. Initial version.
373
32000D–04/2011
374 AVR32
32000D–04/2011
AVR32
Table of contents
Feature Summary...................................................................................... 1
1 Introduction .............................................................................................. 2
1.1 The AVR family ..................................................................................................2
1.2 The AVR32 Microprocessor Architecture .........................................................2
1.3 Microarchitectures .............................................................................................4
i
32000D–04/2011
7 Performance counters ........................................................................... 57
7.1 Overview ..........................................................................................................57
7.2 Registers .........................................................................................................57
7.3 Monitorable events ..........................................................................................59
7.4 Usage ..............................................................................................................60
ii AVR32
32000D–04/2011
Atmel Corporation Atmel Asia Limited Atmel Munich GmbH Atmel Japan
2325 Orchard Parkway Unit 1-5 & 16, 19/F Business Campus 9F, Tonetsu Shinkawa Bldg.
San Jose, CA 95131 BEA Tower, Millennium City 5 Parkring 4 1-24-8 Shinkawa
USA 418 Kwun Tong Road D-85748 Garching b. Munich Chuo-ku, Tokyo 104-0033
Tel: (+1)(408) 441-0311 Kwun Tong, Kowloon GERMANY JAPAN
Fax: (+1)(408) 487-2600 HONG KONG Tel: (+49) 89-31970-0 Tel: (+81)(3) 3523-3551
www.atmel.com Tel: (+852) 2245-6100 Fax: (+49) 89-3194621 Fax: (+81)(3) 3523-7581
Fax: (+852) 2722-1369
Atmel ®, logo and combinations thereof, and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries.
Other terms and product names may be trademarks of others.
Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to
any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL
TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY
EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROF-
ITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL
HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or com-
pleteness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice.
Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suit-
able for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applica-
tions intended to support or sustain life.
32000D–04/2011
Mouser Electronics
Authorized Distributor
Atmel:
ATUC128D4-AUR ATUC128D4-Z1UR ATUC64D3-Z2UR ATUC64D4-AUR ATUC64D4-Z1UT ATUC64D3-A2UR
ATUC256L4U-ZAUT ATUC256L4U-D3HR ATUC256L4U-AUT ATUC128L4U-D3HT ATUC128L4U-AUT
ATUC128L3U-AUT ATUC64L4U-D3HT ATUC64L4U-AUT ATUC64L3U-AUT AT32UC3A0256AU-ALUT
AT32UC3A1256AU-AUR ATUC128D3-A2UR ATUC128D3-Z2UR