16-Bit MCU & DSC Programmer's Reference Manual
16-Bit MCU & DSC Programmer's Reference Manual
DS70157E
Note the following details of the code protection feature on Microchip devices:
Microchip products meet the specification contained in their particular Microchip Data Sheet.
Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchips Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
Microchip is willing to work with the customer who is concerned about the integrity of their code.
Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as unbreakable.
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchips code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Trademarks
The Microchip name and logo, the Microchip logo, dsPIC,
KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART,
PIC32 logo, rfPIC and UNI/O are registered trademarks of
Microchip Technology Incorporated in the U.S.A. and other
countries.
FilterLab, Hampshire, HI-TECH C, Linear Active Thermistor,
MXDEV, MXLAB, SEEVAL and The Embedded Control
Solutions Company are registered trademarks of Microchip
Technology Incorporated in the U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, HI-TIDE, In-Circuit Serial
Programming, ICSP, Mindi, MiWi, MPASM, MPLAB Certified
logo, MPLIB, MPLINK, mTouch, Octopus, Omniscient Code
Generation, PICC, PICC-18, PICDEM, PICDEM.net, PICkit,
PICtail, REAL ICE, rfLAB, Select Mode, Total Endurance,
TSHARC, UniWinDriver, WiperLock and ZENA are
trademarks of Microchip Technology Incorporated in the
U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
2010, Microchip Technology Incorporated, Printed in the
U.S.A., All Rights Reserved.
Printed on recycled paper.
ISBN: 978-1-60932-029-4
Microchip received ISO/TS-16949:2002 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Companys quality system processes and procedures
are for its PIC MCUs and dsPIC DSCs, KEELOQ code hopping
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchips quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.
DS70157E-page 2
Table of Contents
PAGE
SECTION 1. INTRODUCTION
Introduction ......................................................................................................................................................... 6
Manual Objective ................................................................................................................................................ 6
Development Support ......................................................................................................................................... 6
Style and Symbol Conventions ........................................................................................................................... 7
Instruction Set Symbols ...................................................................................................................................... 8
37
Introduction ....................................................................................................................................................... 38
Instruction Set Overview ................................................................................................................................... 38
Instruction Set Summary Tables ....................................................................................................................... 40
51
93
SECTION 6. REFERENCE
441
DS70157E-page 3
456
460
DS70157E-page 4
1
Introduction
Section 1. Introduction
HIGHLIGHTS
This section of the manual contains the following topics:
1.1
1.2
1.3
1.4
1.5
Introduction ....................................................................................................................... 6
Manual Objective .............................................................................................................. 6
Development Support ....................................................................................................... 6
Style and Symbol Conventions ......................................................................................... 7
Instruction Set Symbols .................................................................................................... 8
DS70157E-page 5
INTRODUCTION
Microchip Technology focuses on products for the embedded control market. Microchip is a
leading supplier of the following devices and products:
Information about these devices and products, with corresponding technical documentation, is
available on the Microchip web site (www.microchip.com).
1.2
MANUAL OBJECTIVE
This manual is a software developers reference for the 16-bit MCU and DSC device families. It
describes the Instruction Set in detail and also provides general information to assist the
development of software for the 16-bit MCU and DSC device families.
This manual does not include detailed information about the core, peripherals, system integration
or device-specific information. The user should refer to the specific device family reference
manual for information about the core, peripherals and system integration. For device-specific
information, the user should refer to the individual data sheets. The information that can be found
in the data sheets includes:
Code examples are given throughout this manual. These examples are valid for any device in
the 16-bit MCU and DSC families.
1.3
DEVELOPMENT SUPPORT
Microchip offers a wide range of development tools that allow users to efficiently develop and
debug application code. Microchips development tools can be broken down into four categories:
Code generation
Hardware/Software debug
Device programmer
Product evaluation boards
Information about the latest tools, product briefs and user guides can be obtained from the
Microchip web site (www.microchip.com) or from your local Microchip Sales Office.
Microchip offers other reference tools to speed the development cycle. These include:
Application Notes
Reference Designs
Microchip web site
Local Sales Offices with Field Application Support
Corporate Support Line
The Microchip web site also lists other sites that may be useful references.
DS70157E-page 6
Section 1. Introduction
1.4
Table 1-1:
Document Conventions
Symbol or Term
Description
set
clear
Reset
1.
2.
0xnnnn
: (colon)
<>
LSb, MSb
LSB, MSB
lsw, msw
Courier Font
Used for code examples, binary numbers and for Instruction Mnemonics
in the text.
Times New
Used for equations and variables.
Roman Font, Italic
Times New
Roman Font,
Bold Italic
Used in explanatory text for items called out from a figure, equation, or
example.
Note:
DS70157E-page 7
Introduction
Throughout this document, certain style and font format conventions are used. Table 1-1
provides a description of the conventions used in this document.
Symbol(1)
Description
{ }
[text]
(text)
#text
The literal defined by text
a [b, c, d] a must be in the set of [b, c, d]
<n:m>
{label:}
Acc
AWB
Accumulator A or Accumulator B
Accumulator Write Back
bit4
Expr
4-bit wide bit position (0:7 in Byte mode, 0:15 in Word mode)
Absolute address, label or expression (resolved by the linker)
f
lit1
lit4
lit5
lit8
lit10
lit14
lit16
lit23
Slit4
Slit6
Slit10
Slit16
TOS
Wb
Wd
Wm, Wn
Wm * Wm
Wm * Wn
Wn
Wnd
Wns
WREG
Ws
Wx
Wxd
Source Addressing mode and working register for X data bus prefetch
Destination working register for X data bus prefetch
Wy
Wyd
Source Addressing mode and working register for Y data bus prefetch
Destination working register for Y data bus prefetch
Note 1:
DS70157E-page 8
DS70157E-page 9
Programmers
Model
2.1
2.2
2.3
2.4
2.5
2.1.1
The core of the 16-bit MCU and DSC devices is a 16-bit (data) modified Harvard architecture with
an enhanced instruction set. The core has a 24-bit instruction word, with an 8-bit Op code field.
The Program Counter (PC) is 23 bits wide and addresses up to 4M x 24 bits of user program
memory space. An instruction prefetch mechanism is used to help maintain throughput and
provides predictable execution. The majority of instructions execute in a single cycle.
2.1.1.1
REGISTERS
The 16-bit MCU and DSC devices have sixteen 16-bit working registers. Each of the working
registers can act as a data, address or offset register. The 16th working register (W15) operates
as a software Stack Pointer for interrupts and calls.
2.1.1.2
INSTRUCTION SET
The instruction set is almost identical for the 16-bit MCU and DSC architectures. The instruction
set includes many Addressing modes and was designed for optimum C compiler efficiency.
2.1.1.3
The data space can be addressed as 32K words or 64 Kbytes. The upper 32 Kbytes of the data
space memory map can optionally be mapped into program space at any 16K program word
boundary, which is a feature known as Program Space Visibility (PSV). The program to data
space mapping feature lets any instruction access program space as if it were the data space,
which is useful for storing data coefficients.
Note:
2.1.1.4
Some devices families support Extended Data Space addressing. See the specific
device data sheet and family reference manual for more details on this feature.
ADDRESSING MODES
The core supports Inherent (no operand), Relative, Literal, Memory Direct, Register Direct,
Register Indirect, and Register Offset Addressing modes. Each instruction is associated with a
predefined Addressing mode group, depending upon its functional requirements. As many as
seven Addressing modes are supported for each instruction.
For most instructions, the CPU is capable of executing a data (or program data) memory read, a
working register (data) read, a data memory write and a program (instruction) memory read per
instruction cycle. As a result, 3-operand instructions can be supported, allowing A + B = C
operations to be executed in a single cycle.
DS70157E-page 10
A high-speed, 17-bit by 17-bit multiplier is included to significantly enhance the cores arithmetic
capability and throughput. The multiplier supports Signed, Unsigned, and Mixed modes, as well
as 16-bit by 16-bit, or 8-bit by 8-bit integer multiplication. All multiply instructions execute in a
single cycle.
The 16-bit Arithmetic Logic Unit (ALU) is enhanced with integer divide assist hardware that
supports an iterative non-restoring divide algorithm. It operates in conjunction with the REPEAT
instruction looping mechanism, and a selection of iterative divide instructions, to support 32-bit
(or 16-bit) divided by 16-bit integer signed and unsigned division. All divide operations require 19
cycles to complete, but are interruptible at any cycle boundary.
EXCEPTION PROCESSING
The 16-bit MCU and DSC devices have a vectored exception scheme with support for up to 8
sources of non-maskable traps and up to 246 interrupt sources. In both families, each interrupt
source can be assigned to one of seven priority levels.
2.1.2
In addition to the information provided in 2.1.1 Features Specific to 16-bit MCU and DSC
Core, this section describes the enhancements that are available in the PIC24E and dsPIC33E
families of devices.
2.1.2.1
The Base Data Space address is used in conjunction with a read or write page register (DSRPAG
or DSWPAG) to form an Extended Data Space (EDS) address, which can also be used for PSV
access. The EDS can be addressed as 8 M words or 16 Mbytes. Refer to Section 3. Data
Memory (DS70595) in the dsPIC33E/PIC24E Family Reference Manual for more details on
EDS, PSV, and table accesses.
Note:
2.1.3
Some PIC24F devices also support Extended Data Space. Refer to Section 44.
CPU with EDS (DS39732) and Section 45. Data Memory with EDS
(DS39733) of the PIC24F Family Reference Manual for details.
In addition to the information provided in 2.1.1 Features Specific to 16-bit MCU and DSC
Core, this section describes the DSP enhancements that are available in the dsPIC30F,
dsPIC33F, and dsPIC33E families of devices.
2.1.3.1
Overhead free program loop constructs are supported using the DO instruction, which is
interruptible.
2.1.3.2
The DSP class of instructions.are seamlessly integrated into the architecture and execute from
a single execution unit.
2.1.3.3
The data space is split into two blocks, referred to as X and Y data memory. Each memory block
has its own independent Address Generation Unit (AGU). The MCU class of instructions operate
solely through the X memory AGU, which accesses the entire memory map as one linear data
space. The DSP dual source class of instructions operates through the X and Y AGUs, which
splits the data address space into two parts. The X and Y data space boundary is arbitrary and
device-specific.
DS70157E-page 11
Programmers
Model
2.1.1.6
Overhead-free circular buffers (modulo addressing) are supported in both X and Y address
spaces. The modulo addressing removes the software boundary checking overhead for DSP
algorithms. Furthermore, the X AGU circular addressing can be used with any of the MCU class
of instructions. The X AGU also supports bit-reverse addressing, to greatly simplify input or
output data reordering for radix-2 FFT algorithms.
2.1.3.5
DSP ENGINE
The DSP engine features a high-speed, 17-bit by 17-bit multiplier, a 40-bit ALU, two 40-bit
saturating accumulators and a 40-bit bidirectional barrel shifter. The barrel shifter is capable of
shifting a 40-bit value, up to 16 bits right, or up to 16 bits left, in a single cycle. The DSP
instructions operate seamlessly with all other instructions and have been designed for optimal
real-time performance. The MAC instruction and other associated instructions can concurrently
fetch two data operands from memory while multiplying two working registers. This requires that
the data space be split for these instructions and linear for all others. This is achieved in a
transparent and flexible manner through dedicating certain working registers to each address
space.
2.1.3.6
EXCEPTION PROCESSING
The dsPIC30F devices have a vectored exception scheme with support for up to 8 sources of
non-maskable traps and up to 54 interrupt sources. The dsPIC33F and dsPIC33E have a similar
exception scheme, but support up to 118, and up to 246 interrupt sources, respectively. In all
three families, each interrupt source can be assigned to one of seven priority levels.
DS70157E-page 12
PROGRAMMERS MODEL
Figure 2-1 through Figure show the programmers model diagrams for the 16-bit MCU and DSC
families of devices.
Figure 2-1:
15
PUSH.S
Shadow
Register
0
W0/WREG
W1
Legend
W2
W4
W5
W6
W7
Working Registers
W8
W9
W10
W11
W12
W13
W14/Frame Pointer
W15/Stack Pointer
SPLIM
0
22
0
7
0
TABPAG
TBLPAG
15
0
REPEAT Loop Counter
RCOUNT
15
0
CORCON
DC
0
PSVPAG
PSVPAG
Program Counter
OV
C
Status Register
SRH
SRL
DS70157E-page 13
Programmers
Model
W3
15
PUSH.S and
POP.S Shadow
Registers
0
W0/WREG
W1
Legend
W2
W3
W4
W5
W6
W7
Working Registers
W8
W9
W10
W11
W12
W13
W14/Frame Pointer
W15/Stack Pointer
SPLIM
0
22
0
7
0
TABPAG
TBLPAG
0
Data Space Write Page Address
PSVPAG
DSWPAG
15
0
REPEAT Loop Counter
RCOUNT
15
0
CORCON
DC
0
PSVPAG
DSRPAG
Program Counter
OV
C
Status Register
SRH
DS70157E-page 14
SRL
15
PUSH.S
Shadow
Register
0
W0/WREG
W1
DO Shadow
Register
W2
W3
Legend
W4
MAC Operand
Registers
W5
W6
Programmers
Model
W7
Working Registers
W8
W9
MAC Address
Registers
W10
W11
W12
W13
W14/Frame Pointer
W15/Stack Pointer
SPLIM
39
15
31
0
ACCA
ACCB
22
0
7
0
TABPAG
TBLPAG
0
REPEAT Loop Counter
RCOUNT
15
0
DCOUNT
24
DOSTART
DOEND
24
15
DC
0
CPU Core Control Register
CORCON
SB OAB SAB DA
DO Loop Counter
SA
15
OB
Program Counter
0
PSVPAG
PSVPAG
OA
DSP
Accumulators
OV
C
Status Register
SRH
SRL
DS70157E-page 15
PUSH.S and
POP.S Shadow
Registers
0
W0/WREG
W1
Nested DO
Stack
W2
W3
Legend
W4
MAC Operand
Registers
W5
W6
W7
Working Registers
W8
W9
MAC Address
Registers
W10
W11
W12
W13
W14/Frame Pointer
W15/Stack Pointer
SPLIM
39
15
31
0
ACCA
ACCB
0
22
Program Counter
0
7
0
Data Table Page Address
TABPAG
TBLPAG
9
0
X Data Space Read Page Address
PSVPAG
DSRPAG
8
0
X Data Space Write Page Address
PSVPAG
DSWPAG
15
0
REPEAT Loop Counter
RCOUNT
15
0
DCOUNT
24
DOSTART
DOEND
24
15
SB OAB SAB
DA
DC
CORCON
SA
OB
DO Loop Counter
OA
DSP
Accumulators
OV
C
Status Register
SRH
DS70157E-page 16
SRL
Table 2-1:
Register
PC
PSVPAG(1)
DSRPAG(2)
(2)
DSWPAG
RCOUNT
SPLIM
SR
TBLPAG
W0-W15
ACCA, ACCB(3)
DCOUNT(3)
DOSTART(3)
DOEND(3)
2:
3:
2
Programmers
Model
CORCON
Note 1:
2.3
Description
2.4
DS70157E-page 17
2.5.1
W15 serves as a dedicated Software Stack Pointer, and will be automatically modified by function
calls, exception processing and returns. However, W15 can be referenced by any instruction in
the same manner as all other W registers. This simplifies reading, writing and manipulating the
Stack Pointer. Refer to Section 4.7.1 Software Stack Pointer for detailed information about
the Stack Pointer.
2.5.2
The SPLIM is a 16-bit register associated with the Stack Pointer. It is used to prevent the Stack
Pointer from overflowing and accessing memory beyond the user allocated region of stack
memory. Refer to Section 4.7.3 Stack Pointer Overflow for detailed information about the
SPLIM.
2.5.3
Accumulator A (ACCA) and Accumulator B (ACCB) are 40-bit wide registers, utilized by DSP
instructions to perform mathematical and shifting operations. Each accumulator is composed of
3 memory mapped registers:
AccxU (bits 39-32)
AccxH (bits 31-16)
AccxL (bits 15-0)
Refer to Section 4.12 Accumulator Usage (dsPIC30F, dsPIC33F, and dsPIC33E Devices)
for details on using ACCA and ACCB.
2.5.4
Program Counter
The Program Counter (PC) is 23 bits wide. Instructions are addressed in the 4M x 24-bit user
program memory space by PC<22:1>, where PC<0> is always set to 0 to maintain instruction
word alignment and provide compatibility with data space addressing. This means that during
normal instruction execution, the PC increments by 2.
Program memory located at 0x800000 and above is utilized for device configuration data, Unit ID
and Device ID. This region is not available for user code execution and the PC can not access
this area. However, one may access this region of memory using table instructions. For details
on accessing the configuration data, Unit ID, and Device ID, refer to the specific device family
reference manual.
2.5.5
TBLPAG Register
The TBLPAG register is used to hold the upper 8 bits of a program memory address during table
read and write operations. Table instructions are used to transfer data between program memory
space and data memory space. For details on accessing program memory with the table
instructions, refer to the family reference manual of the specific device.
DS70157E-page 18
Program space visibility allows the user to map a 32-Kbyte section of the program memory space
into the upper 32 Kbytes of data address space. This feature allows transparent access of
constant data through instructions that operate on data memory. The PSVPAG register selects
the 32-Kbyte region of program memory space that is mapped to the data address space. For
details on program space visibility, refer to the specific device family reference manual.
2.5.7
RCOUNT Register
Note 1: If a REPEAT loop is executing and gets interrupted, RCOUNT may be cleared by
the Interrupt Service Routine to break out of the REPEAT loop when the foreground
code is re-entered.
2: Refer to the specific device family reference manual for complete details about
REPEAT loops.
2.5.8
The 14-bit DCOUNT register (16-bit for dsPIC33E devices) contains the loop counter for
hardware DO loops. When a DO instruction is executed, DCOUNT is loaded with the loop count
of the instruction, either lit14 for the DO #lit14,Expr instruction (lit15 for the DO
#lit15,Expr instruction for dsPIC33E devices) or the 14 LSb of the Ws register for the DO
Ws,Expr instruction (entire Wn for dsPIC33E devices). The DO loop will be executed DCOUNT
+ 1 times.
Note 1: In dsPIC30F and dsPIC33F devices, the DCOUNT register contains a shadow
register. See 2.5.13 Shadow Registers for information on shadow registers.
2: The dsPIC33E devices have a 4-level-deep, nested DO stack instead of a shadow
register.
3: Refer to the specific device family reference manual for complete details about DO
loops.
2.5.9
The DOSTART register contains the starting address for a hardware DO loop. When a DO
instruction is executed, DOSTART is loaded with the address of the instruction that follows the
DO instruction. This location in memory is the start of the DO loop. When looping is activated,
program execution continues with the instruction stored at the DOSTART address after the last
instruction in the DO loop is executed. This mechanism allows for zero overhead looping.
Note 1: For dsPIC30F and dsPIC33F devices, DOSTART has a shadow register. See
2.5.13 Shadow Registers for information on shadowing.
2: The dsPIC33E devices have a 4-level-deep, nested DO stack instead of a shadow
register.
3: Refer to the specific device family reference manual for complete details about DO
loops.
DS70157E-page 19
2
Programmers
Model
The 14-bit RCOUNT register (16-bit for PIC24E and dsPIC33E devices) register contains the
loop counter for the REPEAT instruction. When a REPEAT instruction is executed, RCOUNT is
loaded with the repeat count of the instruction, either lit14 for the REPEAT #lit14 instruction
(lit15 for the REPEAT #lit15 instruction for PIC24E and dsPIC33E devices), or the 14 LSb
of the Wn register for the REPEAT Wn instruction (entire Wn for PIC24E and dsPIC33E
devices). The REPEAT loop will be executed RCOUNT + 1 time.
The DOEND register contains the ending address for a hardware DO loop. When a DO instruction
is executed, DOEND is loaded with the address specified by the expression in the DO instruction.
This location in memory specifies the last instruction in the DO loop. When looping is activated
and the instruction stored at the DOEND address is executed, program execution will continue
from the DO loop start address (stored in the DOSTART register).
Note 1: For dsPIC30F and dsPIC33F devices, DOEND has a shadow register. See
2.5.13 Shadow Registers for information on shadow registers.
2: The dsPIC33E devices have a 4-level-deep, nested DO stack instead of a shadow
register.
3: Refer to the specific device family reference manual for complete details about DO
loops.
2.5.11
STATUS Register
The 16-bit STATUS register maintains status information for the instructions which have been
executed most recently. Operation Status bits exist for MCU operations, loop operations and
DSP operations. Additionally, the STATUS register contains the CPU Interrupt Priority Level bits,
IPL<2:0>, which are used for interrupt processing.
Depending on the MCU and DSC family, one of the following STATUS registers is used:
Register 2-1 for PIC24F, PIC24H, and PIC24E devices
Register 2-2 for dsPIC30F and dsPIC33F devices
Register 2-3 for dsPIC33E devices
2.5.11.1
The MCU operation Status bits are either affected or used by the majority of instructions in the
instruction set. Most of the logic, math, rotate/shift and bit instructions modify the MCU Status bits
after execution, and the conditional Branch instructions use the state of individual Status bits to
determine the flow of program execution. All conditional branch instructions are listed in Section
4.8 Conditional Branch Instructions.
The Carry (C), Zero (Z), Overflow (OV), Negative (N), and Digit Carry (DC) bits show the
immediate status of the MCU ALU by indicating whether an operation has resulted in a Carry,
Zero, Overflow, Negative result, or Digit Carry. When a subtract operation is performed, the C
flag is used as a Borrow flag.
The Z Status bit is useful for extended precision arithmetic. The Z Status bit functions like a
normal Z flag for all instructions except those that use a carry or borrow input (ADDC, CPB,
SUBB and SUBBR). See Section 4.9 Z Status Bit for more detailed information.
Note 1: All MCU bits are shadowed during execution of the PUSH.S instruction and they are
restored on execution of the POP.S instruction.
2: All MCU bits, except the DC flag (which is not in the SRL), are stacked during
exception processing (see Section 4.7.1 Software Stack Pointer).
2.5.11.2
The REPEAT Active (RA) bit is used to indicate when looping is active. The RA flag indicates that
a REPEAT instruction is being executed, and it is only affected by the REPEAT instructions. The
RA flag is set to 1 when the instruction being repeated begins execution, and it is cleared when
the instruction being repeated completes execution for the last time.
Since the RA flag is also read-only, it may not be directly cleared. However, if a REPEAT or its
target instruction is interrupted, the Interrupt Service Routine may clear the RA flag of the SRL,
which resides on the stack. This action will disable looping once program execution returns from
the Interrupt Service Routine, because the restored RA will be 0.
DS70157E-page 20
2.5.11.3
The OA and OB bits are used to indicate when an operation has generated an overflow into the
guard bits (bits 32 through 39) of the respective accumulator. This condition can only occur when
the processor is in Super Saturation mode, or if saturation is disabled. It indicates that the
operation has generated a number which cannot be represented with the lower 31 bits of the
accumulator.
The SA and SB bits are used to indicate when an operation has generated an overflow out of the
MSb of the respective accumulator. The SA and SB bits are active, regardless of the Saturation
mode (Disabled, Normal or Super) and may be considered sticky. Namely, once the SA or SB
bit is set to 1, it can only be cleared manually by software, regardless of subsequent DSP
operations. When it is required, the BCLR instruction can be used to clear the SA or SB bit.
In addition, the SA and SB bits can be set by software in dsPIC33E devices, enabling efficient
context state switching.
For convenience, the OA and OB bits are logically ORed together to form the OAB flag, and the
SA and SB bits are logically ORed to form the SAB flag. These cumulative Status bits provide
efficient overflow and saturation checking when an algorithm is implemented. Instead of
interrogating the OA and the OB bits independently for arithmetic overflows, a single check of
OAB can be performed. Likewise, when checking for saturation, SAB may be examined instead
of checking both the SA and SB bits. Note that clearing the SAB flag will clear both the SA and
SB bits.
2.5.11.4
The three Interrupt Priority Level (IPL) bits of the SRL, SR<7:5>, and the IPL3 bit, CORCON<3>,
set the CPUs IPL which is used for exception processing. Exceptions consist of interrupts and
hardware traps. Interrupts have a user-defined priority level between 0 and 7, while traps have a
fixed priority level between 8 and 15. The fourth Interrupt Priority Level bit, IPL3, is a special IPL
bit that may only be read or cleared by the user. This bit is only set when a hardware trap is
activated and it is cleared after the trap is serviced.
The CPUs IPL identifies the lowest level exception which may interrupt the processor. The
interrupt level of a pending exception must always be greater than the CPUs IPL for the CPU to
process the exception. This means that if the IPL is 0, all exceptions at priority Level 1 and above
may interrupt the processor. If the IPL is 7, only hardware traps may interrupt the processor.
When an exception is serviced, the IPL is automatically set to the priority level of the exception
being serviced, which will disable all exceptions of equal and lower priority. However, since the
IPL field is read/write, one may modify the lower three bits of the IPL in an Interrupt Service
Routine to control which exceptions may preempt the exception processing. Since the SRL is
DS70157E-page 21
Programmers
Model
The high byte of the STATUS Register (SRH) is used by the DSP class of instructions, and it is
modified when data passes through one of the adders. The SRH provides status information
about overflow and saturation for both accumulators. The Saturate A, Saturate B, Overflow A and
Overflow B (SA, SB, OA, OB) bits provide individual accumulator status, while the Saturate AB
and Overflow AB (SAB, OAB) bits provide combined accumulator status. The SAB and OAB bits
provide an efficient method for the software developer to check the register for saturation or
overflow.
2.5.12
For more detailed information on exception processing, refer to the family reference
manual of the specific device.
For all MCU and DSC devices, the 16-bit CPU Core Control register (CORCON), is used to set
the configuration of the CPU. This register provides the ability to map program space into data
space.
In addition to setting CPU modes, the CORCON register contains status information about the
IPL<3> Status bit, which indicates if a trap exception is being processed.
Depending on the MCU and DSC family, one of the following CORCON registers is used:
2.5.12.1
In addition to setting CPU modes, the following features are available through the CORCON
register:
2.5.12.2
A Status bit (SFA) is available that indicates whether the Stack Frame is active.
Note:
DS70157E-page 22
Shadow Registers
A shadow register is used as a temporary holding register and can transfer its contents to or from
the associated host register when instructed. Some of the registers in the programmers model
have a shadow register, which is utilized during the execution of a DO, POP.S, or PUSH.S
instruction. Shadow register usage is shown in Table 2-2.
Note:
Table 2-2:
DCOUNT(1)
Yes
DOSTART(1)
Yes
DOEND(1)
Yes
Yes
W0-W3
Yes
Note 1:
The DO shadow registers are only available in dsPIC30F and dsPIC33F devices.
For dsPIC30F and dsPIC33F devicessince the DCOUNT, DOSTART and DOEND registers
are shadowedthe ability to nest DO loops without additional overhead is provided. Since all
shadow registers are one register deep, up to one level of DO loop nesting is possible. Further
nesting of DO loops is possible in software, with support provided by the DO Loop Nesting Level
Status bits (DL<2:0>) in the CORCON register (CORCON<10:8>).
Note:
2.5.14
All shadow registers are one register deep and not directly accessible. Additional
shadowing may be performed in software using the software stack.
The DO stack is used to preserve the following elements associated with a DO loop underway
when another DO loop is encountered (i.e., a nested DO loop).
Note that the DO level status field (DL<2:0>) also acts as a pointer to address the DO stack. After
the DO instruction is executed, the DO level status field (DL<2:0>) points to the next free entry.
The DOSTART, DOEND, and DCOUNT registers each have an associated hardware stack that
allows the DO loop hardware to support up to three levels of nesting. A conceptual representation
of the DO stack is shown in Figure 2-5.
DS70157E-page 23
Programmers
Model
DO(1)
Location
DL<2:0>
DOSTART
DOEND
DCOUNT
Odd Loop Op
Even Loop Op
000
Empty
001
Level 1 Registers
Level 1 Ops
010
Level 2 Registers
Level 2 Ops
011
Level 3 Registers
Level 3 Ops
Level 4 Ops
100
Note 1:
DS70157E-page 24
For DO register entries, DL<2:0> represents the value before the DO stack is executed.
2:
For DO instruction buffer entries, DL<2:0> represents the value after the DO stack is executed.
3:
U-0
U-0
U-0
U-0
U-0
U-0
U-0
R/W-0
DC
bit 15
bit 8
R/W-0
R/W-0
(1,2)
IPL1
IPL2
(1,2)
R/W-0
IPL0
(1,2)
R-0
R/W-0
R/W-0
R/W-0
R/W-0
RA
OV
bit 7
bit 0
U = Unimplemented bit, read as 0
R = Readable bit
W = Writable bit
C = Clearable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 15-9
Unimplemented: Read as 0
bit 8
bit 7-5
bit 4
bit 3
bit 2
bit 1
bit 0
Note 1: The IPL<2:0> bits are concatenated with the IPL3 bit (CORCON<3>) to form the CPU Interrupt Priority
Level. The value in parentheses indicates the IPL, if IPL3 = 1. User interrupts are disabled when
IPL<3> = 1.
2: The IPL<2:0> Status bits are read only when NSTDIS = 1 (INTCON1<15>). Refer to the family reference
manual of the specific device family to see the associated interrupt register.
DS70157E-page 25
Programmers
Model
Legend:
R-0
OA
R-0
R/C-0
R/C-0
OB
(1,2)
(1,2)
SA
SB
R-0
OAB
R/C-0
(1,2,3)
SAB
R-0
R/W-0
(4)
DA
DC
bit 15
bit 8
R/W-0
R/W-0
R/W-0
R-0
R/W-0
R/W-0
R/W-0
R/W-0
(5)
(5)
(5)
RA
OV
IPL2
IPL1
IPL0
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
C = Clearable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 15
bit 14
bit 13
bit 12
bit 11
bit 10
bit 9
bit 8
bit 7-5
DS70157E-page 26
bit 3
bit 2
bit 1
bit 0
2
Programmers
Model
bit 4
DS70157E-page 27
R/W-0
R/W-0
OA
OB
R/W-0
(3)
SA
R/W-0
(3)
SB
R/C-0
R/C-0
R -0
R/W-0
OAB
SAB
DA
DC
bit 15
bit 8
R/W-0
R/W-0
(1,2)
IPL1
IPL2
(1,2)
R/W-0
IPL0
(1,2)
R-0
R/W-0
R/W-0
R/W-0
R/W-0
RA
OV
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
C = Clearable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 15
bit 14
bit 13
bit 12
bit 11
bit 10
bit 9
bit 8
Note 1: The IPL<2:0> bits are concatenated with the IPL3 bit (CORCON<3>) to form the CPU Interrupt Priority
Level. The value in parentheses indicates the IPL, if IPL3 = 1. User interrupts are disabled when IPL3 = 1.
2: The IPL<2:0> Status bits are read only when NSTDIS = 1 (INTCON1<15>). Refer to the family reference
manual of the specific device family to see the associated interrupt register.
3: A data write to SR can modify the SA or SB bits by either a data write to SA and SB or by clearing the SAB
bit. To avoid a possible SA/SB bit write race-condition, the SA and SB bits should not be modified using
bit operations.
DS70157E-page 28
bit 3
bit 2
bit 1
bit 0
Note 1: The IPL<2:0> bits are concatenated with the IPL3 bit (CORCON<3>) to form the CPU Interrupt Priority
Level. The value in parentheses indicates the IPL, if IPL3 = 1. User interrupts are disabled when IPL3 = 1.
2: The IPL<2:0> Status bits are read only when NSTDIS = 1 (INTCON1<15>). Refer to the family reference
manual of the specific device family to see the associated interrupt register.
3: A data write to SR can modify the SA or SB bits by either a data write to SA and SB or by clearing the SAB
bit. To avoid a possible SA/SB bit write race-condition, the SA and SB bits should not be modified using
bit operations.
DS70157E-page 29
Programmers
Model
bit 4
U-0
bit 15
bit 8
U
R/C-0
IPL3
(1,2)
R/W-0
U-0
PSV
bit 7
bit 0
Legend:
C = Clearable bit
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
Unimplemented: Read as 0
bit 3
bit 2
bit 1-0
DS70157E-page 30
R/W-0
U-0
U-0
U-0
U-0
U-0
U-0
U-0
VAR
bit 15
bit 8
U-0
U-0
U-0
U-0
R/C-0
(1,2)
IPL3
R-0
U-0
U-0
SFA
bit 7
bit 0
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 15
bit 14-4
bit 3
bit 2
bit 1-0
DS70157E-page 31
Programmers
Model
Legend:
R/W-0
R(0)/W-0
US
EDT(1)
R-0
R-0
R-0
DL<2:0>(2,3)
bit 15
bit 8
R/W-0
R/W-0
SATA
SATB
R/W-1
SATDW
R/W-0
ACCSAT
R/C-0
IPL3
(4,5)
R/W-0
R/W-0
R/W-0
PSV
RND
IF
bit 7
bit 0
Legend:
C = Clearable bit
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
x = Bit is unknown
bit 12
bit 11
bit 10-8
bit 7
bit 6
bit 5
SATDW: Data Space Write from DSP Engine Saturation Enable bit
1 = Data space write saturation enabled
0 = Data space write saturation disabled
bit 4
bit 3
DS70157E-page 32
bit 2
bit 1
bit 0
DS70157E-page 33
Programmers
Model
R/W-0
U-0
VAR
R/W-0
R/W-0
R/W-0
US<1:0>
EDT
R-0
(1)
R-0
R-0
DL<2:0>
bit 15
bit 8
R/W-0
R/W-0
SATA
SATB
R/W-1
SATDW
R/W-0
R/C-0
(2,3)
ACCSAT
IPL3
R-0
R/W-0
R/W-0
SFA
RND
IF
bit 7
bit 0
Legend:
R = Readable bit
W = Writable bit
-n = Value at POR
1 = Bit is set
0 = Bit is cleared
bit 15
x = Bit is unknown
bit 14
bit 13-12
bit 11
bit 10-8
bit 7
bit 6
bit 5
SATDW: Data Space Write from DSP Engine Saturation Enable bit
1 = Data space write saturation enabled
0 = Data space write saturation disabled
bit 4
bit 3
DS70157E-page 34
bit 2
bit 1
bit 0
DS70157E-page 35
Programmers
Model
DS70157E-page 36
Introduction ..................................................................................................................... 38
Instruction Set Overview ................................................................................................. 38
Instruction Set Summary Tables ..................................................................................... 40
3
Instruction Set
Overview
DS70157E-page 37
INTRODUCTION
The 16-bit MCU and DSC instruction set provides a broad suite of instructions which supports
traditional microcontroller applications, and a class of instructions which supports math intensive
applications. Since almost all of the functionality of the 8-bit PIC MCU instruction set has been
maintained, this hybrid instruction set allows an easy 16-bit migration path for users already
familiar with the PIC microcontroller.
3.2
Instruction Groups
Functional Group
Summary Table
Page Number
Move Instructions
Table 3-2
40
Math Instructions
Table 3-3
41
Logic Instructions
Table 3-4
43
Rotate/Shift Instructions
Table 3-5
44
Bit Instructions
Table 3-6
45
Table 3-7
46
Table 3-8
47
Shadow/Stack Instructions
Table 3-9
49
Control Instructions
Table 3-10
49
DSP Instructions(1)
Table 3-11
49
Note 1:
DSP instructions are only available in the dsPIC30F, dsPIC33F, and dsPIC33E
device families.
Most instructions have several different Addressing modes and execution flows, which require
different instruction variants. For instance, depending on the device family, there are up to six
unique ADD instructions and each instruction variant has its own instruction encoding. Instruction
format descriptions and specific instruction operation are provided in Section 5. Instruction
Descriptions. Additionally, a composite alphabetized instruction set table is provided in
Section 6. Reference.
DS70157E-page 38
Multi-Cycle Instructions
As the instruction summary tables show, most instructions execute in a single cycle, with the
following exceptions:
Note:
The DO and DIVF instructions are only available in the dsPIC30F, dsPIC33F, and
dsPIC33E device families.
2: All instructions may incur an additional delay on some device families, depending
on Flash memory access time. For example, PIC24E and dsPIC33E devices have
a 3-cycle Flash memory access time. However, instruction pipelining increases the
effective instruction execution throughput. Refer to Section 2. CPU of the
specific device family reference manual for details on instruction timing.
3: All read and read-modify-write operations (including bit operations) on non-CPU
Special Function Registers (e.g., I/O Port, peripheral control, or status registers;
interrupt flags, etc.) in PIC24E and dsPIC33E devices require 2 instruction cycles
to execute.
3.2.2
Multi-Word Instructions
As defined by Table 3-2, almost all instructions consume one instruction word (24 bits), with the
exception of the CALL, DO and GOTO instructions, which are Program Flow Instructions, listed
in Table 3-8. These instructions require two words of memory because their opcodes embed
large literal operands.
DS70157E-page 39
3
Instruction Set
Overview
Note 1: Instructions which access program memory as data, using Program Space Visibility
(PSV), will incur a one or two cycle delay for PIC24F, PIC24H, dsPIC30F, and
dsPIC33F devices, whereas using PSV in dsPIC33E and PIC24E devices incurs a
4-cycle delay based on Flash memory access time. However, regardless of which
device is being used, when the target instruction of a REPEAT loop accesses program memory as data, only the first execution of the target instruction is subject to
the delay. See the specific device family reference manual for details.
Table 3-2:
Move Instructions
Words
Cycles
Page
Number
247
282
Assembly Syntax
EXCH
Wns,Wnd
(1)
Description
MOV
f {,WREG}
Move f to destination
MOV
WREG,f
Move WREG to f
283
MOV
f,Wnd
Move f to Wnd
284
MOV
Wns,f
Move Wns to f
285
MOV.B
#lit8,Wnd
286
MOV
#lit16,Wnd
287
MOV
[Ws+Slit10],Wnd
288
MOV
Wns,[Wd+Slit10]
289
MOV
Ws,Wd
Move Ws to Wd
290
MOV.D
Ws,Wnd
292
MOV.D
Wns,Wd
292
MOVPAG
#lit10,DSRPAG(2)
294
MOVPAG
#lit9,DSWPAG(2)
294
MOVPAG
#lit8,TBLPAG(2)
294
SWAP
Wn
422
TBLRDH
Ws,Wd
2(3)
423
2(3)
425
TBLRDL
Ws,Wd
TBLWTH
Ws,Wd
427
TBLWTL
Ws,Wd
429
Note 1:
2:
3:
When the optional {,WREG} operand is specified, the destination of the instruction is WREG. When
{,WREG} is not specified, the destination of the instruction is the file register f.
The MOVPAG instruction is only available in dsPIC33E and PIC24E devices.
In dsPIC33E and PIC24E devices, these instructions require 3 additional cycles compared to dsPIC30F,
dsPIC33F, PIC24F and PIC24H devices.
DS70157E-page 40
Math Instructions
Assembly Syntax
Description
Words
Cycles
Page
Number
ADD
f {,WREG}(1)
Destination = f + WREG
100
ADD
#lit10,Wn
Wn = lit10 + Wn
101
ADD
Wb,#lit5,Wd
Wd = Wb + lit5
102
ADD
Wb,Ws,Wd
Wd = Wb + Ws
104
(1)
ADDC
f {,WREG}
109
ADDC
#lit10,Wn
Wn = lit10 + Wn + (C)
110
ADDC
Wb,#lit5,Wd
Wd = Wb + lit5 + (C)
111
ADDC
Wb,Ws,Wd
Wd = Wb + Ws + (C)
113
DAW.B
Wn
Wn = decimal adjust Wn
222
DEC
f {,WREG}(1)
Destination = f 1
223
DEC
Ws,Wd
Wd = Ws 1
224
DEC2
f {,WREG}(1)
Destination = f 2
226
DEC2
Ws,Wd
Wd = Ws 2
227
DIV.S
Wm, Wn
18(2)
229
DIV.SD
Wm, Wn
18(2)
229
DIV.U
Wm, Wn
18(2)
231
231
Wm, Wn
DIVF
Wm, Wn
18(2)
233
INC
f {,WREG}(1)
Destination = f + 1
258
INC
Ws,Wd
Wd = Ws + 1
259
(1)
INC2
f {,WREG}
Destination = f + 2
260
INC2
Ws,Wd
Wd = Ws + 2
261
MUL
W3:W2 = f * WREG
306
MUL.SS
Wb,Ws,Wnd
307
MUL.SS
Wb,Ws,Acc(4)
309
MUL.SU
Wb,#lit5,Wnd
310
MUL.SU
Wb,Ws,Wnd
312
MUL.SU
Wb,Ws,Acc(4)
314
(4)
MUL.SU
Wb,#lit5,Acc
315
MUL.US
Wb,Ws,Wnd
316
MUL.US
Wb,Ws,Acc(4)
318
MUL.UU
Wb,#lit5,Wnd
319
MUL.UU
Wb,Ws,Wnd
320
MUL.UU
Wb,Ws,Acc(4)
322
MUL.UU
323
MULW.SS
Wb,Ws,Wnd(3)
324
MULW.SU
Wb,Ws,Wnd(3)
326
MULW.SU
328
329
MULW.US
Note 1:
2:
3:
4:
Wb,Ws,Wnd
(3)
When the optional {,WREG} operand is specified, the destination of the instruction is WREG. When
{,WREG} is not specified, the destination of the instruction is the file register f.
The divide instructions must be preceded with a REPEAT #17 instruction, such that they are executed
18 consecutive times.
These instructions are only available in dsPIC33E and PIC24E devices.
These instructions are only available in dsPIC33E devices.
DS70157E-page 41
3
Instruction Set
Overview
DIV.UD
18(2)
Assembly Syntax
Description
Words
Cycles
Page
Number
MULW.UU
Wb,Ws,Wnd(3)
331
MULW.UU
Wb,#lit5,Wnd(3)
332
SE
Ws,Wnd
Wnd = signed-extended Ws
391
SUB
f {,WREG}(1)
Destination = f WREG
401
SUB
#lit10,Wn
Wn = Wn lit10
402
SUB
Wb,#lit5,Wd
Wd = Wb lit5
403
SUB
Wb,Ws,Wd
Wd = Wb Ws
404
SUBB
f {,WREG}(1)
407
SUBB
#lit10,Wn
Wn = Wn lit10 (C)
408
SUBB
Wb,#lit5,Wd
Wd = Wb lit5 (C)
409
Wd = Wb Ws (C)
411
413
Wd = lit5 Wb (C)
414
SUBB
Wb,Ws,Wd
(1)
SUBBR
f {,WREG}
SUBBR
Wb,#lit5,Wd
SUBBR
Wb,Ws,Wd
Wd = Ws Wb (C)
416
SUBR
f {,WREG}(1)
Destination = WREG f
418
SUBR
Wb,#lit5,Wd
Wd = lit5 Wb
419
SUBR
Wb,Ws,Wd
Wd = Ws Wb
420
Ws,Wnd
Wnd = zero-extended Ws
439
ZE
Note 1:
2:
3:
4:
When the optional {,WREG} operand is specified, the destination of the instruction is WREG. When
{,WREG} is not specified, the destination of the instruction is the file register f.
The divide instructions must be preceded with a REPEAT #17 instruction, such that they are executed
18 consecutive times.
These instructions are only available in dsPIC33E and PIC24E devices.
These instructions are only available in dsPIC33E devices.
DS70157E-page 42
Logic Instructions
Assembly Syntax
Description
Words
Cycles
Page
Number
AND
f {,WREG}(1)
115
AND
#lit10,Wn
Wn = lit10 .AND. Wn
116
AND
Wb,#lit5,Wd
Wd = Wb .AND. lit5
117
AND
Wb,Ws,Wd
Wd = Wb .AND. Ws
118
CLR
f = 0x0000
188
CLR
WREG
WREG = 0x0000
188
CLR
Wd
Wd = 0x0000
189
COM
f {,WREG}(1)
Destination = f
193
COM
Ws,Wd
Wd = Ws
194
IOR
f {,WREG}(1)
262
IOR
#lit10,Wn
Wn = lit10 .IOR. Wn
263
IOR
Wb,#lit5,Wd
Wd = Wb .IOR. lit5
264
IOR
Wb,Ws,Wd
Wd = Wb .IOR. Ws
266
NEG
f {,WREG}(1)
Destination = f + 1
333
Ws,Wd
Wd = Ws + 1
334
f = 0xFFFF
392
SETM
WREG
WREG = 0xFFFF
392
SETM
Wd
Wd = 0xFFFF
393
XOR
f {,WREG}(1)
433
XOR
#lit10,Wn
Wn = lit10 .XOR. Wn
434
XOR
Wb,#lit5,Wd
Wd = Wb .XOR. lit5
435
XOR
Wb,Ws,Wd
Wd = Wb .XOR. Ws
437
Note 1:
When the optional {,WREG} operand is specified, the destination of the instruction is WREG. When
{,WREG} is not specified, the destination of the instruction is the file register f.
DS70157E-page 43
3
Instruction Set
Overview
NEG
SETM
Rotate/Shift Instructions
Assembly Syntax
(1)
Description
Words
Cycles
Page #
ASR
f {,WREG}
120
ASR
Ws,Wd
122
ASR
Wb,#lit4,Wnd
124
ASR
Wb,Wns,Wnd
125
(1)
LSR
f {,WREG}
272
LSR
Ws,Wd
274
LSR
Wb,#lit4,Wnd
276
LSR
Wb,Wns,Wnd
277
374
376
378
379
RLC
f {,WREG}
RLC
Ws,Wd
RLNC
f {,WREG}
RLNC
Ws,Wd
(1)
(1)
{,WREG}(1)
RRC
381
RRC
Ws,Wd
382
RRNC
f {,WREG}(1)
384
RRNC
Ws,Wd
385
(1)
SL
f {,WREG}
396
SL
Ws,Wd
Wd = left shift Ws
397
SL
Wb,#lit4,Wnd
399
SL
Wb,Wns,Wnd
400
Note 1:
When the optional {,WREG} operand is specified, the destination of the instruction is WREG. When
{,WREG} is not specified, the destination of the instruction is the file register f.
DS70157E-page 44
Bit Instructions
Assembly Syntax
Description
Words
Cycles
Page
Number
127
f,#bit4
Bit clear f
BCLR
Ws,#bit4
Bit clear Ws
128
BSET
f,#bit4
Bit set f
156
BSET
Ws,#bit4
Bit set Ws
157
BSW.C
Ws,Wb
159
BSW.Z
Ws,Wb
159
BTG
f,#bit4
Bit toggle f
161
BTG
Ws,#bit4
Bit toggle Ws
162
BTST
f,#bit4
Bit test f
171
BTST.C
Ws,#bit4
Bit test Ws to C
172
BTST.Z
Ws,#bit4
Bit test Ws to Z
172
BTST.C
Ws,Wb
174
BTST.Z
Ws,Wb
174
BTSTS
f,#bit4
176
BTSTS.C
Ws,#bit4
177
BTSTS.Z
Ws,#bit4
177
FBCL
Ws,Wnd
248
FF1L
Ws,Wnd
250
FF1R
Ws,Wnd
252
DS70157E-page 45
3
Instruction Set
Overview
BCLR
Assembly Syntax
Description
Words
Cycles(1)
Page
Number
BTSC
f,#bit4
1 (2 or 3)
164
BTSC
Ws,#bit4
1 (2 or 3)
166
BTSS
f,#bit4
1 (2 or 3)
168
BTSS
Ws,#bit4
1 (2 or 3)
169
CP
Compare (f WREG)
196
CP
Wb,#lit5(2)
197
CP
Wb,#lit8(3)
198
CP
Wb,Ws
199
CP0
Compare (f 0x0000)
200
CP0
Ws
201
CPB
202
CPB
Wb,#lit5
(2)
203
CPB
Wb,#lit8(3)
205
CPB
Wb,Ws
207
(5)(4)
209
1 (5)(4)
210
1 (5)(4)
211
(5)(4)
212
Wb,Wn,Expr
(3)
CPBGT
Wb,Wn,Expr
(3)
CPBLT
CPBEQ
(3)
CPBNE
Wb,Wn,Expr
CPSEQ
Wb, Wn
1 (2 or 3)
213
CPSGT
Wb, Wn
1 (2 or 3)
217
CPSLT
Wb, Wn
1 (2 or 3)
218
CPSNE
Wb, Wn
1 (2 or 3)
220
Note 1:
2:
3:
4:
Conditional skip instructions execute in 1 cycle if the skip is not taken, 2 cycles if the skip is taken over a
one-word instruction and 3 cycles if the skip is taken over a two-word instruction.
This instruction is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction is only available in dsPIC33E and PIC24E devices.
Compare-branch instructions in dsPIC33E/PIC24E devices execute in 1 cycle if the branch is not taken and
5 cycles if the branch is taken.
DS70157E-page 46
Assembly Syntax
BRA
Expr
Description
Branch unconditionally
Words
Cycles
Page
Number
2(8)
130
(8)
132
BRA
Wn
Computed branch
BRA
C,Expr
1 (2)(1,8)
134
(2)(1,8)
136
BRA
GE,Expr
BRA
GEU,Expr
1 (2)(1,8)
138
(1,8)
139
(2)(1,8)
140
(1,8)
BRA
GT,Expr
BRA
GTU,Expr
1 (2)
1
BRA
LE,Expr
1 (2)
141
BRA
LEU,Expr
1 (2)(1,8)
142
(2)(1,8)
143
BRA
LT,Expr
BRA
LTU,Expr
1 (2)(1,8)
144
(1,8)
145
(2)(1,8)
146
(2)(1,8)
147
BRA
N,Expr
BRA
NC,Expr
Branch if Negative
Branch if not Carry (Borrow)
1 (2)
BRA
NN,Expr
BRA
NOV,Expr
1 (2)(1,8)
148
(2)(1,8)
149
BRA
NZ,Expr
BRA
OA,Expr
1 (2)(1,8)
150
(1,8)
151
OB,Expr
1 (2)
BRA
OV,Expr
Branch if Overflow
1 (2)(1,8)
152
(2)(1,8)
153
BRA
SA,Expr
BRA
SB,Expr
1 (2)(1,8)
154
(2)(1,8)
155
BRA
Z,Expr
Branch if Zero
CALL
Expr
Call subroutine
2(8)
179
(8)
183
CALL
Wn
CALL.L
Wn(4)
187
DO
#lit14,Expr(6
235
DO
#lit15,Expr(7
237
DO
Wn,Expr(3)
239
(8)
254
)
)
GOTO
Expr
Go to address
GOTO
Wn
Go to address indirectly
2(8)
255
257
Relative call
2(8)
348
2(8)
352
(4)
GOTO.L
Wn
RCALL
Expr
RCALL
Note 1:
2:
3:
4:
5:
6:
7:
8:
9:
Wn
Computed call
Conditional branch instructions execute in 1 cycle if the branch is not taken, or 2 cycles if the branch is
taken.
RETURN instructions execute in 3 cycles, but if an exception is pending, they execute in 2 cycles.
This instruction is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction is only available in dsPIC33E and PIC24E devices.
This instruction is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction is only available in dsPIC30F and dsPIC33F devices.
This instruction is only available in dsPIC33E devices.
In dsPIC33E and PIC24E devices, these instructions require 2 additional cycles (4 cycles overall) when
the branch is taken.
In dsPIC33E and PIC24E devices, these instructions require 3 additional cycles.
DS70157E-page 47
3
Instruction Set
Overview
BRA
Assembly Syntax
Description
Words
Cycles
Page
Number
356
REPEAT
#lit14(5)
REPEAT
(4)
#lit15
358
REPEAT
Wn
360
3 (2)(2,9)
366
3 (2)(2,9)
368
(2,9)
372
RETFIE
RETLW
#lit10,Wn
RETURN
Note 1:
2:
3:
4:
5:
6:
7:
8:
9:
3 (2)
Conditional branch instructions execute in 1 cycle if the branch is not taken, or 2 cycles if the branch is
taken.
RETURN instructions execute in 3 cycles, but if an exception is pending, they execute in 2 cycles.
This instruction is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction is only available in dsPIC33E and PIC24E devices.
This instruction is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction is only available in dsPIC30F and dsPIC33F devices.
This instruction is only available in dsPIC33E devices.
In dsPIC33E and PIC24E devices, these instructions require 2 additional cycles (4 cycles overall) when
the branch is taken.
In dsPIC33E and PIC24E devices, these instructions require 3 additional cycles.
DS70157E-page 48
Shadow/Stack Instructions
Assembly Syntax
Description
Words
Cycles
Page
Number
LNK
#lit14
270
POP
POP TOS to f
338
POP
Wd
POP TOS to Wd
339
POP.D
Wnd
340
341
PUSH f to TOS
342
PUSH
Ws
PUSH Ws to TOS
343
PUSH.D
Wns
345
POP.S
PUSH
PUSH.S
346
ULNK
431
Words
Cycles
Page
Number
Table 3-10:
Control Instructions
Assembly Syntax
Description
Clear Watchdog Timer
192
228
NOP
No operation
336
NOPR
No operation
337
CLRWDT
DISI
#lit1
RESET
Table 3-11:
347
364
Words
Cycles
Page
Number
Description
ADD
Acc
Add accumulators
106
ADD
Ws,#Slit4,Acc
107
CLR
Acc,Wx,Wxd,Wy,Wyd,AWB
Clear Acc
190
ED
Wm*Wm,Acc,Wx,Wy,Wxd
Euclidean distance
(no accumulate)
243
EDAC
Wm*Wm,Acc,Wx,Wy,Wxd
Euclidean distance
245
LAC
Ws,#Slit4,Acc
Load Acc
268
MAC
278
MAC
Wm*Wm,Acc,Wx,Wxd,Wy,Wyd
280
MOVSAC
Acc,Wx,Wxd,Wy,Wyd,AWB
296
MPY
Wm*Wn,Acc,Wx,Wxd,Wy,Wyd
Multiply Wn by Wm to Acc
298
MPY
Wm*Wm,Acc,Wx,Wxd,Wy,Wyd
Square to Acc
300
MPY.N
Wm*Wn,Acc,Wx,Wxd,Wy,Wyd
302
MSC
304
NEG
Acc
Negate Acc
335
SAC
Acc,#Slit4,Wd
Store Acc
387
SAC.R
Acc,#Slit4,Wd
389
SFTAC
Acc,#Slit6
394
SFTAC
Acc,Wn
395
SUB
Acc
Subtract accumulators
406
DS70157E-page 49
3
Instruction Set
Overview
PWRSAV
#lit14
DS70157E-page 50
4
Instruction Set
Details
DS70157E-page 51
Addressing Mode
File Register
Register Direct
Register Indirect
0x0000-0xFFFF
Immediate
Note:
4.1.1
Address Range
DS70157E-page 52
Before Instruction:
Data Memory 0x1000 = 0x5555
After Instruction:
Data Memory 0x1000 = 0x5554
MOV
0x27FE, W0
Before Instruction:
W0 = 0x5555
Data Memory 0x27FE = 0x1234
After Instruction:
W0 = 0x1234
Data Memory 0x27FE = 0x1234
Example 4-2:
AND
Before Instruction:
W0 (WREG) = 0x332C
Data Memory 0x1000 = 0x5555
After Instruction:
W0 (WREG) = 0x332C
Data Memory 0x1000 = 0x1104
AND
0x1000, WREG
Before Instruction:
W0 (WREG) = 0x332C
Data Memory 0x1000 = 0x5555
After Instruction:
W0 (WREG) = 0x1104
Data Memory 0x1000 = 0x5555
4.1.2
Another feature of register direct addressing is that it provides the ability for dynamic flow control.
Since variants of the DO and REPEAT instruction support register direct addressing, flexible
looping constructs may be generated using these instructions.
Note:
Instructions which must use register direct addressing, use the symbols Wb, Wn,
Wns and Wnd in the summary tables of Section 3. Instruction Set Overview.
Commonly, register direct addressing may also be used when register indirect
addressing may be used. Instructions which use register indirect addressing, use
the symbols Wd and Ws in the summary tables of Section 3. Instruction Set
Overview.
DS70157E-page 53
Instruction Set
Details
Register direct addressing is used to access the contents of the 16 working registers (W0:W15).
The Register Direct Addressing mode is fully orthogonal, which allows any working register to be
specified for any instruction that uses register direct addressing, and it supports both byte and
word accesses. Instructions which employ register direct addressing use the contents of the
specified working register as data to execute the instruction, therefore this Addressing mode is
useful only when data already resides in the working register core. Sample instructions which
utilize register direct addressing are shown in Example 4-3.
W2, W3
; Exchange W2 and W3
Before Instruction:
W2 = 0x3499
W3 = 0x003D
After Instruction:
W2 = 0x003D
W3 = 0x3499
IOR
#0x44, W0
Before Instruction:
W0 = 0x9C2E
After Instruction:
W0 = 0x9C6E
SL
W6, W7, W8
Before Instruction:
W6 = 0x000C
W7 = 0x0008
W8 = 0x1234
After Instruction:
W6 = 0x000C
W7 = 0x0008
W8 = 0x0C00
4.1.3
Register indirect addressing is used to access any location in data memory by treating the
contents of a working register as an Effective Address (EA) to data memory. Essentially, the
contents of the working register become a pointer to the location in data memory which is to be
accessed by the instruction.
This Addressing mode is powerful, because it also allows one to modify the contents of the
working register, either before or after the data access is made, by incrementing or decrementing
the EA. By modifying the EA in the same cycle that an operation is being performed, register
indirect addressing allows for the efficient processing of data that is stored sequentially in
memory. The modes of indirect addressing supported by the 16-bit MCU and DSC devices are
shown in Table 4-2.
Table 4-2:
Indirect Mode
No Modification
Syntax
[Wn]
Function
(Byte Instruction)
EA = [Wn]
Function
(Word Instruction)
EA = [Wn]
Description
The contents of Wn forms the EA.
Pre-Increment
[++Wn]
EA = [Wn + = 1]
EA = [Wn + = 2]
Pre-Decrement
[--Wn]
EA = [Wn = 1]
EA = [Wn = 2]
Post-Increment
[Wn++]
EA = [Wn]+ = 1
EA = [Wn]+ = 2
EA = [Wn] = 1
EA = [Wn] = 2
EA = [Wn + Wb]
Post-Decrement [Wn--]
Register Offset
DS70157E-page 54
The MOV with offset instructions (see pages 288 and 289) provides a literal addressing offset ability to be used with indirect addressing. In these instructions, the EA is
formed by adding the contents of a working register to a signed 10-bit literal.
Example 4-6 shows how these instructions may be used to move data to and from
the working register array.
Example 4-4:
MOV.B
Before Instruction:
W0 = 0x2300
W13 = 0x2708
Data Memory 0x2300 = 0x7783
Data Memory 0x2708 = 0x904E
After Instruction:
W0 = 0x2301
W13 = 0x2707
Data Memory 0x2300 = 0x7783
Data Memory 0x2708 = 0x9083
ADD
W1 =
W5 =
W8 =
Data
Data
Instruction Set
Details
Before Instruction:
0x0800
0x2200
0x2400
Memory 0x21FE = 0x7783
Memory 0x2402 = 0xAACC
After Instruction:
W1 =
W5 =
W8 =
Data
Data
0x0800
0x21FE
0x2402
Memory 0x21FE = 0x7783
Memory 0x2402 = 0x7F83
DS70157E-page 55
Before Instruction:
W0 =
W1 =
W7 =
Data
Data
0x2300
0x01FE
0x1000
Memory 0x24FE = 0x7783
Memory 0x1000 = 0x11DC
After Instruction:
W0 =
W1 =
W7 =
Data
Data
0x2300
0x01FE
0x1001
Memory 0x24FE = 0x7783
Memory 0x1000 = 0x1183
LAC
[W0+W8], A
Before Instruction:
W0 =
W8 =
ACCA
Data
0x2344
0x0008
= 0x00 7877 9321
Memory 0x234C = 0xE290
After Instruction:
W0 =
W8 =
ACCA
Data
0x2344
0x0008
= 0xFF E290 0000
Memory 0x234C = 0xE290
Example 4-6:
MOV
; move [W0+0x20] to W1
Before Instruction:
W0 = 0x1200
W1 = 0x01FE
Data Memory 0x1220 = 0xFD27
After Instruction:
W0 = 0x1200
W1 = 0xFD27
Data Memory 0x1220 = 0xFD27
MOV
W4, [W8-0x300]
; move W4 to [W8-0x300]
Before Instruction:
W4 = 0x3411
W8 = 0x2944
Data Memory 0x2644 = 0xCB98
After Instruction:
W4 = 0x3411
W8 = 0x2944
Data Memory 0x2644 = 0x3411
DS70157E-page 56
The Addressing modes presented in Table 4-2 demonstrate the Indirect Addressing mode
capability of the 16-bit MCU and DSC devices. Due to operation encoding and functional
considerations, not every instruction which supports indirect addressing supports all modes
shown in Table 4-2. The majority of instructions which use indirect addressing support the No
Modify, Pre-Increment, Pre-Decrement, Post-Increment and Post-Decrement Addressing
modes. The MOV instructions, and several accumulator-based DSP instructions (dsPIC30F,
dsPIC33F, and dsPIC33E devices only), are also capable of using the Register Offset
Addressing mode.
Note:
Instructions which use register indirect addressing use the operand symbols Wd
and Ws in the summary tables of Section 3. Instruction Set Overview.
4.1.3.2
A special class of Indirect Addressing modes is utilized by the DSP MAC instructions. As is
described later in 4.14 DSP MAC Instructions (dsPIC30F, dsPIC33F, and dsPIC33E
Devices), the DSP MAC class of instructions are capable of performing two fetches from
memory using effective addressing. Since DSP algorithms frequently demand a broader range
of address updates, the Addressing modes offered by the DSP MAC instructions provide greater
range in the size of the effective address update which may be made. Table 4-3 shows that both
X and Y prefetches support Post-Increment and Post-Decrement Addressing modes, with
updates of 2, 4 and 6 bytes. Since DSP instructions only execute in Word mode, no provisions
are made for odd sized EA updates.
Table 4-3:
X Memory
Y Memory
EA = [Wx]
EA = [Wy]
EA = [Wx] + = 2
EA = [Wy] + = 2
EA = [Wx] + = 4
EA = [Wy] + = 4
EA = [Wx] + = 6
EA = [Wy] + = 6
EA = [Wx] = 2
EA = [Wy] = 2
EA = [Wx] = 4
EA = [Wy] = 4
EA = [Wx] = 6
EA = [Wy] = 6
EA = [W9 + W12]
EA = [W11 + W12]
4.1.3.3
The 16-bit DSC architecture provides support for two special Register Indirect Addressing
modes, which are commonly used to implement DSP algorithms. Modulo (or circular) addressing
provides an automated means to support circular data buffers in X and/or Y memory. Modulo
buffers remove the need for software to perform address boundary checks, which can improve
the performance of certain algorithms. Similarly, bit-reversed addressing allows one to access
the elements of a buffer in a nonlinear fashion. This Addressing mode simplifies data re-ordering
for radix-2 FFT algorithms and provides a significant reduction in FFT processing time.
Both of these Addressing modes are powerful features of the dsPIC30F, dsPIC33F, and
dsPIC33E architectures, which can be exploited by any instruction that uses indirect addressing.
Refer to the specific device family reference manual for details on using modulo and bit-reversed
addressing.
DS70157E-page 57
Instruction Set
Details
Note:
Immediate Addressing
Table 4-4:
The 6-bit (#Slit6) operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E
devices.
Immediate Operands in the Instruction Set
Operand
Instruction Usage
#lit1
PWRSAV
#bit4
#lit4
ASR, LSR, SL
#Slit4
#lit5
#Slit6(1)
SFTAC
#lit8
#lit10
ADD, ADDC, AND, CP, CPB, IOR, RETLW, SUB, SUBB, XOR
#Slit10
MOV
#lit14
#lit15
DO(3), REPEAT(4)
#lit16
MOV
Note 1:
2:
3:
4:
5:
The syntax for immediate addressing requires that the number sign (#) must immediately
precede the constant operand value. The # symbol indicates to the assembler that the quantity
is a constant. If an out-of-range constant is used with an instruction, the assembler will generate
an error. Several examples of immediate addressing are shown in Example 4-7.
DS70157E-page 58
Immediate Addressing
PWRSAV #1
ADD.B
#0x10, W0
Before Instruction:
W0 = 0x12A9
After Instruction:
W0 = 0x12B9
XOR
Before Instruction:
W0 = 0xFFFF
W1 = 0x0890
Data Memory 0x0890 = 0x0032
After Instruction:
W0 = 0xFFFF
W1 = 0x0892
Data Memory 0x0890 = 0xFFFE
4.1.5
The Data Addressing modes of the PIC24F, PIC24H, and PIC24E families are summarized in
Figure 4-1.
Figure 4-1:
Direct
Indirect
No Modification
Pre-Increment
Pre-Decrement
Post-Increment
Literal Offset
Register Offset
The Data Addressing modes of the dsPIC30F, dsPIC33F, and dsPIC33E are summarized in
Figure 4-2.
DS70157E-page 59
Instruction Set
Details
Post-Decrement
No Modification
Pre-Increment
Pre-Decrement
Post-Increment
Post-Decrement
Literal Offset
Register Offset
Direct
DSP MAC
No Modification
Post-Increment (2, 4 and 6)
Indirect
DS70157E-page 60
Table 4-5:
Condition/Instruction
PC Modification
Sequential Execution
PC = PC + 2
None
BRA Expr(1)
(Branch Unconditionally)
PC = PC + 2*Slit16
None
PC = PC + 2 (condition false)
PC = PC + 2 * Slit16 (condition true)
None
CALL Expr(1)
(Call Subroutine)
PC = lit23
CALL Wn
(Call Subroutine Indirect)
PC = Wn
CALL.L Wn(5)
(Call Indirect Subroutine Long)
PC = {Wn+1:Wn}
None
GOTO Expr(1)
(Unconditional Jump)
PC = lit23
None
GOTO Wn
(Unconditional Indirect Jump)
PC = Wn
None
GOTO.L
(Unconditional Indirect Long Jump)
PC = {Wn+1:Wn}
None
RCALL Expr(1)
(Relative Call)
PC = PC + 2 * Slit16
RCALL Wn
(Computed Relative Call)
PC = PC + 2 * Wn
Exception Handling
None
PC = DOEND address(4)
(DO Looping)
None
Wn(5)
2:
3:
4:
5:
For BRA, CALL and GOTO, the Expr may be a label, absolute address, or expression, which is resolved by
the linker to a 16-bit or 23-bit value (Slit16 or lit23). See Section 5. Instruction Descriptions for details.
After CALL or RCALL is executed, RETURN or RETLW will POP the Top-of-Stack (TOS) back into the PC.
After an exception is processed, RETFIE will POP the Top-of-Stack (TOS) back into the PC.
This condition/instruction is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This condition instruction is only available in dsPIC33E and PIC24E devices.
DS70157E-page 61
Instruction Set
Details
Note 1:
INSTRUCTION STALLS
In order to maximize the data space EA calculation and operand fetch time, the X data space
read and write accesses are partially pipelined. A consequence of this pipelining is that address
register data dependencies may arise between successive read and write operations using
common registers.
Read After Write (RAW) dependencies occur across instruction boundaries and are detected by
the hardware. An example of a RAW dependency would be a write operation that modifies W5,
followed by a read operation that uses W5 as an Address Pointer. The contents of W5 will not be
valid for the read operation until the earlier write completes. This problem is resolved by stalling
the instruction execution for one instruction cycle, which allows the write to complete before the
next read is started.
4.3.1
During the instruction pre-decode, the core determines if any address register dependency is
imminent across an instruction boundary. The stall detection logic compares the W register
(if any) used for the destination EA of the instruction currently being executed with the W register
to be used by the source EA (if any) of the prefetched instruction. When a match between the
destination and source registers is identified, a set of rules are applied to decide whether or not
to stall the instruction by one cycle. Table 4-6 lists various RAW conditions which cause an
instruction execution stall.
Table 4-6:
Destination
Address Mode Using Wn
Examples(2)
(Wn = W2)
Stall
Required?
Direct
Direct
No Stall
ADD.W
MOV.W
W0, W1, W2
W2, W3
Indirect
Direct
No Stall
ADD.W
MOV.W
Indirect
Indirect
No Stall
ADD.W
MOV.W
Indirect
No Stall
ADD.W
MOV.W
No Stall
ADD.W
MOV.W
Direct
Indirect
Stall(1)
ADD.W
MOV.W
W0, W1, W2
[W2], W3
Direct
Stall(1)
ADD.W
MOV.W
W0, W1, W2
[W2++], W3
Indirect
Indirect
Stall(1)
ADD.W
MOV.W
Indirect
Stall(1)
Stall(1)
ADD.W
MOV.W
Stall(1)
ADD.W
MOV.W
Note 1:
2:
When stalls are detected, one cycle is added to the instruction execution time.
For these examples, the contents of W2 = the mapped address of W2 (0x0004).
DS70157E-page 62
In order to maintain deterministic operation, instruction stalls are allowed to happen, even if they
occur immediately prior to exception processing.
4.3.3
CALL and RCALL write to the stack using W15 and may, therefore, be subject to an instruction
stall if the source read of the subsequent instruction uses W15.
GOTO, RETFIE and RETURN instructions are never subject to an instruction stall because they
do not perform write operations to the working registers.
4.3.4
Instructions operating in a DO or REPEAT loop are subject to instruction stalls, just like any other
instruction. Stalls may occur on loop entry, loop exit and also during loop processing.
Note:
4.3.5
Instructions operating in PSV address space are subject to instruction stalls, just like any other
instruction. Should a data dependency be detected in the instruction immediately following the
PSV data access, the second cycle of the instruction will initiate a stall. Should a data
dependency be detected in the instruction immediately before the PSV data access, the last
cycle of the previous instruction will initiate a stall.
Note:
Refer to the specific device family reference manual for more detailed information
about RAW instruction stalls.
4
Instruction Set
Details
DS70157E-page 63
BYTE OPERATIONS
Since the data memory is byte addressable, most of the base instructions may operate in either
Byte mode or Word mode. When these instructions operate in Byte mode, the following rules
apply:
All direct working register references use the Least Significant Byte of the 16-bit working
register and leave the Most Significant Byte (MSB) unchanged
All indirect working register references use the data byte specified by the 16-bit address
stored in the working register
All file register references use the data byte specified by the byte address
The STATUS Register is updated to reflect the result of the byte operation
It should be noted that data addresses are always represented as byte addresses. Additionally,
the native data format is little-endian, which means that words are stored with the Least
Significant Byte at the lower address, and the Most Significant Byte at the adjacent, higher
address (as shown in Figure 4-3). Example 4-8 shows sample byte move operations and
Example 4-9 shows sample byte math operations.
Note:
Example 4-8:
MOV.B
W0
W0
Before Instruction:
W0 = 0x5555
After Instruction:
W0 = 0x5530
MOV.B
0x1000, W0
Before Instruction:
W0 = 0x5555
Data Memory 0x1000 = 0x1234
After Instruction:
W0 = 0x5534
Data Memory 0x1000 = 0x1234
MOV.B
W0, 0x1001
Before Instruction:
W0 = 0x1234
Data Memory 0x1000 = 0x5555
After Instruction:
W0 = 0x1234
Data Memory 0x1000 = 0x3455
MOV.B
W0, [W1++]
Before Instruction:
W0 = 0x1234
W1 = 0x1001
Data Memory 0x1000 = 0x5555
After Instruction:
W0 = 0x1234
W1 = 0x1002
Data Memory 0x1000 = 0x3455
DS70157E-page 64
Before Instruction:
W6 = 0x1001
Data Memory 0x1000 = 0x5555
After Instruction:
W6 = 0x1000
Data Memory 0x1000 = 0x0055
SUB.B
W0, #0x10, W1
Before Instruction:
W0 = 0x1234
W1 = 0xFFFF
After Instruction:
W0 = 0x1234
W1 = 0xFF24
ADD.B
Before Instruction:
W0 =
W1 =
W2 =
Data
0x1234
0x5678
0x1000
Memory 0x1000 = 0x5555
After Instruction:
W0 =
W1 =
W2 =
Data
0x1234
0x5678
0x1001
Memory 0x1000 = 0x55AC
4
Instruction Set
Details
DS70157E-page 65
0x1001
b0
0x1000
0x1003
b1
0x1005
b3
b2
0x1004
0x1007
b5
b4
0x1006
0x1009
b7
b6
0x1008
b8
0x100A
0x100B
0x1002
Legend:
b0 byte stored at 0x1000
b1 byte stored at 0x1003
b3:b2 word stored at 0x1005:1004 (b2 is LSB)
b7:b4 double word stored at 0x1009:0x1006 (b4 is LSB)
b8 byte stored at 0x100A
Note:
Instructions that operate in Word mode are not required to use an instruction
extension. However, they may be specified with an optional .w or .W extension,
if desired. For example, the following instructions are valid forms of a word clear
operation:
CLR
CLR.w
CLR.W
DS70157E-page 66
W0
W0
W0
#0x30, W0
Before Instruction:
W0 = 0x5555
After Instruction:
W0 = 0x0030
MOV
0x1000, W0
Before Instruction:
W0 = 0x5555
Data Memory 0x1000 = 0x1234
After Instruction:
W0 = 0x1234
Data Memory 0x1000 = 0x1234
MOV
[W0], [W1++]
Before Instruction:
W0 =
W1 =
Data
Data
0x1234
0x1000
Memory 0x1000 = 0x5555
Memory 0x1234 = 0xAAAA
After Instruction:
W0 =
W1 =
Data
Data
0x1234
0x1002
Memory 0x1000 = 0xAAAA
Memory 0x1234 = 0xAAAA
4
Instruction Set
Details
DS70157E-page 67
0x1001, W0
Before Instruction:
W0 = 0x5555
Data Memory 0x1000 = 0x1234
Data Memory 0x1002 = 0x5678
After Instruction:
W0 = 0x1234
Data Memory 0x1000 = 0x1234
Data Memory 0x1002 = 0x5678
W0, 0x1001
Before Instruction:
W0 = 0x1234
Data Memory 0x1000 = 0x5555
Data Memory 0x1002 = 0x6666
After Instruction:
W0 = 0x1234
Data Memory 0x1000 = 0x5555
Data Memory 0x1002 = 0x6666
[W0], [W1++]
Before Instruction:
W0 =
W1 =
Data
Data
Data
0x1235
0x1000
Memory 0x1000 = 0x1234
Memory 0x1234 = 0xAAAA
Memory 0x1236 = 0xBBBB
After Instruction:
W0 =
W1 =
Data
Data
Data
0x1235
0x1002
Memory 0x1000 = 0xAAAA
Memory 0x1234 = 0xAAAA
Memory 0x1236 = 0xBBBB
DS70157E-page 68
Literal Value
Word Mode
kk kkkk kkkk
Byte Mode
kkkk kkkk
00 0000 0000
0000 0000
00 0000 0001
0000 0001
00 0000 0010
0000 0010
127
00 0111 1111
0111 1111
128
00 1000 0000
1000 0000
255
00 1111 1111
1111 1111
256
01 0000 0000
N/A
512
10 0000 0000
N/A
1023
11 1111 1111
N/A
Example 4-12:
ADD.B
ADD.B
ADD.B
ADD.B
ADD.B
ADD.B
ADD.B
Note:
#0x80, W0
#0x380, W0
#0xFF, W0
#0x3FF, W0
#0xF, W0
#0x7F, W0
#0x100, W0
;
;
;
;
;
;
;
Using a literal value greater than 127 in Byte mode is functionally identical to using
the equivalent negative twos complement value, since the Most Significant bit of the
byte is set. When operating in Byte mode, the Assembler will accept either a positive
or negative literal value (i.e., #-10).
4
Instruction Set
Details
DS70157E-page 69
The 16-bit MCU and DSC devices feature a software stack which facilitates function calls and
exception handling. W15 is the default Stack Pointer (SP) and after any Reset, it is initialized to
0x0800 (0x1000 for PIC24E and dsPIC33E devices). This ensures that the SP will point to valid
RAM and permits stack availability for exceptions, which may occur before the SP is set by the
user software. The user may reprogram the SP during initialization to any location within data
space.
The SP always points to the first available free word (Top-of-Stack) and fills the software stack,
working from lower addresses towards higher addresses. It pre-decrements for a stack POP
(read) and post-increments for a stack PUSH (write).
The software stack is manipulated using the PUSH and POP instructions. The PUSH and POP
instructions are the equivalent of a MOV instruction, with W15 used as the destination pointer. For
example, the contents of W0 can be PUSHed onto the Top-of-Stack (TOS) by:
PUSH W0
During any CALL instruction, the PC is PUSHed onto the stack, such that when the subroutine
completes execution, program flow may resume from the correct location. When the PC is
PUSHed onto the stack, PC<15:0> is PUSHed onto the first available stack word, then
PC<22:16> is PUSHed. When PC<22:16> is PUSHed, the Most Significant 7 bits of the PC are
zero-extended before the PUSH is made, as shown in Figure 4-4. During exception processing,
the Most Significant 7 bits of the PC are concatenated with the lower byte of the STATUS
register (SRL) and IPL<3>, CORCON<3>. This allows the primary STATUS register contents
and CPU Interrupt Priority Level to be automatically preserved during interrupts.
Note:
Figure 4-4:
0x0000
15
PC<15:0>
0x0
PC<22:16>
Top-of-Stack
0xFFFE
Note:
DS70157E-page 70
For exceptions, the upper nine bits of the second PUSHed word contains
the SRL and IPL<3>.
Figure 4-5 through Figure 4-8 show how the software stack is modified for the code snippet
shown in Example 4-13. Figure 4-5 shows the software stack before the first PUSH has executed.
Note that the SP has the initialized value of 0x0800. Furthermore, the example loads 0x5A5A
and 0x3636 to W0 and W1, respectively. The stack is PUSHed for the first time in Figure 4-6 and
the value contained in W0 is copied to TOS. W15 is automatically updated to point to the next
available stack location, and the new TOS is 0x0802. In Figure 4-7, the contents of W1 are
PUSHed onto the stack, and the new TOS becomes 0x0804. In Figure 4-8, the stack is POPped,
which copies the last PUSHed value (W1) to W3. The SP is decremented during the POP
operation, and at the end of the example, the final TOS is 0x0802.
Example 4-13:
MOV
MOV
PUSH
PUSH
POP
Figure 4-5:
#0x5A5A, W0
#0x3636, W1
W0
W1
W3
;
;
;
;
;
Load W0
Load W1
Push W0
Push W1
Pop TOS
with 0x5A5A
with 0x3636
to TOS (see Figure 4-5)
to TOS (see Figure 4-7)
to W3 (see Figure 4-8)
<TOS>
W15 (SP)
0xFFFE
W0 = 0x5A5A
W1 = 0x3636
W15 = 0x0800
Figure 4-6:
5A5A
<TOS>
W15 (SP)
Instruction Set
Details
0xFFFE
W0 = 0x5A5A
W1 = 0x3636
W15 = 0x0802
DS70157E-page 71
5A5A
3636
<TOS>
W15 (SP)
0xFFFE
W0 = 0x5A5A
W1 = 0x3636
W15 = 0x0804
Figure 4-8:
5A5A
<TOS>
W15 (SP)
0xFFFE
W0 = 0x5A5A
W1 = 0x3636
W3 = 0x3636
W15 = 0x0802
Note: The contents of 0x802, the new TOS, remain unchanged (0x3636).
4.7.2
A Stack Frame is a user-defined section of memory residing in the software stack. It is used to
allocate memory for temporary variables which a function uses, and one Stack Frame may be
created for each function. W14 is the default Stack Frame Pointer (FP) and it is initialized to
0x0000 on any Reset. If the Stack Frame Pointer is not used, W14 may be used like any other
working register.
The link (LNK) and unlink (ULNK) instructions provide Stack Frame functionality. The LNK
instruction is used to create a Stack Frame. It is used during a call sequence to adjust the SP,
such that the stack may be used to store temporary variables utilized by the called function. After
the function completes execution, the ULNK instruction is used to remove the Stack Frame
created by the LNK instruction. The LNK and ULNK instructions must always be used together to
avoid stack overflow.
DS70157E-page 72
Figure 4-9 through Figure 4-11 show how a Stack Frame is created and removed for the code
snippet shown in Example 4-14. This example demonstrates how a Stack Frame operates and
is not indicative of the code generated by the compiler. Figure 4-9 shows the stack condition at
the beginning of the example, before any registers are PUSHed to the stack. Here, W15 points
to the first free stack location (TOS) and W14 points to a portion of stack
memory allocated for the routine that is currently executing.
Before calling the function COMPUTE, the parameters of the function (W0, W1 and W2) are
PUSHed on the stack. After the CALL COMPUTE instruction is executed, the PC changes to the
address of COMPUTE and the return address of the function TASKA is placed on the stack
(Figure 4-10). Function COMPUTE then uses the LNK #4 instruction to PUSH the calling
routines Frame Pointer value onto the stack and the new Frame Pointer will be set to point to the
current Stack Pointer. Then, the literal 4 is added to the Stack Pointer address in W15, which
reserves memory for two words of temporary data (Figure 4-11).
Inside the function COMPUTE, the FP is used to access the function parameters and temporary
(local) variables. [W14 + n] will access the temporary variables used by the routine and [W14 n]
is used to access the parameters. At the end of the function, the ULNK instruction is used to copy
the Frame Pointer address to the Stack Pointer and then POP the calling subroutines Frame
Pointer back to the W14 register. The ULNK instruction returns the stack back to the state shown
in Figure 4-10.
A RETURN instruction will return to the code that called the subroutine. The calling code is
responsible for removing the parameters from the stack. The RETURN and POP instructions
restore the stack to the state shown in Figure 4-9.
Example 4-14:
TASKA:
...
PUSH
PUSH
PUSH
CALL
POP
POP
POP
...
W0
W1
W2
COMPUTE
W2
W1
W0
;
;
;
;
;
;
;
Push parameter 1
Push parameter 2
Push parameter 3
Call COMPUTE function
Pop parameter 3
Pop parameter 2
Pop parameter 1
W14 (FP)
<TOS>
W15 (SP)
0xFFFE
DS70157E-page 73
4
Instruction Set
Details
COMPUTE:
LNK
#4
...
ULNK
RETURN
Figure 4-9:
W14 (FP)
W15 (SP)
0xFFFE
Figure 4-11:
W14 (FP)
W15 (SP)
0xFFFE
4.7.3
There is a stack limit register (SPLIM) associated with the Stack Pointer that is reset to 0x0000.
SPLIM is a 16-bit register, but SPLIM<0> is fixed to 0, because all stack operations must be
word-aligned.
The stack overflow check will not be enabled until a word write to SPLIM occurs, after which time
it can only be disabled by a device Reset. All effective addresses generated using W15 as a
source or destination are compared against the value in SPLIM. Should the effective address be
greater than the contents of SPLIM, then a stack error trap is generated.
If stack overflow checking has been enabled, a stack error trap will also occur if the W15 effective
address calculation wraps over the end of data space (0xFFFF).
Refer to the specific device family reference manual for more information on the stack error trap.
4.7.4
The stack is initialized to 0x0800 during Reset (0x1000 for PIC24E and dsPIC33E devices). A
stack error trap will be initiated should the Stack Pointer address ever be less than 0x0800
(0x1000 for PIC24E and dsPIC33E devices).
Note:
DS70157E-page 74
Locations in data space between 0x0000 and 0x07FF (0x0FFF for PIC24E and
dsPIC33E devices) are, in general, reserved for core and peripheral Special
Function Registers (SFR).
W15 is never subject to paging and is therefore restricted to address range 0x000000 to
0x00FFFF. However, the Stack Frame Pointer (W14) for any user software function is only
dedicated to that function when a stack frame addressed by W14 is active (i.e., after a LNK
instruction). Therefore, it is desirable to have the ability to dynamically switch W14 between use
as a general purpose W register, and use as a Stack Frame Pointer. The SFA Status
(CORCON<2>) bit achieves this function without additional S/W overhead.
When SFA is clear, W14 may be used with any page register. When SFA is set, W14 is not
subject to paging and is locked into the same address range as W15 (0x000000 to 0x00FFFF).
Operation of the SFA register lock is as follows:
The LNK instruction sets SFA (and creates a stack frame).
The ULNK instruction clears SFA (and deletes the stack frame).
The CALL, CALL.L, and RCALL instructions also stack the SFA bit (placing it in the LSb of
the stacked PC), and clear the SFA bit after the stacking operation is complete. The called
procedure is now free to either use W14 as a general purpose register, or create another
stack frame using the LNK instruction.
The RETURN, RETLW and RETFIE instructions all restore the SFA bit from its previously
stacked value.
The SFA bit is a read-only bit. It can only be set by execution of the LNK instruction, and cleared
by the ULNK, CALL, CALL.L, and RCALL instructions.
Note:
In dsPIC33E and PIC24E devices, the SFA bit is stacked instead of PC<0>.
4
Instruction Set
Details
DS70157E-page 75
Condition
Mnemonic(1)
Status Test
GE
(N&&OV) || (N&&OV)
GEU(2)
GT
(Z&&N&&OV) || (Z&&N&&OV)
GTU
C&&Z
LE
Z || (N&&OV) || (N&&OV)
LEU
C || Z
LT
(N&&OV) || (N&&OV)
LTU
Negative
(3)
NC
NN
Not Negative
NOV
Not Overflow
OV
NZ
Not Zero
OA(4)
Accumulator A overflow
OA
OB(4)
Accumulator B overflow
OB
OV
Overflow
OV
SA(4)
Accumulator A saturate
SA
SB(4)
Accumulator B saturate
SB
Zero
Note 1:
2:
3:
4:
Note:
DS70157E-page 76
Description
Z STATUS BIT
The Z Status bit is a special zero Status bit that is useful for extended precision arithmetic. The
Z bit functions like a normal Z flag for all instructions, except those that use the carry/borrow input
(ADDC, CPB, SUBB and SUBBR). For the ADDC, CPB, SUBB and SUBBR instructions, the Z bit
can only be cleared and never set. If the result of one of these instructions is non-zero, the Z bit
will be cleared and will remain cleared, regardless of the result of subsequent ADDC, CPB, SUBB
or SUBBR operations. This allows the Z bit to be used for performing a simple zero check on the
result of a series of extended precision operations.
A sequence of instructions working on multi-precision data (starting with an instruction with no
carry/borrow input), will automatically logically AND the successive results of the zero test. All
results must be zero for the Z flag to remain set at the end of the sequence of operations. If the
result of the ADDC, CPB, SUBB or SUBBR instruction is non-zero, the Z bit will be cleared and
remain cleared for all subsequent ADDC, CPB, SUBB or SUBBR instructions. Example 4-15
shows how the Z bit operates for a 32-bit addition. It shows how the Z bit is affected for a 32-bit
addition implemented with an ADD/ADDC instruction sequence. The first example generates a
zero result for only the most significant word, and the second example generates a zero result
for both the least significant word and most significant word.
Example 4-15:
Before 32-bit Addition (zero result for the most significant word):
W0
W1
W2
W3
W4
W5
SR
=
=
=
=
=
=
=
0x2342
0xFFF0
0x39AA
0x0010
0x0000
0x0000
0x0000
0x2342
0xFFF0
0x39AA
0x0010
0x5CEC
0x0000
0x0201 (DC,C=1)
Before 32-bit Addition (zero result for the least significant word and most significant word):
W0
W1
W2
W3
W4
W5
SR
=
=
=
=
=
=
=
0xB76E
0xFB7B
0x4892
0x0484
0x0000
0x0000
0x0000
=
=
=
=
=
=
=
0xB76E
0xFB7B
0x4892
0x0485
0x0000
0x0000
0x0103 (DC,Z,C=1)
DS70157E-page 77
Instruction Set
Details
W0
W1
W2
W3
W4
W5
SR
Register
Special Assignment
W0
W1
Divide Remainder
W2
W3
W4
MAC Operand(1)
W5
MAC Operand(1)
W6
MAC Operand(1)
W7
MAC Operand(1)
W8
W9
W10
W11
W12
W13
W14
Frame Pointer
W15
Stack Pointer
Note 1:
4.10.1
To assist instruction encoding and maintain uniformity among the DSP class of instructions,
some working registers have pre-assigned functionality. For all DSP instructions which have
prefetch ability, the following 10 register assignments must be adhered to:
These restrictions only apply to the DSP MAC class of instructions, which utilize working
registers and have prefetch ability (described in Section 4.15 DSP Accumulator Instructions
(dsPIC30F, dsPIC33F, and dsPIC33E Devices)). These instructions are CLR, ED, EDAC, MAC,
MOVSAC, MPY, MPY.N and MSC.
The DSP Accumulator class of instructions (described in Section 4.15 DSP Accumulator
Instructions (dsPIC30F, dsPIC33F, and dsPIC33E Devices)) are not required to follow the
working register assignments in Table 4-9 and may freely use any working register when required.
DS70157E-page 78
To accommodate software stack usage, W14 is the implied Frame Pointer (used by the LNK and
ULNK instructions) and W15 is the implied Stack Pointer (used by the CALL, LNK, POP, PUSH,
RCALL, RETFIE, RETLW, RETURN, TRAP and ULNK instructions). Even though W14 and
W15 have this implied usage, they may still be used as generic operands in any instruction, with
the exceptions outlined in Section 4.10.1 Implied DSP Operands (dsPIC30F, dsPIC33F, and
dsPIC33E Devices). If W14 and W15 must be used for other purposes (it is strongly advised
that they remain reserved for the Frame and Stack Pointer), extreme care must be taken such
that the run-time environment is not corrupted.
4.10.3
4.10.3.1
To ease the migration path for users of the Microchip 8-bit PIC MCU families, the 16-bit MCU and
DSC devices have matched the functionality of the PIC MCU instruction sets as closely as
possible. One major difference between the 16-bit MCU and DSC and the 8-bit PIC MCU
processors is the number of working registers provided. The 8-bit PIC MCU families only provide
one 8-bit working register, while the 16-bit MCU and DSC families provide sixteen, 16-bit working
registers. To accommodate for the one working register of the 8-bit PIC MCU, the 16-bit MCU
and DSC device instruction set has designated one working register to be the default working
register for all legacy file register instructions. The default working register is set to W0, and it is
used by all instructions which use file register addressing.
Additionally, the syntax used by the 16-bit MCU and DSC device assembler to specify the default
working register is similar to that used by the 8-bit PIC MCU assembler. As shown in the detailed
instruction descriptions in Section 5. Instruction Descriptions, WREG must be used to
specify the default working register. Example 4-16 shows several instructions which use WREG.
Example 4-16:
ADD
ASR
CLR.B
DEC
MOV
SETM
XOR
4.10.3.2
RAM100
RAM100, WREG
WREG
RAM100, WREG
WREG, RAM100
WREG
RAM100
;
;
;
;
;
;
;
Despite this architectural difference, the 16-bit MCU and DSC devices still support the legacy file
register multiply instruction (MULWF) with the MUL{.B} f instruction (described on page 306).
Supporting the legacy MULWF instruction has been accomplished by mapping the
PRODH:PRODL registers to the working register pair W3:W2. This means that when MUL{.B}
f is executed in Word mode, the multiply generates a 32-bit product which is stored in W3:W2,
where W3 has the most significant word of the product and W2 has the least significant word of
the product. When MUL{.B} f is executed in Byte mode, the 16-bit product is stored in W2,
and W3 is unaffected. Examples of this instruction are shown in Example 4-17.
DS70157E-page 79
4
Instruction Set
Details
Another significant difference between the Microchip 8-bit PIC MCU and 16-bit MCU and DSC
architectures is the multiplier. Some PIC MCU families support an 8-bit x 8-bit multiplier, which
places the multiply product in the PRODH:PRODL register pair. The 16-bit MCU and DSC
devices have a 17-bit x 17-bit multiplier, which may place the result into any two successive
working registers (starting with an even register), or an accumulator.
0x100
Before Instruction:
W0 (WREG) = 0x7705
W2 = 0x1235
W3 = 0x1000
Data Memory 0x0100 = 0x1255
After Instruction:
W0 (WREG) = 0x7705
W2 = 0x01A9
W3 = 0x1000
Data Memory 0x0100 = 0x1255
MUL
0x100
Before Instruction:
W0 (WREG) = 0x7705
W2 = 0x1235
W3 = 0x1000
Data Memory 0x0100 = 0x1255
After Instruction:
W0 (WREG) = 0x7705
W2 = 0xDEA9
W3 = 0x0885
Data Memory 0x0100 = 0x1255
4.10.3.3
The MOV{.B} f {,WREG} instruction (described on page 5-145) and MOV{.B} WREG, f
instruction (described on page 5-146) allow for byte or word data to be moved between file
register memory and the WREG (working register W0). These instructions provide equivalent
functionality to the legacy Microchip PIC MCU MOVF and MOVWF instructions.
The MOV{.B} f {,WREG} and MOV{.B} WREG, f instructions are the only MOV instructions
which support moves of byte data to and from file register memory. Example 4-18 shows several
MOV instruction examples using the WREG.
Note:
When moving word data between file register memory and the working register
array, the MOV Wns, f and MOV f, Wnd instructions allow any working register
(W0:W15) to be used as the source or destination register, not just WREG.
Example 4-18:
MOV.B
MOV
MOV.B
MOV
DS70157E-page 80
0x1001, WREG
0x1000, WREG
WREG, TBLPAG
WREG, 0x804
;
;
;
;
move
move
move
move
the
the
the
the
byte
word
byte
word
stored
stored
stored
stored
at
at
at
at
location 0x1001 to W0
location 0x1000 to W0
W0 to the TBLPAG register
W0 to location 0x804
The dsPIC30F, dsPIC33F, and dsPIC33E devices support both integer and fractional data types.
Integer data is inherently represented as a signed twos complement value, where the Most
Significant bit is defined as a sign bit. Generally speaking, the range of an N-bit twos complement
integer is -2N-1 to 2N-1 1. For a 16-bit integer, the data range is -32768 (0x8000) to 32767
(0x7FFF), including 0. For a 32-bit integer, the data range is -2,147,483,648 (0x8000 0000) to
2,147,483,647 (0x7FFF FFFF).
Fractional data is represented as a twos complement number, where the Most Significant bit is
defined as a sign bit, and the radix point is implied to lie just after the sign bit. This format is
commonly referred to as 1.15 (or Q15) format, where 1 is the number of bits used to represent
the integer portion of the number, and 15 is the number of bits used to represent the fractional
portion. The range of an N-bit twos complement fraction with this implied radix point is -1.0 to
(1 21-N). For a 16-bit fraction, the 1.15 data range is -1.0 (0x8000) to 0.999969482 (0x7FFF),
including 0.0 and it has a precision of 3.05176x10-5. In Normal Saturation mode, the 32-bit
accumulators use a 1.31 format, which enhances the precision to 4.6566x10-10.
Super Saturation mode expands the dynamic range of the accumulators by using the 8 bits of
the Upper Accumulator register (ACCxU) as guard bits. Guard bits are used if the value stored
in the accumulator overflows beyond the 32nd bit, and they are useful for implementing DSP
algorithms. This mode is enabled when the ACCSAT bit (CORCON<4>), is set to 1 and it
expands the accumulators to 40 bits. The accumulators then support an integer range of
-5.498x1011 (0x80 0000 0000) to 5.498x1011 (0x7F FFFF FFFF). In Fractional mode, the guard
bits of the accumulator do not modify the location of the radix point and the 40-bit accumulators
use a 9.31 fractional format. Note that all fractional operation results are stored in the 40-bit
Accumulator, justified with a 1.31 radix point. As in Integer mode, the guard bits merely increase
the dynamic range of the accumulator. 9.31 fractions have a range of -256.0 (0x80 0000 0000)
to (256.0 4.65661x10-10) (0x7F FFFF FFFF). Table 4-10 identifies the range and precision of
integers and fractions on the dsPIC30F/33F/33E devices for 16-bit, 32-bit and 40-bit registers.
Table 4-10:
Register Size
16-bit
Integer Range
-32768 to 32767
Fraction Range
-1.0 to (1.0 2-15)
-31
32-bit
-2,147,483,648 to
2,147,483,647
-1.0 to (1.0 2
40-bit
-549,755,813,888 to
549,755,813,887
Fraction Resolution
3.052 x 10-5
4.657 x 10-10
4.657 x 10-10
DS70157E-page 81
4
Instruction Set
Details
It should be noted that, with the exception of DSP multiplies, the ALU operates identically on
integer and fractional data. Namely, an addition of two integers will yield the same result (binary
number) as the addition of two fractional numbers. The only difference is how the result is
interpreted by the user. However, multiplies performed by DSP operations are different. In these
instructions, data format selection is made by the IF bit, CORCON<0>, and it must be set
accordingly (0 for Fractional mode, 1 for Integer mode). This is required because of the implied
radix point used by dsPIC30F/33F/33E fractional numbers. In Integer mode, multiplying two
16-bit integers produces a 32-bit integer result. However, multiplying two 1.15 values generates
a 2.30 result. Since the dsPIC30F, dsPIC33F, and dsPIC33E devices use a 1.31 format for the
accumulators, a DSP multiply in Fractional mode also includes a left shift of one bit to keep the
radix point properly aligned. This feature reduces the resolution of the DSP multiplier to 2-30, but
has no other effect on the computation (e.g., 0.5 x 0.5 = 0.25).
Having a working knowledge of how integer and fractional data are represented on the
dsPIC30F, dsPIC33F, and dsPIC33E is fundamental to working with the device. Both integer and
fractional data treat the Most Significant bit as a sign bit, and the binary exponent decreases by
one as the bit position advances toward the Least Significant bit. The binary exponent for an N-bit
integer starts at (N-1) for the Most Significant bit, and ends at 0 for the Least Significant bit. For
an N-bit fraction, the binary exponent starts at 0 for the Most Significant bit, and ends at (1-N)
for the Least Significant bit (as shown in Figure 4-12 for a positive value and in Figure 4-13 for a
negative value).
Conversion between integer and fractional representations can be performed using simple
division and multiplication. To go from an N-bit integer to a fraction, divide the integer value by
2N-1. Likewise, to convert an N-bit fraction to an integer, multiply the fractional value by 2N-1.
Figure 4-12:
Integer:
0
-215 214
213
212 . . . . . .
20
-20 . 2-1
2-2
2-3 . . . . . .
2-15
Integer:
1
-215 214
213
212 . . . . . .
20
-20 . 2-1
2-2
2-3 . . . . . .
2-15
DS70157E-page 82
A)
ACCxU
39
32 31 30
ACCxL
ACCxH
16
15
B)
C)
Instruction Set
Details
D)
A)
B)
C)
D)
DS70157E-page 83
DS70157E-page 84
For convenience, ACCAU and ACCBU are sign-extended to 16 bits. This provides
the flexibility to access these registers using either Byte or Word mode (when file
register or indirect addressing is used).
Instruction
Description
Accumulator WB?
CLR
Clear accumulator
Yes
ED
No
EDAC
Euclidean distance
No
MAC
Yes
MAC
No
MOVSAC
Yes
MPY
Multiply to accumulator
No
MPY
Square to accumulator
No
MPY.N
No
MSC
Yes
4.14.1
MAC Prefetches
Prefetches (or data reads) are made using the effective address stored in the working register.
The two prefetches from data memory must be specified using the working register assignments
shown in Table 4-9. One read must occur from the X data bus using W8 or W9, and one read
must occur from the Y data bus using W10 or W11. The allowed destination registers for both
prefetches are W4-W7.
4.14.2
After the MAC prefetches are made, the effective address stored in each prefetch working register
may be modified. This feature enables efficient single-cycle processing for data stored
sequentially in X and Y memory. Since all DSP instructions execute in Word mode, only even
numbered updates may be made to the effective address stored in the working register.
Allowable address modifications to each prefetch register are -6, -4, -2, 0 (no update), +2, +4 and
+6. This means that effective address updates may be made up to 3 words in either direction.
When the Register Offset Addressing mode is used, no update is made to the base prefetch
register (W9 or W11), or the offset register (W12).
DS70157E-page 85
4
Instruction Set
Details
As shown in Table 4-3, one special Addressing mode exists for the MAC class of instructions. This
mode is the Register Offset Addressing mode and utilizes W12. In this mode, the prefetch is
made using the effective address of the specified working register, plus the 16-bit signed value
stored in W12. Register Offset Addressing may only be used in the X space with W9, and in the
Y-space with W11.
MAC Operations
The mathematical operations performed by the MAC class of DSP instructions center around
multiplying the contents of two working registers and either adding or storing the result to either
Accumulator A or Accumulator B. This is the operation of the MAC, MPY, MPY.N and MSC
instructions. Table 4-9 shows that W4-W7 must be used for data source operands in the MAC
class of instructions. W4-W7 may be combined in any fashion, and when the same working
register is specified for both operands, a square or square and accumulate operation is
performed.
For the ED and EDAC instructions, the same multiplicand operand must be specified by the
instruction, because this is the definition of the Euclidean Distance operation. Another unique
feature about this instruction is that the values prefetched from X and Y memory are not actually
stored in W4-W7. Instead, only the difference of the prefetched data words is stored in W4-W7.
The two remaining MAC class instructions, CLR and MOVSAC, are useful for initiating or completing
a series of MAC or EDAC instructions and do not use the multiplier. CLR has the ability to clear
Accumulator A or B, prefetch two values from data memory and store the contents of the other
accumulator. Similarly, MOVSAC has the ability to prefetch two values from data memory and store
the contents of either accumulator.
4.14.4
The write back ability of the MAC class of DSP instructions facilitates efficient processing of
algorithms. This feature allows one mathematical operation to be performed with one
accumulator, and the rounded contents of the other accumulator to be stored in the same cycle.
As indicated in Table 4-9, register W13 is assigned for performing the write back, and two
Addressing modes are supported: Direct and Indirect with Post-Increment.
The CLR, MOVSAC and MSC instructions support accumulator Write Back, while the ED, EDAC,
MPY and MPY.N instructions do not support accumulator Write Back. The MAC instruction, which
multiplies two working registers which are not the same, also supports accumulator Write Back.
However, the square and accumulate MAC instruction does not support accumulator Write Back
(see Table 4-11).
4.14.5
MAC Syntax
The syntax of the MAC class of instructions can have several formats, which depend on the
instruction type and the operation it is performing, with respect to prefetches and accumulator
Write Back. With the exception of the CLR and MOVSAC instructions, all MAC class instructions
must specify a target accumulator along with two multiplicands, as shown in Example 4-19.
Example 4-19:
DS70157E-page 86
ACCB=ACCB+W5*W5
Y([W11+W12])W5
; MAC with X/Y prefetch
MAC W6*W7, B, [W9], W6,
[W10]+=4, W7
ACCB=ACCB+W6*W7
X([W9])W6
Y([W10]+=4)W7
DS70157E-page 87
Instruction Set
Details
If an accumulator Write Back is used in the instruction, it is specified last. The Write Back must
use the W13 register, and allowable forms for the Write Back are W13 for direct addressing and
[W13] + = 2 for indirect addressing with post-increment. By definition, the accumulator not used
in the mathematical operation is stored, so the Write Back accumulator is not specified in the
instruction. Legal forms of accumulator Write Back (WB) are shown in Example 4-21.
W13
0ACCA
ACCBW13
[W13]+=2
ACCA=ACCA+W4*W5
ACCB [W13]+=2
[W10]+=2, W4,
W13
ACCB=ACCB+W4*W5
Y([W10]+=2)W4
ACCA W13
Putting it all together, an MSC instruction which performs two prefetches and a write back is
shown in Example 4-22.
Example 4-22:
DS70157E-page 88
Accumulator WB?
ADD
Add accumulators
No
ADD
No
LAC
Load accumulator
No
NEG
Negate accumulator
No
SAC
Store accumulator
No
SAC.R
No
SFTAC
No
SFTAC
No
SUB
Subtract accumulators
No
4
Instruction Set
Details
DS70157E-page 89
Scaling Examples
Word Value
Exponent
0x0001
14
0x4000
0x0002
13
0x4000
0x0004
12
0x4000
0x0100
0x4000
0x01FF
0x7FC0
0x0806
0x4030
0x2007
0x400E
0x4800
0x4800
0x7000
0x7000
0x8000
0x8000
0x900A
0x900A
0xE001
0x8004
0xFF07
0x8380
Note:
For the word values 0x0000 and 0xFFFF, the FBCL instruction returns -15.
As a practical example, assume that block processing is performed on a sequence of data with
very low dynamic range stored in 1.15 fractional format. To minimize quantization errors, the data
may be scaled up to prevent any quantization loss which may occur as it is processed. The FBCL
instruction can be executed on the sample with the largest magnitude to determine the optimal
scaling value for processing the data. Note that scaling the data up is performed by left shifting
the data. This is demonstrated with the code snippet below.
DS70157E-page 90
4
Instruction Set
Details
DS70157E-page 91
DS70157E-page 92
; W5 points to ACCAH
; if overflow we right shift
; extract exponent for left shift
; branch to the shift
; extract exponent for right shift
; adjust the sign for right shift
; shift ACCA to normalize
Instruction Symbols......................................................................................................... 94
Instruction Encoding Field Descriptors Introduction........................................................ 94
Instruction Description Example ..................................................................................... 99
Instruction Descriptions................................................................................................. 100
5
Instruction
Descriptions
DS70157E-page 93
Instruction Symbols
All the symbols used in 5.4 Instruction Descriptions are listed in Table 1-2.
5.2
Description
A(1)
aa(1)
B
bbbb
D
dddd
f ffff ffff ffff
fff ffff ffff ffff
ffff ffff ffff ffff
ggg
hhh
iiii(1)
jjjj(1)
k
kkkk
kk kkkk
kkkk kkkk
kk kkkk kkkk
kk kkkk kkkk kkkk
kkkk kkkk kkkk kkkk
mm
mmm
nnnn nnnn nnnn nnn0
nnn nnnn
nnnn nnnn nnnn nnnn
ppp
qqq
rrrr
ssss
tttt
vvvv
W
DS70157E-page 94
ppp
Source Operand
000
Register Direct
Ws
001
Indirect
[Ws]
010
[Ws--]
011
[Ws++]
100
[--Ws]
101
[++Ws]
11x
Unused
Table 5-3:
qqq
Destination Operand
000
Register Direct
Wd
001
Indirect
[Wd]
010
[Wd--]
011
[Wd++]
100
[--Wd]
101
[++Wd]
11x
Unused (an attempt to use this Addressing mode will force a RESET instruction)
Table 5-4:
ggg
Source Operand
000
Register Direct
Ws
001
Indirect
[Ws]
010
[Ws--]
011
[Ws++]
100
[--Ws]
101
[++Ws]
11x
[Ws+Wb]
Table 5-5:
hhh
Source Operand
Register Direct
Wd
001
Indirect
[Wd]
010
[Wd--]
011
[Wd++]
100
[--Wd]
101
[++Wd]
11x
[Wd+Wb]
5
Instruction
Descriptions
000
DS70157E-page 95
iiii
0000
Wxd = [W8]
0001
Wxd = [W8], W8 = W8 + 2
0010
Wxd = [W8], W8 = W8 + 4
0011
Wxd = [W8], W8 = W8 + 6
0100
0101
Wxd = [W8], W8 = W8 6
0110
Wxd = [W8], W8 = W8 4
0111
Wxd = [W8], W8 = W8 2
1000
Wxd = [W9]
1001
Wxd = [W9], W9 = W9 + 2
1010
Wxd = [W9], W9 = W9 + 4
1011
Wxd = [W9], W9 = W9 + 6
1100
1101
Wxd = [W9], W9 = W9 6
1110
Wxd = [W9], W9 = W9 4
1111
Wxd = [W9], W9 = W9 2
Table 5-7:
xx
00
W4
01
W5
10
W6
11
W7
Table 5-8:
jjjj
DS70157E-page 96
0000
Wyd = [W10]
0001
0010
0011
0100
0101
0110
0111
1000
Wyd = [W11]
1001
1010
1011
1100
1101
1110
1111
yy
00
W4
01
W5
10
W6
11
W7
Table 5-10:
mm
00
W4 * W4
01
W5 * W5
10
W6 * W6
11
W7 * W7
Table 5-11:
mmm
000
W4 * W5
001
W4 * W6
010
W4 * W7
011
Invalid
100
W5 * W6
101
W5 * W7
110
W6 * W7
111
Invalid
Table 5-12:
aa
00
01
10
No Write Back
11
Invalid
Table 5-13:
PP
01
DSWPAG
10
11
TBLPAG
5
Instruction
Descriptions
00
DS70157E-page 97
Accumulator Selection
DS70157E-page 98
Target Accumulator
Accumulator A
Accumulator B
FOO
Implemented in:
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
The Syntax field consists of an optional label, the instruction mnemonic, any
optional extensions which exist for the instruction and the operands for the
instruction. Most instructions support more than one operand variant to
support the various dsPIC30F/dsPIC33F Addressing modes. In these
circumstances, all possible instruction operands are listed beneath each
other and are enclosed in braces.
Operands:
The Operands field describes the set of values which each of the operands
may take. Operands may be accumulator registers, file registers, literal
constants (signed or unsigned), or working registers.
Operation:
Status Affected:
The Status Affected field describes which bits of the STATUS Register are
affected by the instruction. Status bits are listed by bit position in
descending order.
Encoding:
The Encoding field shows how the instruction is bit encoded. Individual bit
fields are explained in the Description field, and complete encoding details
are provided in Table 5.2.
Description:
Words:
The Words field contains the number of program words that are used to
store the instruction in memory.
Cycles:
The Cycles field contains the number of instruction cycles that are required
to execute the instruction.
Examples:
The Examples field contains examples that demonstrate how the instruction
operates. Before and After register snapshots are provided, which allow
the user to clearly understand what operation the instruction performs.
5
Instruction
Descriptions
DS70157E-page 99
Instruction Descriptions
ADD
Add f to WREG
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
ADD{.B}
1011
0100
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
0BDf
ffff
Add the contents of the default working register WREG to the contents of
the file register, and place the result in the destination register. The
optional WREG operand determines the destination register. If WREG is
specified, the result is stored in WREG. If WREG is not specified, the
result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
ADD.B
RAM100
Before
Instruction
WREG CC80
RAM100 FFC0
SR
0000
Example 2:
ADD
After
Instruction
WREG CC80
RAM100 FF40
SR
0005 (OV, C = 1)
RAM200, WREG
Before
Instruction
WREG CC80
RAM200 FFC0
SR 0000
DS70157E-page 100
After
Instruction
WREG CC40
RAM200 FFC0
SR 0001 (C = 1)
ADD
Add Literal to Wn
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
kkkk
kkkk
dddd
Syntax:
{label:}
ADD{.B}
Operands:
Operation:
lit10 + (Wn) Wn
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
1011
0000
#lit10,
Wn
0Bkk
Add the 10-bit unsigned literal operand to the contents of the working
register Wn, and place the result back into the working register Wn.
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits specify the literal operand.
The d bits select the address of the working register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: For byte operations, the literal must be specified as an unsigned
value [0:255]. See Section 4.6 Using 10-bit Literal Operands
for information on using 10-bit literal operands in Byte mode.
Words:
Cycles:
Example 1:
ADD.B
#0xFF, W7
Before
Instruction
W7 12C0
SR
0000
Example 2:
ADD
Before
Instruction
W1 12C0
SR
0000
After
Instruction
W7 12BF
SR 0009 (N, C = 1)
#0xFF, W1
After
Instruction
W1 13BF
SR 0000
5
Instruction
Descriptions
DS70157E-page 101
ADD
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
ADD{.B}
Wb,
#lit5,
dsPIC33F dsPIC33E
X
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
(Wb) + lit5 Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
0100
0www
wBqq
qddd
d11k
kkkk
Add the contents of the base register Wb to the 5-bit unsigned short literal
operand, and place the result in the destination register Wd. Register
direct addressing must be used for Wb. Either register direct or indirect
addressing may be used for Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The k bits provide the literal operand, a five-bit integer number.
Note:
Words:
Cycles:
Example 1:
ADD.B
Before
Instruction
W0
2290
W7 12C0
SR
0000
DS70157E-page 102
W0, #0x1F, W7
After
Instruction
W0 2290
W7 12AF
SR 0008 (N = 1)
ADD
Before
Instruction
W3
6006
W4
1000
Data 0FFE DDEE
Data 1000 DDEE
SR
0000
After
Instruction
W3 6006
W4 0FFE
Data 0FFE 600C
Data 1000 DDEE
SR 0000
5
Instruction
Descriptions
DS70157E-page 103
ADD
Add Wb to Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
ADD{.B}
Operands:
Operation:
(Wb) + (Ws) Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
0100
0www
Wb,
Ws,
wBqq
dsPIC33F dsPIC33E
X
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
qddd
dppp
ssss
Add the contents of the source register Ws and the contents of the base
register Wb, and place the result in the destination register Wd. Register
direct addressing must be used for Wb. Either register direct or indirect
addressing may be used for Ws and Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
ADD.B
W5, W6, W7
Before
Instruction
W5
AB00
W6
0030
W7
FFFF
SR
0000
DS70157E-page 104
After
Instruction
W5
AB00
W6
0030
W7
FF30
SR
0000
ADD
Before
Instruction
W5
AB00
W6
0030
W7
FFFF
SR
0000
W5, W6, W7
After
Instruction
W5
AB00
W6
0030
W7
AB30
SR
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 105
ADD
Add Accumulators
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Acc [A,B]
Operation:
If (Acc = A):
(ACCA) + (ACCB) ACCA
Else:
(ACCA) + (ACCB) ACCB
Status Affected:
Encoding:
ADD
PIC24E
1100
Description:
1011
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
0000
Acc
A000
Words:
Cycles:
Example 1:
ADD
ACCA
ACCB
SR
Example 2:
ADD
ACCA
ACCB
SR
DS70157E-page 106
Before
Instruction
00 0022 3300
00 1833 4558
0000
B
Before
Instruction
00 E111 2222
00 7654 3210
0000
ACCA
ACCB
SR
After
Instruction
00 1855 7858
00 1833 4558
0000
ACCA
ACCB
SR
After
Instruction
00 E111 2222
01 5765 5432
4800 (OB, OAB = 1)
ADD
Implemented in:
Syntax:
PIC24F
{label:}
PIC24H
ADD
PIC24E
Ws,
dsPIC30F
dsPIC33F
dsPIC33E
rggg
ssss
{#Slit4,}
Acc
[Ws],
[Ws++],
[Ws--],
[--Ws],
[++Ws],
[Ws+Wb],
Operands:
Operation:
1100
1001
Awww
wrrr
Add a 16-bit value specified by the source working register to the most
significant word of the selected accumulator. The source operand may
specify the direct contents of a working register or an effective address. The
value specified is added to the most significant word of the accumulator by
sign-extending and zero backfilling the source operand prior to the operation.
The value added to the accumulator may also be shifted by a 4-bit signed
literal before the addition is made.
The A bit specifies the destination accumulator.
The w bits specify the offset register Wb.
The r bits encode the optional shift.
The g bits select the source Address mode.
The s bits specify the source register Ws.
Note:
Words:
Cycles:
Example 1:
ADD
W0, #2, A
Before
Instruction
8000
00 7000 0000
0000
W0
ACCA
SR
After
Instruction
8000
00 5000 0000
0000
Instruction
Descriptions
W0
ACCA
SR
DS70157E-page 107
ADD
W5
ACCA
Data 2000
SR
DS70157E-page 108
[W5++], A
Before
Instruction
2000
00 0067 2345
5000
0000
W5
ACCA
Data 2000
SR
After
Instruction
2002
00 5067 2345
5000
0000
ADDC
Implemented in:
PIC24F
PIC24H
PIC24E
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
1011
ADDC{.B} f
0100
ffff
ffff
{,WREG}
1BDf
ffff
Add the contents of the default working register WREG, the contents of
the file register and the Carry bit and place the result in the destination
register. The optional WREG operand determines the destination
register. If WREG is specified, the result is stored in WREG. If WREG is
not specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
3: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR. These
instructions can only clear Z.
Words:
Cycles:
Example 1:
ADDC.B
RAM100
Before
After
Instruction
Instruction
WREG CC60
WREG CC60
RAM100
8006
RAM100 8067
SR
0001 (C=1)
SR 0000
Example 2:
ADDC
RAM200, WREG
Before
After
Instruction
Instruction
WREG
5600
WREG 8A01
RAM200
3400
RAM200 3400
SR
0001 (C=1)
SR 000C (N, OV = 1)
5
Instruction
Descriptions
DS70157E-page 109
ADDC
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
kkkk
kkkk
dddd
Syntax:
{label:}
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
1011
ADDC{.B}
0000
#lit10,
1Bkk
dsPIC33F dsPIC33E
Wn
Add the 10-bit unsigned literal operand, the contents of the working
register Wn and the Carry bit, and place the result back into the working
register Wn.
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits specify the literal operand.
The d bits select the address of the working register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: For byte operations, the literal must be specified as an
unsigned value [0:255]. See Section 4.6 Using 10-bit Literal
Operands for information on using 10-bit literal operands in
Byte mode.
3: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR. These
instructions can only clear Z.
Words:
Cycles:
Example 1:
ADDC.B
#0xFF, W7
Before
Instruction
W7 12C0
SR
0000 (C = 0)
Example 2:
ADDC
#0xFF, W1
Before
Instruction
W1 12C0
SR
0001 (C = 1)
DS70157E-page 110
After
Instruction
W7 12BF
SR 0009 (N,C = 1)
After
Instruction
W1 13C0
SR 0000
ADDC
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
ADDC{.B}
Wb,
#lit5,
dsPIC33F dsPIC33E
X
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
0100
1www
wBqq
qddd
d11k
kkkk
Add the contents of the base register Wb, the 5-bit unsigned short literal
operand and the Carry bit, and place the result in the destination register
Wd. Register direct addressing must be used for Wb. Register direct or
indirect addressing may be used for Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The k bits provide the literal operand, a five-bit integer number.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR. These
instructions can only clear Z.
Words:
Cycles:
Example 1:
ADDC.B
After
Instruction
W0 CC80
W7 12C0
Data 12C0 B09F
SR
0008 (N = 1)
5
Instruction
Descriptions
Before
Instruction
W0 CC80
W7
12C0
Data 12C0
B000
SR
0000 (C = 0)
DS70157E-page 111
ADDC
Before
Instruction
W3 6006
W4 1000
Data 0FFE DDEE
Data 1000 DDEE
SR
0001 (C = 1)
DS70157E-page 112
W3
W4
Data 0FFE
Data 1000
SR
After
Instruction
6006
0FFE
600D
DDEE
0000
ADDC
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
ADDC{.B}
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
0100
Wb,
1www
Ws,
wBqq
dsPIC33F dsPIC33E
X
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
qddd
dppp
ssss
Add the contents of the source register Ws, the contents of the base
register Wb and the Carry bit, and place the result in the destination
register Wd. Register direct addressing must be used for Wb. Either
register direct or indirect addressing may be used for Ws and Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR. These
instructions can only clear Z.
Words:
Cycles:
Example 1:
ADDC.B
W0,[W1++],[W2++]
Before
After
Instruction
Instruction
W0 CC20
W0 CC20
W1 0800
W1 0801
W2 1000
W2 1001
Data 0800 AB25
Data 0800 AB25
Data 1000 FFFF
Data 1000 FF46
SR 0001 (C = 1)
SR 0000
Instruction
Descriptions
DS70157E-page 113
ADDC
W3,[W2++],[W1++]
Before
After
Instruction
Instruction
W1 1000
W1
1002
W2 2000
W2
2002
W3 0180
W3
0180
Data 1000 8000
Data 1000
2681
Data 2000 2500
Data 2000
2500
SR 0001 (C = 1)
SR
0000
DS70157E-page 114
AND
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
N, Z
Encoding:
Description:
AND{.B}
1011
0110
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
0BDf
ffff
Compute the logical AND operation of the contents of the default working
register WREG and the contents of the file register, and place the result in
the destination register. The optional WREG operand determines the
destination register. If WREG is specified, the result is stored in WREG.
If WREG is not specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
AND.B
RAM100
Before
Instruction
WREG CC80
RAM100 FFC0
SR
0000
Example 2:
AND
RAM200, WREG
Before
Instruction
WREG CC80
RAM200 12C0
SR
0000
After
Instruction
WREG CC80
RAM100 FF80
SR 0008 (N = 1)
; AND RAM200 to WREG (Word mode)
After
Instruction
WREG 0080
RAM200 12C0
SR 0000
5
Instruction
Descriptions
DS70157E-page 115
AND
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
kkkk
kkkk
dddd
Syntax:
{label:}
Operands:
Operation:
lit10.AND.(Wn) Wn
Status Affected:
N, Z
Encoding:
Description:
AND{.B}
1011
0010
#lit10,
0Bkk
dsPIC33F dsPIC33E
Wn
Compute the logical AND operation of the 10-bit literal operand and the
contents of the working register Wn and place the result back into the
working register Wn. Register direct addressing must be used for Wn.
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits specify the literal operand.
The d bits select the address of the working register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: For byte operations, the literal must be specified as an unsigned
value [0:255]. See Section 4.6 Using 10-bit Literal Operands for information on using 10-bit literal operands in Byte
mode.
Words:
Cycles:
Example 1:
AND.B
#0x83, W7
Before
Instruction
W7 12C0
SR
0000
Example 2:
AND
#0x333, W1
Before
Instruction
W1 12D0
SR
0000
DS70157E-page 116
After
Instruction
W7
1280
SR
0008 (N = 1)
; AND 0x333 to W1 (Word mode)
After
Instruction
W1
0210
SR
0000
AND
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
AND{.B}
Wb,
#lit5,
dsPIC33F dsPIC33E
X
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
(Wb).AND.lit5 Wd
Status Affected:
N, Z
Encoding:
0110
Description:
0www
wBqq
qddd
d11k
kkkk
Compute the logical AND operation of the contents of the base register
Wb and the 5-bit literal and place the result in the destination register Wd.
Register direct addressing must be used for Wb. Either register direct or
indirect addressing may be used for Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The k bits provide the literal operand, a five-bit integer number.
Note:
Words:
Cycles:
Example 1:
AND.B
W0,#0x3,[W1++]
Before
Instruction
W0 23A5
W1
2211
Data 2210
9999
SR
0000
AND
Before
Instruction
W0
6723
W1
7878
SR
0000
After
Instruction
W0 23A5
W1 2212
Data 2210 0199
SR 0000
W0,#0x1F,W1
After
Instruction
W0 6723
W1 0003
SR 0000
DS70157E-page 117
Instruction
Descriptions
Example 2:
AND
And Wb and Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
AND{.B}
Operands:
Operation:
(Wb).AND.(Ws) Wd
Status Affected:
N, Z
Encoding:
0110
Description:
Wb,
0www
wBqq
dsPIC33F dsPIC33E
X
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
qddd
dppp
ssss
Compute the logical AND operation of the contents of the source register
Ws and the contents of the base register Wb, and place the result in the
destination register Wd. Register direct addressing must be used for Wb.
Either register direct or indirect addressing may be used for Ws and Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
AND.B
W0, W1 [W2++]
Before
Instruction
W0 AA55
W1
2211
W2
1001
Data 1000 FFFF
SR
0000
DS70157E-page 118
After
Instruction
W0 AA55
W1
2211
W2
1002
Data 1000
11FF
SR
0000
AND
Before
Instruction
W0
AA55
W1
1000
W2
55AA
Data 1000
2634
SR
0000
After
Instruction
W0
AA55
W1
1002
W2
2214
Data 1000
2634
SR
0000
5
Instruction
Descriptions
DS70157E-page 119
ASR
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
ASR{.B}
Operands:
f [0 ... 8191]
Operation:
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
Status Affected:
N, Z, C
Encoding:
1101
Description:
0101
1BDf
ffff
Shift the contents of the file register one bit to the right and place the result
in the destination register. The Least Significant bit of the file register is
shifted into the Carry bit of the STATUS Register. After the shift is performed, the result is sign-extended. The optional WREG operand determines the destination register. If WREG is specified, the result is stored in
WREG. If WREG is not specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
ASR.B
RAM400, WREG
Before
Instruction
WREG
0600
RAM400
0823
SR
0000
DS70157E-page 120
After
Instruction
WREG
0611
RAM400
0823
SR
0001 (C = 1)
ASR
RAM200
Before
Instruction
RAM200
8009
SR
0000
After
Instruction
RAM200 C004
SR
0009 (N, C = 1)
5
Instruction
Descriptions
DS70157E-page 121
ASR
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
ASR{.B}
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
Operands:
Operation:
dsPIC33F dsPIC33E
X
dppp
ssss
Status Affected:
N, Z, C
Encoding:
Description:
1101
0001
1Bqq
qddd
Shift the contents of the source register Ws one bit to the right and place the
result in the destination register Wd. The Least Significant bit of Ws is
shifted into the Carry bit of the STATUS register. After the shift is performed,
the result is sign-extended. Either register direct or indirect addressing may
be used for Ws and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
DS70157E-page 122
Words:
Cycles:
ASR.B
[W0++], [W1++]
Before
Instruction
W0
0600
W1
0801
Data 600
2366
Data 800
FFC0
SR
0000
Example 2:
ASR
W12, W13
Before
Instruction
W12 AB01
W13
0322
SR
0000
After
Instruction
W0
0601
W1
0802
Data 600
2366
Data 800 33C0
SR
0000
After
Instruction
W12 AB01
W13 D580
SR 0009 (N, C = 1)
5
Instruction
Descriptions
DS70157E-page 123
ASR
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
lit4<3:0> Shift_Val
Wb<15> Wnd<15:15-Shift_Val + 1>
Wb<15:Shift_Val> Wnd<15-Shift_Val:0>
Status Affected:
N, Z
Encoding:
1101
Description:
ASR
1110
Wb,
1www
#lit4,
dsPIC33F dsPIC33E
X
d100
kkkk
Wnd
wddd
Arithmetic shift right the contents of the source register Wb by the 4-bit
unsigned literal, and store the result in the destination register Wnd. After
the shift is performed, the result is sign-extended. Direct addressing must
be used for Wb and Wnd.
The w bits select the address of the base register.
The d bits select the destination register.
The k bits provide the literal operand.
Note:
Words:
Cycles:
Example 1:
ASR
W0, #0x4, W1
Before
Instruction
W0
060F
W1
1234
SR
0000
Example 2:
ASR
W0, #0x6, W1
Before
Instruction
W0
80FF
W1
0060
SR
0000
Example 3:
ASR
W0, #0xF, W1
Before
Instruction
W0
70FF
W1 CC26
SR
0000
DS70157E-page 124
After
Instruction
W0 060F
W1
0060
SR
0000
; ASR W0 by 6 and store to W1
After
Instruction
W0 80FF
W1 FE03
SR
0008 (N = 1)
; ASR W0 by 15 and store to W1
After
Instruction
W0
70FF
W1
0000
SR
0002 (Z = 1)
ASR
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Wns<3:0> Shift_Val
Wb<15> Wnd<15:15-Shift_Val + 1>
Wb<15:Shift_Val> Wnd<15-Shift_Val:0>
Status Affected:
N, Z
Encoding:
ASR
1101
1110
Wb,
Wns,
1www
wddd
dsPIC33F dsPIC33E
X
d000
ssss
Wnd
Description:
Arithmetic shift right the contents of the source register Wb by the 4 Least
Significant bits of Wns (up to 15 positions) and store the result in the
destination register Wnd. After the shift is performed, the result is
sign-extended. Direct addressing must be used for Wb, Wns and Wnd.
The w bits select the address of the base register.
The d bits select the destination register.
The s bits select the source register.
Note 1: This instruction operates in Word mode only.
2: If Wns is greater than 15, Wnd = 0x0 if Wb is positive, and
Wnd = 0xFFFF if Wb is negative.
Words:
Cycles:
Example 1:
ASR
W0, W5, W6
Before
Instruction
W0
80FF
W5
0004
W6
2633
SR
0000
Example 2:
ASR
W0, W5, W6
Before
Instruction
W0
6688
W5
000A
W6
FF00
SR
0000
After
Instruction
W0
80FF
W5
0004
W6
F80F
SR
0000
; ASR W0 by W5 and store to W6
After
Instruction
W0
6688
W5
000A
W6
0019
SR
0000
5
Instruction
Descriptions
DS70157E-page 125
ASR
Before
Instruction
W11
8765
W12
88E4
W13
A5A5
SR
0000
DS70157E-page 126
After
Instruction
W11
8765
W12
88E4
W13
F876
SR
0008 (N = 1)
BCLR
Bit Clear f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
0 f<bit4>
Status Affected:
None
Encoding:
1010
Description:
BCLR{.B}
1001
f,
dsPIC33F dsPIC33E
X
ffff
fffb
#bit4
bbbf
ffff
Clear the bit in the file register f specified by bit4. Bit numbering begins
with the Least Significant bit (bit 0) and advances to the Most Significant
bit (bit 7 for byte operations, bit 15 for word operations).
The b bits select value bit4 of the bit position to be cleared.
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: When this instruction operates in Word mode, the file register
address must be word-aligned.
3: When this instruction operates in Byte mode, bit4 must be
between 0 and 7.
Words:
Cycles:
Example 1:
Before
Instruction
Data 0800
66EF
SR
0000
Example 2:
BCLR
After
Instruction
Data 0800
666F
SR
0000
0x400, #0x9
Before
Instruction
Data 0400
AA55
SR
0000
After
Instruction
Data 0400
A855
SR
0000
5
Instruction
Descriptions
DS70157E-page 127
BCLR
Bit Clear in Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
0B00
0ppp
ssss
{label:}
BCLR{.B}
Ws,
dsPIC33F dsPIC33E
#bit4
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
0 Ws<bit4>
Status Affected:
None
Encoding:
Description:
1010
0001
bbbb
Clear the bit in register Ws specified by bit4. Bit numbering begins with
the Least Significant bit (bit 0) and advances to the Most Significant bit (bit
7 for byte operations, bit 15 for word operations). Register direct or indirect addressing may be used for Ws.
The b bits select value bit4 of the bit position to be cleared.
The B bit selects byte or word operation (0 for word, 1 for byte).
The s bits select the source/destination register.
The p bits select the source Address mode.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: When this instruction operates in Word mode, the source
register address must be word-aligned.
3: When this instruction operates in Byte mode, bit4 must be
between 0 and 7.
4: In dsPIC33E and PIC24E devices, this instruction uses the
DSRPAG register for indirect address generation in Extended
Data Space.
Words:
Cycles:
Example 1:
Before
Instruction
W2
F234
SR
0000
DS70157E-page 128
; Clear bit 3 in W2
After
Instruction
W2
F230
SR
0000
BCLR
[W0++], #0x0
Before
Instruction
W0
2300
Data 2300
5607
SR
0000
After
Instruction
W0
2302
Data 2300
5606
SR
0000
5
Instruction
Descriptions
DS70157E-page 129
BRA
Branch Unconditionally
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
BRA
dsPIC33F dsPIC33E
0011
Expr
0111
nnnn
nnnn
nnnn
nnnn
Description:
The program will branch unconditionally, relative to the next PC. The offset
of the branch is the twos complement number 2 * Slit16, which supports
branches up to 32K instructions forward or backward. The Slit16 value is
resolved by the linker from the supplied label, absolute address or
expression. After the branch is taken, the new address will be (PC + 2) + 2 *
Slit16, since the PC will have incremented to fetch the next instruction.
The n bits are a signed literal that specifies the number of program words
offset from (PC + 2).
Words:
Cycles:
Example 1:
002000 HERE:
002002
002004
002006
002008
00200A THERE:
00200C
PC
SR
Example 2:
DS70157E-page 130
THERE
.
.
.
.
.
.
Before
Instruction
00 2000
0000
002000 HERE:
002002
002004
002006
002008
00200A THERE:
00200C
PC
SR
BRA
. .
. .
. .
. .
. .
. .
Before
Instruction
00 2000
0000
; Branch to THERE
After
Instruction
PC
00 200A
SR
0000
BRA
. .
. .
. .
. .
. .
. .
THERE+0x2
.
.
.
.
.
.
; Branch to THERE+0x2
After
Instruction
PC
00 200C
SR
0000
002000 HERE:
002002
002004
PC
SR
Before
Instruction
00 2000
0000
BRA 0x1366
. . .
. . .
; Branch to 0x1366
After
Instruction
PC
00 1366
SR
0000
5
Instruction
Descriptions
DS70157E-page 131
BRA
Computed Branch
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(PC + 2) + (2 * Wn) PC
NOP Instruction Register
Status Affected:
None
Encoding:
BRA
PIC24E
0000
Description:
0001
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
Wn
0110
ssss
The program branches unconditionally, relative to the next PC. The offset
of the branch is the sign-extended 17-bit value (2 * Wn), which supports
branches up to 32K instructions forward or backward. After this instruction
executes, the new PC will be (PC + 2) + 2 * Wn, since the PC will have
incremented to fetch the next instruction.
The s bits select the source register.
Words:
Cycles:
Example 1:
002000 HERE:
002002
...
...
002108
00210A TABLE7:
00210C
PC
W7
SR
DS70157E-page 132
Before
Instruction
00 2000
0084
0000
.
.
.
.
.
.
BRA W7
. .
. .
. .
. .
. .
. .
After
Instruction
PC
00 210A
W7
0084
SR
0000
BRA
Computed Branch
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(PC + 2) + (2 * Wn) PC
NOP Instruction Register
Status Affected:
None
Encoding:
BRA
0000
Description:
0001
Wn
0000
0110
0000
ssss
The program branches unconditionally, relative to the next PC. The offset
of the branch is the sign-extended 17-bit value (2 * Wn), which supports
branches up to 32K instructions forward or backward. After this instruction
executes, the new PC will be (PC + 2) + 2 * Wn, since the PC will have
incremented to fetch the next instruction.
The s bits select the source register.
Words:
Cycles:
Example 1:
002000 HERE:
002002
...
...
002108
00210A TABLE7:
00210C
PC
W7
SR
Before
Instruction
00 2000
0084
0000
.
.
.
.
.
.
BRA W7
. .
. .
. .
. .
. .
. .
After
Instruction
PC
00 210A
W7
0084
SR
0000
5
Instruction
Descriptions
DS70157E-page 133
BRA C
Branch if Carry
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
Operands:
Operation:
Condition = C
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Description:
0011
0001
C,
Syntax:
Encoding:
BRA
dsPIC33F dsPIC33E
Expr
nnnn
nnnn
nnnn
nnnn
If the Carry flag bit is 1, then the program will branch relative to the next PC.
The offset of the branch is the twos complement number 2 * Slit16, which
supports branches up to 32K instructions forward or backward. The Slit16
value is resolved by the linker from the supplied label, absolute address or
expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since the
PC will have incremented to fetch the next instruction. The instruction then
becomes a two-cycle instruction, with a NOP executed in the second cycle.
The n bits are a 16-bit signed literal that specify the offset from (PC + 2) in
instruction words.
Words:
Cycles:
Example 1:
002000
002002
002004
002006
002008
00200A
00200C
00200E
PC
SR
DS70157E-page 134
HERE:
NO_C:
CARRY:
THERE:
BRA C, CARRY
. . .
. . .
GOTO THERE
. . .
. . .
. . .
. . .
Before
Instruction
00 2000
0001 (C = 1)
PC
SR
After
Instruction
00 2008
0001 (C = 1)
002000
002002
002004
002006
002008
00200A
00200C
00200E
PC
SR
Example 3:
Example 4:
CARRY:
THERE:
HERE:
NO_C:
CARRY:
THERE:
PC
SR
BRA C, CARRY
...
...
GOTO THERE
...
...
...
...
Before
Instruction
00 6230
0001 (C = 1)
006230 START:
006232
006234 CARRY:
006236
006238
00623A
00623C HERE:
00623E
PC
SR
BRA C, CARRY
...
...
GOTO THERE
...
...
...
...
Before
Instruction
00 2000
0000
006230
006232
006234
006236
006238
00623A
00623C
00623E
PC
SR
HERE:
NO_C:
PC
SR
...
...
...
...
...
...
BRA C, CARRY
...
Before
Instruction
00 623C
0001 (C = 1)
After
Instruction
00 2002
0000
After
Instruction
00 6238
0001 (C = 1)
PC
SR
After
Instruction
00 6234
0001 (C = 1)
5
Instruction
Descriptions
DS70157E-page 135
BRA GE
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = (N&&OV)||(!N&&!OV)
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
GE,
dsPIC33F dsPIC33E
1101
nnnn
nnnn
Expr
nnnn
nnnn
The assembler will convert the specified label into the offset to
be used.
Words:
Cycles:
Example 1:
007600 LOOP:
007602
007604
007606
007608 HERE:
00760A NO_GE:
PC
SR
DS70157E-page 136
Before
Instruction
00 7608
0000
. .
. .
. .
. .
BRA
. .
.
.
.
.
GE, LOOP
.
After
Instruction
PC
00 7600
SR
0000
007600 LOOP:
007602
007604
007606
007608 HERE:
00760A NO_GE:
PC
SR
. .
. .
. .
. .
BRA
. .
.
.
.
.
GE, LOOP
.
Before
Instruction
00 7608
0008 (N = 1)
After
Instruction
PC
00 760A
SR
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 137
BRA GEU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
Operands:
Operation:
Condition = C
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
0011
Description:
0001
GEU,
Syntax:
Encoding:
BRA
dsPIC33F dsPIC33E
nnnn
Expr
nnnn
nnnn
nnnn
If the Carry flag is 1, then the program will branch relative to the next
PC. The offset of the branch is the twos complement number 2 *
Slit16, which supports branches up to 32K instructions forward or backward. The Slit16 value is resolved by the linker from the supplied label,
absolute address or expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16,
since the PC will have incremented to fetch the next instruction. The
instruction then becomes a two-cycle instruction, with a NOP executed
in the second cycle.
The n bits are a 16-bit signed literal that specify the offset from
(PC + 2) in instruction words.
Note:
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_GEU:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
DS70157E-page 138
Before
Instruction
00 2000
0001 (C = 1)
PC
SR
; If C is set, branch
; to BYPASS
; Otherwise... continue
After
Instruction
00 200C
0001 (C = 1)
BRA GT
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = (!Z&&N&&OV)||(!Z&&!N&&!OV)
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
1100
GT,
dsPIC33F dsPIC33E
X
nnnn
nnnn
Expr
nnnn
nnnn
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_GT:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
Before
Instruction
00 2000
0001 (C = 1)
After
Instruction
PC
00 200C
SR
0001 (C = 1)
5
Instruction
Descriptions
DS70157E-page 139
BRA GTU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = (C&&!Z)
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
1110
GTU,
dsPIC33F dsPIC33E
X
nnnn
nnnn
Expr
nnnn
nnnn
If the logical expression (C&&!Z) is true, then the program will branch
relative to the next PC. The offset of the branch is the twos complement
number 2 * Slit16, which supports branches up to 32K instructions
forward or backward. The Slit16 value is resolved by the linker from the
supplied label, absolute address or expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_GTU:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
DS70157E-page 140
Before
Instruction
00 2000
0001 (C = 1)
PC
SR
After
Instruction
00 200C
0001 (C = 1)
BRA LE
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = Z||(N&&!OV)||(!N&&OV)
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
0100
LE,
dsPIC33F dsPIC33E
X
nnnn
nnnn
Expr
nnnn
nnnn
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_LE:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
Before
Instruction
00 2000
0001 (C = 1)
PC
SR
After
Instruction
00 2002
0001 (C = 1)
5
Instruction
Descriptions
DS70157E-page 141
BRA LEU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = !C||Z
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
0110
LEU,
dsPIC33F dsPIC33E
nnnn
nnnn
nnnn
Expr
nnnn
If the logical expression (!C||Z) is true, then the program will branch
relative to the next PC. The offset of the branch is the twos complement
number 2 * Slit16, which supports branches up to 32K instructions forward or backward. The Slit16 value is resolved by the linker from the
supplied label, absolute address or expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_LEU:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
DS70157E-page 142
Before
Instruction
00 2000
0001 (C = 1)
PC
SR
After
Instruction
00 200C
0001 (C = 1)
BRA LT
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = (N&&!OV)||(!N&&OV)
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
0101
LT,
dsPIC33F dsPIC33E
X
nnnn
nnnn
Expr
nnnn
nnnn
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_LT:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
Before
Instruction
00 2000
0001 (C = 1)
After
Instruction
PC
00 2002
SR
0001 (C = 1)
5
Instruction
Descriptions
DS70157E-page 143
BRA LTU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = !C
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
1001
LTU,
dsPIC33F dsPIC33E
nnnn
nnnn
nnnn
Expr
nnnn
If the Carry flag is 0, then the program will branch relative to the next PC.
The offset of the branch is the twos complement number 2 * Slit16,
which supports branches up to 32K instructions forward or backward. The
Slit16 value is resolved by the linker from the supplied label, absolute
address or expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
Note:
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_LTU:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
DS70157E-page 144
Before
Instruction
00 2000
0001 (C = 1)
PC
SR
After
Instruction
00 2002
0001 (C = 1)
BRA N
Branch if Negative
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = N
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register.
Status Affected:
None
Encoding:
0011
Description:
BRA
0011
N,
dsPIC33F dsPIC33E
X
nnnn
nnnn
Expr
nnnn
nnnn
If the Negative flag is 1, then the program will branch relative to the next
PC. The offset of the branch is the twos complement number 2 * Slit16,
which supports branches up to 32K instructions forward or backward. The
Slit16 value is resolved by the linker from the supplied label, absolute
address or expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_N:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
BRA N, BYPASS
. . .
. . .
. . .
. . .
GOTO THERE
. . .
. . .
Before
Instruction
00 2000
0008 (N = 1)
PC
SR
; If N, branch to BYPASS
; Otherwise... continue
After
Instruction
00 200C
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 145
BRA NC
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = !C
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
1001
NC,
dsPIC33F dsPIC33E
nnnn
nnnn
nnnn
Expr
nnnn
If the Carry flag is 0, then the program will branch relative to the next PC.
The offset of the branch is the twos complement number 2 * Slit16, which
supports branches up to 32K instructions forward or backward. The Slit16
value is resolved by the linker from the supplied label, absolute address or
expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_NC:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
DS70157E-page 146
Before
Instruction
00 2000
0001 (C = 1)
PC
SR
After
Instruction
00 2002
0001 (C = 1)
BRA NN
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = !N
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
1011
NN,
dsPIC33F dsPIC33E
X
nnnn
nnnn
Expr
nnnn
nnnn
If the Negative flag is 0, then the program will branch relative to the next
PC. The offset of the branch is the twos complement number 2 * Slit16,
which supports branches up to 32K instructions forward or backward. The
Slit16 value is resolved by the linker from the supplied label, absolute
address or expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_NN:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
Before
Instruction
00 2000
0000
PC
SR
After
Instruction
00 200C
0000
5
Instruction
Descriptions
DS70157E-page 147
BRA NOV
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = !OV
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
1000
NOV,
dsPIC33F dsPIC33E
nnnn
nnnn
nnnn
Expr
nnnn
If the Overflow flag is 0, then the program will branch relative to the next
PC. The offset of the branch is the twos complement number 2 * Slit16,
which supports branches up to 32K instructions forward or backward. The
Slit16 value is resolved by the linker from the supplied label, absolute
address or expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_NOV:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
DS70157E-page 148
Before
Instruction
00 2000
0008 (N = 1)
PC
SR
After
Instruction
00 200C
0008 (N = 1)
BRA NZ
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = !Z
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
1010
NZ,
dsPIC33F dsPIC33E
X
nnnn
nnnn
Expr
nnnn
nnnn
If the Z flag is 0, then the program will branch relative to the next PC. The
offset of the branch is the twos complement number 2 * Slit16, which
supports branches up to 32K instructions forward or backward. The Slit16
value is resolved by the linker from the supplied label, absolute address or
expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_NZ:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
Before
Instruction
00 2000
0002 (Z = 1)
PC
SR
After
Instruction
00 2002
0002 (Z = 1)
5
Instruction
Descriptions
DS70157E-page 149
BRA OA
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Condition = OA
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0000
Description:
BRA
1100
OA,
nnnn
nnnn
nnnn
Expr
nnnn
The assembler will convert the specified label into the offset to
be used.
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_OA:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
DS70157E-page 150
Before
Instruction
00 2000
PC
8800 (OA, OAB = 1) SR
After
Instruction
00 200C
8800 (OA, OAB = 1)
BRA OB
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Condition = OB
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0000
Description:
BRA
1101
OB,
nnnn
nnnn
nnnn
Expr
nnnn
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_OB:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
Before
Instruction
00 2000
PC
8800 (OA, OAB = 1) SR
After
Instruction
00 2002
8800 (OA, OAB = 1)
5
Instruction
Descriptions
DS70157E-page 151
BRA OV
Branch if Overflow
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Condition = OV
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0011
Description:
BRA
0000
OV,
dsPIC33F dsPIC33E
nnnn
nnnn
nnnn
Expr
nnnn
If the Overflow flag is 1, then the program will branch relative to the next
PC. The offset of the branch is the twos complement number 2 * Slit16,
which supports branches up to 32K instructions forward or backward. The
Slit16 value is resolved by the linker from the supplied label, absolute
address or expression.
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_OV
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
DS70157E-page 152
Before
Instruction
00 2000
0002 (Z = 1)
PC
SR
After
Instruction
00 2002
0002 (Z = 1)
BRA SA
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Condition = SA
If (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0000
Description:
BRA
1110
SA,
nnnn
nnnn
nnnn
Expr
nnnn
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_SA:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
Before
Instruction
00 2000
PC
2400 (SA, SAB = 1) SR
After
Instruction
00 200C
2400 (SA, SAB = 1)
5
Instruction
Descriptions
DS70157E-page 153
BRA SB
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Condition = SB
if (Condition)
(PC + 2) + 2 * Slit16 PC
NOP Instruction Register
Status Affected:
None
Encoding:
0000
Description:
BRA
1111
SB,
nnnn
nnnn
Expr
nnnn
nnnn
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_SB:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
DS70157E-page 154
Before
Instruction
00 2000
0000
PC
SR
After
Instruction
00 2002
0000
BRA Z
Branch if Zero
Implemented in:
PIC24F
X
PIC24H
X
dsPIC33F
X
dsPIC33E
X
{label:}
Operands:
Status Affected:
Encoding:
Description:
Z,
dsPIC30F
X
Syntax:
Operation:
BRA
PIC24E
X
Expr
If the branch is taken, the new address will be (PC + 2) + 2 * Slit16, since
the PC will have incremented to fetch the next instruction. The instruction
then becomes a two-cycle instruction, with a NOP executed in the second
cycle.
The n bits are a signed literal that specifies the number of instructions
offset from (PC + 2).
1
1 (2 if branch taken) PIC24F, PIC24H, dsPIC30F, dsPIC33F
1 (4 if branch taken) PIC24E, dsPIC33E
Words:
Cycles:
Example 1:
002000 HERE:
002002 NO_Z:
002004
002006
002008
00200A
00200C BYPASS:
00200E
PC
SR
BRA Z, BYPASS
. . .
. . .
. . .
. . .
GOTO THERE
. . .
. . .
Before
Instruction
00 2000
0002 (Z = 1)
PC
SR
; If Z, branch to BYPASS
; Otherwise... continue
After
Instruction
00 200C
0002 (Z = 1)
5
Instruction
Descriptions
DS70157E-page 155
BSET
Bit Set f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
1 f<bit4>
Status Affected:
None
Encoding:
1010
Description:
BSET{.B}
1000
f,
dsPIC33F dsPIC33E
X
ffff
fffb
#bit4
bbbf
ffff
Set the bit in the file register f specified by bit4. Bit numbering begins
with the Least Significant bit (bit 0) and advances to the Most Significant
bit (bit 7 for byte operations, bit 15 for word operations).
The b bits select value bit4 of the bit position to be set.
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: When this instruction operates in Word mode, the file register
address must be word-aligned.
3: When this instruction operates in Byte mode, bit4 must be
between 0 and 7.
Words:
Cycles:
Example 1:
BSET.B
0x601, #0x3
Before
Instruction
Data 0600
F234
SR
0000
Example 2:
BSET
DS70157E-page 156
After
Instruction
Data 0600 FA34
SR
0000
0x444, #0xF
Before
Instruction
Data 0444
5604
SR
0000
After
Instruction
Data 0444 D604
SR
0000
BSET
Bit Set in Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
0B00
0ppp
ssss
{label:}
BSET{.B}
Ws,
dsPIC33F dsPIC33E
#bit4
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
1 Ws<bit4>
Status Affected:
None
Encoding:
Description:
1010
0000
bbbb
Set the bit in register Ws specified by bit4. Bit numbering begins with the
Least Significant bit (bit 0) and advances to the Most Significant bit (bit 7
for byte operations, bit 15 for word operations). Register direct or indirect
addressing may be used for Ws.
The b bits select value bit4 of the bit position to be cleared.
The B bit selects byte or word operation (0 for word, 1 for byte).
The p bits select the source Address mode.
The s bits select the source/destination register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: When this instruction operates in Word mode, the source
register address must be word-aligned.
3: When this instruction operates in Byte mode, bit4 must be
between 0 and 7.
4: In dsPIC33E and PIC24E devices, this instruction uses the
DSRPAG register for indirect address generation in Extended
Data Space.
Words:
Cycles:
Example 1:
After
Instruction
W3 00A6
SR
0000
Instruction
Descriptions
Before
Instruction
W3
0026
SR
0000
; Set bit 7 in W3
DS70157E-page 157
BSET
[W4++], #0x0
Before
Instruction
W4
6700
Data 6700
1734
SR
0000
DS70157E-page 158
After
Instruction
W4
6702
Data 6700
1735
SR
0000
BSW
Bit Write in Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
BSW.C
w000
0ppp
ssss
BSW.Z
Ws,
dsPIC33F dsPIC33E
Wb
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
For .C operation:
C Ws<(Wb)>
For .Z operation (default):
Z Ws<(Wb)>
Status Affected:
None
Encoding:
Description:
1010
1101
Zwww
The (Wb) bit in register Ws is written with the value of the C or Z flag from
the STATUS register. Bit numbering begins with the Least Significant bit
(bit 0) and advances to the Most Significant bit (bit 15) of the working
register. Only the four Least Significant bits of Wb are used to determine
the destination bit number. Register direct addressing must be used for
Wb, and either register direct, or indirect addressing may be used for Ws.
The Z bit selects the C or Z flag as source.
The w bits select the address of the bit select register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
BSW.C
W2, W3
Before
After
Instruction
Instruction
W2
F234
W2 7234
W3
111F
W3
111F
SR
0002 (Z = 1, C = 0) SR 0002 (Z = 1, C = 0)
5
Instruction
Descriptions
DS70157E-page 159
BSW.Z
W2, W3
Before
After
Instruction
Instruction
W2
E235
W2
E234
W3
0550
W3
0550
SR
0002 (Z = 1, C = 0) SR
0002 (Z = 1, C = 0)
Example 3:
BSW.C
[++W0], W6
Before
After
Instruction
Instruction
W0
1000
W0
1002
W6
34A3
W6 34A3
Data 1002
2380
Data 1002
2388
SR
0001 (Z = 0, C = 1) SR
0001 (Z = 0, C = 1)
Example 4:
BSW.Z [W1--], W5
Before
After
Instruction
Instruction
W1
1000
W1 0FFE
W5
888B
W5 888B
Data 1000 C4DD
Data 1000 CCDD
SR
0001 (C = 1)
SR
0001 (C = 1)
DS70157E-page 160
BTG
Bit Toggle f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
(f)<bit4> (f)<bit4>
Status Affected:
None
Encoding:
1010
Description:
BTG{.B}
1010
f,
dsPIC33F dsPIC33E
X
ffff
fffb
#bit4
bbbf
ffff
Words:
Cycles:
Example 1:
BTG.B
0x1001, #0x4
Before
Instruction
Data 1000
F234
SR
0000
Example 2:
BTG
After
Instruction
Data 1000 E234
SR
0000
0x1660, #0x8
Before
Instruction
Data 1660
5606
SR
0000
After
Instruction
Data 1660
5706
SR
0000
5
Instruction
Descriptions
DS70157E-page 161
BTG
Bit Toggle in Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
0B00
0ppp
ssss
{label:}
BTG{.B}
Ws,
dsPIC33F dsPIC33E
#bit4
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
(Ws)<bit4> Ws<bit4>
Status Affected:
None
Encoding:
1010
Description:
0010
bbbb
Words:
Cycles:
Example 1:
BTG
W2, #0x0
Before
Instruction
W2
F234
SR
0000
DS70157E-page 162
; Toggle bit 0 in W2
After
Instruction
W2
F235
SR
0000
BTG
[W0++], #0x0
Before
Instruction
W0
2300
Data 2300
5606
SR
0000
After
Instruction
W0
2302
Data 2300
5607
SR
0000
5
Instruction
Descriptions
DS70157E-page 163
BTSC
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Status Affected:
None
Encoding:
1010
Description:
BTSC{.B}
1111
f,
dsPIC33F dsPIC33E
X
ffff
fffb
#bit4
bbbf
ffff
Bit bit4 in the file register is tested. If the tested bit is 0, the next
instruction (fetched during the current instruction execution) is discarded
and on the next cycle, a NOP is executed instead. If the tested bit is 1,
the next instruction is executed as normal. In either case, the contents of
the file register are not changed. For the bit4 operand, bit numbering
begins with the Least Significant bit (bit 0) and advances to the Most
Significant bit (bit 7 for byte operations, bit 15 for word operations).
The b bits select value bit4, the bit position to test.
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: When this instruction operates in Word mode, the file register
address must be word-aligned.
3: When this instruction operates in Byte mode, bit4 must be
between 0 and 7.
Words:
Cycles:
1 (2 or 3)
Example 1:
002000 HERE:
002002
002004
002006
002008 BYPASS:
00200A
PC
Data 1200
SR
DS70157E-page 164
Before
Instruction
00 2000
264F
0000
BTSC.B
GOTO
. . .
. . .
. . .
. . .
0x1201, #2
BYPASS
; If bit 2 of 0x1201 is 0,
; skip the GOTO
After
Instruction
PC
00 2002
Data 1200
264F
SR
0000
002000 HERE:
002002
002004
002006
002008 BYPASS:
00200A
PC
Data 0804
SR
Before
Instruction
00 2000
2647
0000
BTSC
GOTO
. . .
. . .
. . .
. . .
0x804, #14
BYPASS
; If bit 14 of 0x804 is 0,
; skip the GOTO
After
Instruction
PC
00 2006
Data 0804
2647
SR
0000
5
Instruction
Descriptions
DS70157E-page 165
BTSC
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
0000
0ppp
ssss
{label:}
BTSC
Ws,
dsPIC33F dsPIC33E
#bit4
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
1010
Description:
0111
bbbb
Bit bit4 in Ws is tested. If the tested bit is 0, the next instruction (fetched
during the current instruction execution) is discarded and on the next
cycle, a NOP is executed instead. If the tested bit is 1, the next instruction
is executed as normal. In either case, the contents of Ws are not changed.
For the bit4 operand, bit numbering begins with the Least Significant bit
(bit 0) and advances to the Most Significant bit (bit 15) of the word. Either
register direct or indirect addressing may be used for Ws.
The b bits select value bit4, the bit position to test.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
002000 HERE:
002002
002004
002006
002008 BYPASS:
00200A
PC
W0
SR
DS70157E-page 166
Before
Instruction
00 2000
264F
0000
BTSC
GOTO
. . .
. . .
. . .
. . .
W0, #0x0
BYPASS
; If bit 0 of W0 is 0,
; skip the GOTO
After
Instruction
PC
00 2002
W0
264F
SR
0000
002000 HERE:
002002
002004
002006
002008 BYPASS:
00200A
PC
W6
SR
Example 3:
Before
Instruction
00 2000
264F
0000
003400 HERE:
003402
003404
003406
003408 BYPASS:
00340A
PC
W6
Data 1800
SR
BTSC
GOTO
. . .
. . .
. . .
. . .
Before
Instruction
00 3400
1800
1000
0000
W6, #0xF
BYPASS
PC
W6
SR
BTSC
GOTO
. . .
. . .
. . .
. . .
; If bit 15 of W6 is 0,
; skip the GOTO
After
Instruction
00 2006
264F
0000
[W6++], #0xC
BYPASS
PC
W6
Data 1800
SR
; If bit 12 of [W6] is 0,
; skip the GOTO
; Post-increment W6
After
Instruction
00 3402
1802
1000
0000
5
Instruction
Descriptions
DS70157E-page 167
BTSS
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Status Affected:
None
Encoding:
BTSS{.B}
1010
Description:
1110
f,
dsPIC33F dsPIC33E
X
ffff
fffb
#bit4
bbbf
ffff
Bit bit4 in the file register f is tested. If the tested bit is 1, the next
instruction (fetched during the current instruction execution) is discarded
and on the next cycle, a NOP is executed instead. If the tested bit is 0, the
next instruction is executed as normal. In either case, the contents of the
file register are not changed. For the bit4 operand, bit numbering begins
with the Least Significant bit (bit 0) and advances to the Most Significant
bit (bit 7 for byte operation, bit 15 for word operation).
The b bits select value bit4, the bit position to test.
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: When this instruction operates in Word mode, the file register
address must be word-aligned.
3: When this instruction operates in Byte mode, bit4 must be
between 0 and 7.
Words:
Cycles:
Example 1:
007100 HERE:
007102
007104
PC
Data 1400
SR
Example 2:
DS70157E-page 168
Before
Instruction
00 7100
0280
0000
007100 HERE:
007102
007104
007106 BYPASS:
PC
Data 0890
SR
BTSS.B
CLR
. . .
Before
Instruction
00 7100
00FE
0000
0x1401, #0x1
WREG
PC
Data 1400
SR
BTSS
GOTO
. . .
. . .
After
Instruction
00 7104
0280
0000
0x890, #0x9
BYPASS
PC
Data 0890
SR
; If bit 1 of 0x1401 is 1,
; dont clear WREG
; If bit 9 of 0x890 is 1,
; skip the GOTO
After
Instruction
00 7102
00FE
0000
BTSS
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
0000
0ppp
ssss
{label:}
BTSS
Ws,
dsPIC33F dsPIC33E
#bit4
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Ws [W0 ... W15]
bit4 [0 ... 15]
Operands:
Operation:
Status Affected:
None
Encoding:
1010
Description:
0110
bbbb
Bit bit4 in Ws is tested. If the tested bit is 1, the next instruction (fetched
during the current instruction execution) is discarded and on the next
cycle, a NOP is executed instead. If the tested bit is 0, the next instruction
is executed as normal. In either case, the contents of Ws are not changed.
For the bit4 operand, bit numbering begins with the Least Significant bit
(bit 0) and advances to the Most Significant bit (bit 15) of the word. Either
register direct or indirect addressing may be used for Ws.
The b bits select the value bit4, the bit position to test.
The s bits select the source register.
The p bits select the source Address mode.
Note:
Words:
Cycles:
Example 1:
002000 HERE:
002002
002004
002006
002008 BYPASS:
00200A
PC
W0
SR
Before
Instruction
00 2000
264F
0000
BTSS
GOTO
. . .
. . .
. . .
. . .
W0, #0x0
BYPASS
; If bit 0 of W0 is 1,
; skip the GOTO
After
Instruction
PC
00 2006
W0
264F
SR
0000
5
Instruction
Descriptions
DS70157E-page 169
002000 HERE:
002002
002004
002006
002008 BYPASS:
00200A
PC
W6
SR
Example 3:
DS70157E-page 170
Before
Instruction
00 2000
264F
0000
003400 HERE:
003402
003404
003406
003408 BYPASS:
00340A
PC
W6
Data 1800
SR
BTSS
GOTO
. . .
. . .
. . .
. . .
Before
Instruction
00 3400
1800
1000
0000
W6, #0xF
BYPASS
PC
W6
SR
BTSS
GOTO
. . .
. . .
. . .
. . .
; If bit 15 of W6 is 1,
; skip the GOTO
After
Instruction
00 2002
264F
0000
[W6++], 0xC
BYPASS
PC
W6
Data 1800
SR
; If bit 12 of [W6] is 1,
; skip the GOTO
; Post-increment W6
After
Instruction
00 3406
1802
1000
0000
BTST
Bit Test f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
(f)<bit4> Z
Status Affected:
Encoding:
1010
Description:
BTST{.B}
1011
f,
dsPIC33F dsPIC33E
X
ffff
fffb
#bit4
bbbf
ffff
Bit bit4 in file register f is tested and the complement of the tested bit is
stored to the Z flag in the STATUS register. The contents of the file
register are not changed. For the bit4 operand, bit numbering begins with
the Least Significant bit (bit 0) and advances to the Most Significant bit
(bit 7 for byte operation, bit 15 for word operation).
The b bits select value bit4, the bit position to be tested.
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: When this instruction operates in Word mode, the file register
address must be word-aligned.
3: When this instruction operates in Byte mode, bit4 must be
between 0 and 7.
Words:
Cycles:
Example 1:
BTST.B
0x1201, #0x3
Before
Instruction
Data 1200
F7FF
SR
0000
Example 2:
BTST
; Set Z = complement of
; bit 3 in 0x1201
After
Instruction
Data 1200 F7FF
SR
0002 (Z = 1)
0x1302, #0x7
; Set Z = complement of
; bit 7 in 0x1302
Before
After
Instruction
Instruction
Data 1302
F7FF
Data 1302 F7FF
SR
0002 (Z = 1)
SR 0000
Instruction
Descriptions
DS70157E-page 171
BTST
Bit Test in Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
Z000
0ppp
ssss
{label:}
BTST.C
Ws,
BTST.Z
[Ws],
dsPIC33F dsPIC33E
#bit4
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
For .C operation:
(Ws)<bit4> C
For .Z operation (default):
(Ws)<bit4> Z
Status Affected:
Z or C
Encoding:
Description:
1010
0011
bbbb
Words:
Cycles:
Example 1:
BTST.C
[W0++], #0x3
Before
After
Instruction
Instruction
W0
1200
W0
1202
Data 1200
FFF7
Data 1200 FFF7
SR
0001 (C = 1)
SR
0000
DS70157E-page 172
BTST.Z
W0, #0x7
Before
Instruction
W0
F234
SR
0000
After
Instruction
W0
F234
SR
0002 (Z = 1)
5
Instruction
Descriptions
DS70157E-page 173
BTST
Bit Test in Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
w000
0ppp
ssss
{label:}
BTST.C
BTST.Z
Ws,
dsPIC33F dsPIC33E
Wb
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
For .C operation:
(Ws)<(Wb)> C
For .Z operation (default):
(Ws)<(Wb)> Z
Status Affected:
Z or C
Encoding:
Description:
1010
0101
Zwww
Words:
Cycles:
Example 1:
BTST.C
W2, W3
Before
Instruction
W2
F234
W3
2368
SR
0001 (C = 1)
DS70157E-page 174
; Set C = bit W3 of W2
After
Instruction
W2 F234
W3 2368
SR 0000
BTST.Z
[W0++], W1
; Set Z = complement of
; bit W1 in [W0],
; Post-increment W0
Before
After
Instruction
Instruction
W0
1200
W0 1202
W1 CCC0
W1 CCC0
Data 1200
6243
Data 1200 6243
SR
0002 (Z = 1)
SR 0000
5
Instruction
Descriptions
DS70157E-page 175
BTSTS
Bit Test/Set f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
(f)<bit4> Z
1 (f)<bit4>
Status Affected:
Encoding:
1010
Description:
BTSTS{.B} f,
1100
dsPIC33F dsPIC33E
X
ffff
fffb
#bit4
bbbf
ffff
Bit bit4 in file register f is tested and the complement of the tested bit is
stored to the Zero flag in the STATUS register. The tested bit is then set
to 1 in the file register. For the bit4 operand, bit numbering begins with
the Least Significant bit (bit 0) and advances to the Most Significant bit
(bit 7 for byte operations, bit 15 for word operations).
The b bits select value bit4, the bit position to test/set.
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: When this instruction operates in Word mode, the file register
address must be word-aligned.
3: When this instruction operates in Byte mode, bit4 must be
between 0 and 7.
4: The file register f must not be the CPU Status (SR) register.
Words:
Cycles:
Example 1:
BTSTS.B
Before
Instruction
Data 1200
F7FF
SR
0000
Example 2:
BTSTS
After
Instruction
Data 1200 FFFF
SR
0002 (Z = 1)
0x808, #15
Before
After
Instruction
Instruction
RAM300
8050
RAM300
8050
SR
0002 (Z = 1)
SR
0000
DS70157E-page 176
BTSTS
Bit Test/Set in Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
Z000
0ppp
ssss
{label:}
BTSTS.C
BTSTS.Z
Ws,
dsPIC33F dsPIC33E
#bit4
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
For .C operation:
(Ws)<bit4> C
1 Ws<bit4>
For .Z operation (default):
(Ws)<bit4> Z
1 Ws<bit4>
Status Affected:
Z or C
Encoding:
Description:
1010
0100
bbbb
Words:
Cycles:
Example 1:
BTSTS.C
[W0++], #0x3
5
Instruction
Descriptions
Before
After
Instruction
Instruction
W0
1200
W0
1202
Data 1200
FFF7
Data 1200
FFFF
SR
0001 (C = 1)
SR
0000
DS70157E-page 177
BTSTS.Z
W0, #0x7
Before
Instruction
W0
F234
SR
0000
DS70157E-page 178
After
Instruction
W0 F2BC
SR
0002 (Z = 1)
CALL
Call Subroutine
Implemented in:
PIC24F
X
PIC24H
X
dsPIC30F
X
dsPIC33F
X
dsPIC33E
Syntax:
{label:}
Operands:
Operation:
Status Affected:
Encoding:
1st word
2nd word
Description:
CALL
PIC24E
Expr
0000
0010
nnnn
nnnn
nnnn
nnn0
0000
0000
0000
0000
0nnn
nnnn
Direct subroutine call over the entire 4-Mbyte instruction program
memory range. Before the CALL is made, the 24-bit return address
(PC + 4) is PUSHed onto the stack. After the return address is
stacked, the 23-bit value lit23 is loaded into the PC.
The n bits form the target address.
Note:
Words:
Cycles:
The linker will resolve the specified expression into the lit23 to
be used.
2
2
Example 1:
026000
026004
.
.
026844 _FIR:
026846
PC
W15
Data A268
Data A26A
SR
Before
Instruction
02 6000
A268
FFFF
FFFF
0000
CALL
MOV
...
...
MOV
...
_FIR
W0, W1
#0x400, W2
PC
W15
Data A268
Data A26A
SR
After
Instruction
02 6844
A26C
6004
0002
0000
5
Instruction
Descriptions
DS70157E-page 179
072000
072004
.
077A28 _G66:
077A2A
077A2C
PC
W15
Data 9004
Data 9006
SR
DS70157E-page 180
Before
Instruction
07 2000
9004
FFFF
FFFF
0000
CALL
MOV
...
INC
...
_G66
W0, W1
W6, [W7++]
; routine start
PC
W15
Data 9004
Data 9006
SR
After
Instruction
07 7A28
9008
2004
0007
0000
CALL
Call Subroutine
Implemented in:
PIC24F
PIC24H
dsPIC30F
dsPIC33F
dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Status Affected:
Encoding:
1st word
2nd word
Description:
CALL
PIC24E
X
Expr
0000
0010
nnnn
nnnn
nnnn
nnn0
0000
0000
0000
0000
0nnn
nnnn
Direct subroutine call over the entire 4-Mbyte instruction program
memory range. Before the CALL is made, the 24-bit return address
(PC + 4) is PUSHed onto the stack. After the return address is
stacked, the 23-bit value lit23 is loaded into the PC.
The n bits form the target address.
Note:
Words:
Cycles:
The linker will resolve the specified expression into the lit23 to
be used.
2
4
Example 1:
026000
026004
.
.
026844 _FIR:
026846
PC
W15
Data A268
Data A26A
SR
Before
Instruction
02 6000
A268
FFFF
FFFF
0000
CALL
MOV
...
...
MOV
...
_FIR
W0, W1
#0x400, W2
PC
W15
Data A268
Data A26A
SR
After
Instruction
02 6844
A26C
6004
0002
0000
5
Instruction
Descriptions
DS70157E-page 181
072000
072004
.
077A28 _G66:
077A2A
077A2C
PC
W15
Data 9004
Data 9006
SR
DS70157E-page 182
Before
Instruction
07 2000
9004
FFFF
FFFF
0000
CALL
MOV
...
INC
...
_G66
W0, W1
W6, [W7++]
; routine start
PC
W15
Data 9004
Data 9006
SR
After
Instruction
07 7A28
9008
2004
0007
0000
CALL
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(PC) + 2 PC
(PC<15:0>) TOS
(W15) + 2 W15
(PC<23:16>) TOS
(W15) + 2 W15
0 PC<22:16>
(Wn<15:1>) PC<15:1>
NOP Instruction Register
Status Affected:
None
Encoding:
0000
Description:
CALL
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
Wn
0001
0000
ssss
Indirect subroutine call over the first 32K instructions of program memory.
Before the CALL is made, the 24-bit return address (PC + 2) is PUSHed
onto the stack. After the return address is stacked, Wn<15:1> is loaded
into PC<15:1> and PC<22:16> is cleared. Since PC<0> is always 0,
Wn<0> is ignored.
The s bits select the source register.
Words:
Cycles:
Example
1:
001002
001004
.
001600 _BOOT:
001602
.
PC
W0
W15
Data 6F00
Data 6F02
SR
Before
Instruction
00 1002
1600
6F00
FFFF
FFFF
0000
CALL W0
...
...
MOV #0x400, W2
MOV #0x300, W6
...
PC
W0
W15
Data 6F00
Data 6F02
SR
After
Instruction
00 1600
1600
6F04
1004
0000
0000
5
Instruction
Descriptions
DS70157E-page 183
004200
004202
.
005500 _TEST:
005502
.
PC
W7
W15
Data 6F00
Data 6F02
SR
DS70157E-page 184
Before
Instruction
00 4200
5500
6F00
FFFF
FFFF
0000
CALL
...
...
INC
DEC
...
W7
W1, W2
W1, W3
PC
W7
W15
Data 6F00
Data 6F02
SR
After
Instruction
00 5500
5500
6F04
4202
0000
0000
CALL
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(PC) + 2 PC
(PC<15:1>) TOS, SFA bit TOS<0>
(W15) + 2 W15
(PC<23:16>) TOS
(W15) + 2 W15
0 SFA bit
0 PC<22:16>
(Wn<15:1>) PC<15:1>
NOP Instruction Register
Status Affected:
SFA
Encoding:
0000
Description:
CALL
0001
Wn
0000
0000
0000
ssss
Indirect subroutine call over the first 32K instructions of program memory.
Before the CALL is made, the 24-bit return address (PC + 2) is PUSHed
onto the stack. After the return address is stacked, Wn<15:1> is loaded
into PC<15:1> and PC<22:16> is cleared. Since PC<0> is always 0,
Wn<0> is ignored.
The s bits select the source register.
Words:
Cycles:
Example 1:
001002
001004
.
001600 _BOOT:
001602
.
PC
W0
W15
Data 6F00
Data 6F02
SR
Before
Instruction
00 1002
1600
6F00
FFFF
FFFF
0000
CALL W0
...
...
MOV #0x400, W2
MOV #0x300, W6
...
PC
W0
W15
Data 6F00
Data 6F02
SR
After
Instruction
00 1600
1600
6F04
1004
0000
0000
5
Instruction
Descriptions
DS70157E-page 185
004200
004202
.
005500 _TEST:
005502
.
PC
W7
W15
Data 6F00
Data 6F02
SR
DS70157E-page 186
Before
Instruction
00 4200
5500
6F00
FFFF
FFFF
0000
CALL
...
...
INC
DEC
...
W7
W1, W2
W1, W3
PC
W7
W15
Data 6F00
Data 6F02
SR
After
Instruction
00 5500
5500
6F04
4202
0000
0000
CALL.L
Implemented in:
PIC24F
PIC24H
dsPIC30F
dsPIC33F
dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Status Affected:
Encoding:
Description:
Words:
Cycles:
CALL.L
PIC24E
X
Wn
1
4
Example 1:
026000
026004
.
.
026844 _FIR:
026846
PC
W4
W5
W15
Data A268
Data A26A
SR
Before
Instruction
02 6000
6844
0002
A268
FFFF
FFFF
0000
CALL.L W4
MOV
W0, W1
...
...
MOV
#0x400, W2
...
PC
W4
W5
W15
Data A268
Data A26A
SR
After
Instruction
02 6844
6844
0002
A26C
6004
0002
0000
5
Instruction
Descriptions
DS70157E-page 187
CLR
Clear f or WREG
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
ffff
ffff
ffff
{label:}
CLR{.B}
dsPIC33F dsPIC33E
f
WREG
Operands:
f [0 ... 8191]
Operation:
0 destination designated by D
Status Affected:
None
Encoding:
Description:
1110
1111
0BDf
Clear the contents of a file register or the default working register WREG.
If WREG is specified, the WREG is cleared. Otherwise, the specified file
register f is cleared.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
CLR.B
RAM200
Before
Instruction
RAM200 8009
SR 0000
Example 2:
CLR
WREG
Before
Instruction
WREG
0600
SR
0000
DS70157E-page 188
After
Instruction
RAM200 8000
SR 0000
; Clear WREG (Word mode)
After
Instruction
WREG
0000
SR
0000
CLR
Clear Wd
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
qddd
d000
0000
{label:}
CLR{.B}
dsPIC33F dsPIC33E
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
0 Wd
Status Affected:
None
Encoding:
1110
Description:
1011
0Bqq
Words:
Cycles:
Example 1:
CLR.B
W2
Before
Instruction
W2 3333
SR 0000
Example 2:
CLR
[W0++]
Before
Instruction
W0
2300
Data 2300
5607
SR
0000
After
Instruction
W2 3300
SR 0000
; Clear [W0]
; Post-increment W0
After
Instruction
W0
2302
Data 2300
0000
SR
0000
5
Instruction
Descriptions
DS70157E-page 189
CLR
Implemented in:
Syntax:
{label:}
PIC24F
CLR
PIC24H
Acc
PIC24E
{,[Wx],Wxd}
dsPIC30F
dsPIC33F
dsPIC33E
{,[Wy],Wyd}
{,AWB}
Acc [A,B]
Wx [W8, W9]; kx [-6, -4, -2, 2, 4, 6]; Wxd [W4 ... W7]
Wy [W10, W11]; ky [-6, -4, -2, 2, 4, 6]; Wyd [W4 ... W7]
AWB [W13, [W13] + = 2]
Operation:
0 Acc(A or B)
([Wx]) Wxd; (Wx) +/ kx Wx
([Wy]) Wyd; (Wy) +/ ky Wy
(Acc(B or A)) rounded AWB
Status Affected:
Encoding:
Description:
1100
0011
A0xx
yyii
iijj
jjaa
DS70157E-page 190
Words:
Cycles:
CLR
W4
W8
W13
ACCA
ACCB
Data 2000
SR
Example
2:
CLR
W6
W7
W8
W10
W13
ACCA
ACCB
Data 2000
Data 3000
Data 4000
SR
Before
Instruction
F001
2000
C623
00 0067 2345
00 5420 3BDD
1221
0000
; Clear ACCA
; Load W4 with [W8], post-inc W8
; Store ACCB to W13
W4
W8
W13
ACCA
ACCB
Data 2000
SR
After
Instruction
1221
2002
5420
00 0000 0000
00 5420 3BDD
1221
0000
Before
Instruction
F001
C783
2000
3000
4000
00 0067 2345
00 5420 ABDD
1221
FF80
FFC3
0000
W6
W7
W8
W10
W13
ACCA
ACCB
Data 2000
Data 3000
Data 4000
SR
;
;
;
;
;
Clear ACCB
Load W6 with [W8]
Load W7 with [W10]
Save ACCA to [W13]
Post-inc W8,W10,W13
After
Instruction
1221
FF80
2002
3002
4002
00 0067 2345
00 0000 0000
1221
FF80
0067
0000
5
Instruction
Descriptions
DS70157E-page 191
CLRWDT
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
0110
0000
0000
0000
Syntax:
{label:}
Operands:
None
Operation:
Status Affected:
None
Encoding:
1111
CLRWDT
1110
Description:
Clear the contents of the Watchdog Timer count register and the
prescaler count registers. The Watchdog Prescaler A and Prescaler B
settings, set by configuration fuses in the FWDT, are not changed.
Words:
Cycles:
Example 1:
CLRWDT
Before
Instruction
SR 0000
DS70157E-page 192
dsPIC33F dsPIC33E
After
Instruction
SR 0000
COM
Complement f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
N, Z
Encoding:
Description:
COM{.B}
1110
1110
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
1BDf
ffff
Compute the 1s complement of the contents of the file register and place
the result in the destination register. The optional WREG operand
determines the destination register. If WREG is specified, the result is
stored in WREG. If WREG is not specified, the result is stored in the file
register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
COM.b
RAM200
Before
Instruction
RAM200 80FF
SR 0000
Example 2:
COM
After
Instruction
RAM200 8000
SR 0002 (Z)
RAM400, WREG
Before
Instruction
WREG
1211
RAM400
0823
SR
0000
After
Instruction
WREG F7DC
RAM400
0823
SR
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 193
COM
Complement Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
COM{.B}
Operands:
Operation:
(Ws) Wd
Status Affected:
N, Z
Encoding:
1110
Description:
1010
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
1Bqq
qddd
dsPIC33F dsPIC33E
X
dppp
ssss
Words:
Cycles:
Example 1:
COM.B
[W0++], [W1++]
Before
Instruction
W0
2301
W1
2400
Data 2300
5607
Data 2400
ABCD
SR
0000
DS70157E-page 194
After
Instruction
W0
2302
W1
2401
Data 2300
5607
Data 2400
ABA9
SR
0008 (N = 1)
COM
W0, [W1++]
Before
Instruction
W0
D004
W1
1000
Data 1000
ABA9
SR
0000
After
Instruction
W0
D004
W1
1002
Data 1000
2FFB
SR
0000
5
Instruction
Descriptions
DS70157E-page 195
CP
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
0B0f
ffff
ffff
ffff
Syntax:
{label:}
Operands:
f [0 ...8191]
Operation:
(f) (WREG)
Status Affected:
DC, N, OV, Z, C
Encoding:
CP{.B}
1110
Description:
0011
dsPIC33F dsPIC33E
Compute (f) (WREG) and update the STATUS register. This instruction
is equivalent to the SUBWF instruction, but the result of the subtraction is
not stored.
The B bit selects byte or word operation (0 for word, 1 for byte).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
CP.B
RAM400
Before
Instruction
WREG
8823
RAM400
0823
SR
0000
Example 2:
CP
0x1200
Before
Instruction
WREG
2377
Data 1200
2277
SR
0000
DS70157E-page 196
After
Instruction
WREG
8823
RAM400
0823
SR
0002 (Z = 1)
; Compare (0x1200) with WREG (Word mode)
After
Instruction
WREG
2377
Data 1200
2277
SR
0008 (N = 1)
CP
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(Wb) lit5
Status Affected:
DC, N, OV, Z, C
Encoding:
CP{.B}
1110
Description:
0001
PIC24E
Wb,
0www
dsPIC30F
dsPIC33F dsPIC33E
wB00
011k
#lit5
kkkk
Compute (Wb) lit5, and update the STATUS register. This instruction is
equivalent to the SUB instruction, but the result of the subtraction is not
stored. Register direct addressing must be used for Wb.
The w bits select the address of the Wb base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits provide the literal operand, a five-bit integer number.
Note:
Words:
Cycles:
Example 1:
CP.B
W4, #0x12
Before
Instruction
W4
7711
SR
0000
Example 2:
CP
W4, #0x12
Before
Instruction
W4
7713
SR
0000
After
Instruction
W4
7711
SR
0008 (N = 1)
; Compare W4 with 0x12 (Word mode)
After
Instruction
W4
7713
SR
0000
5
Instruction
Descriptions
DS70157E-page 197
CP
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(Wb) lit8
Status Affected:
DC, N, OV, Z, C
Encoding:
CP{.B}
1110
Description:
0001
Wb,
0www
X
#lit8
wBkk
k11k
kkkk
Compute (Wb) lit8, and update the STATUS register. This instruction is
equivalent to the SUB instruction, but the result of the subtraction is not
stored. Register direct addressing must be used for Wb.
The w bits select the address of the Wb base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits provide the literal operand, a five-bit integer number.
Note:
Words:
Cycles:
Example 1:
CP.B
W4, #0x12
Before
Instruction
W4
7711
SR
0000
Example 2:
CP
W4, #0x12
Before
Instruction
W4
7713
SR
0000
DS70157E-page 198
After
Instruction
W4
7711
SR
0008 (N = 1)
; Compare W4 with 0x12 (Word mode)
After
Instruction
W4
7713
SR
0000
CP
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
CP{.B}
Wb,
dsPIC33F dsPIC33E
X
0ppp
ssss
Ws
[Ws]
[Ws++]
[Ws--]
[++Ws]
[--Ws]
Operands:
Operation:
(Wb) (Ws)
Status Affected:
DC, N, OV, Z, C
Encoding:
1110
Description:
0001
0www
wB00
Compute (Wb) (Ws), and update the STATUS register. This instruction is
equivalent to the SUB instruction, but the result of the subtraction is not
stored. Register direct addressing must be used for Wb. Register direct or
indirect addressing may be used for Ws.
The w bits select the address of the Wb source register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The p bits select the source Address mode.
The s bits select the address of the Ws source register.
Note:
Words:
Cycles:
Example 1:
CP.B
W0, [W1++]
Before
Instruction
W0 ABA9
W1
2000
Data 2000
D004
SR
0000
Example 2:
CP
W5, W6
After
Instruction
W0 ABA9
W1
2001
Data 2000
D004
SR
0008 (N = 1)
; Compare W6 with W5 (Word mode)
After
Instruction
W5
2334
W6
8001
SR
000C (N, OV = 1)
5
Instruction
Descriptions
Before
Instruction
W5
2334
W6
8001
SR
0000
DS70157E-page 199
CP0
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
0B0f
ffff
ffff
ffff
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
(f) 0x0
Status Affected:
DC, N, OV, Z, C
Encoding:
CP0{.B}
1110
Description:
0010
dsPIC33F dsPIC33E
Compute (f) 0x0 and update the STATUS register. The result of the
subtraction is not stored.
The B bit selects byte or word operation (0 for word, 1 for byte).
The f bits select the address of the file register.
Note:
Words:
Cycles:
Example 1:
CP0.B
RAM100
Before
Instruction
RAM100
44C3
SR
0000
Example 2:
CP0
0x1FFE
Before
Instruction
Data 1FFE
0001
SR
0000
DS70157E-page 200
After
Instruction
RAM100
44C3
SR
0008 (N = 1)
; Compare (0x1FFE) with 0x0 (Word mode)
After
Instruction
Data 1FFE
0001
SR
0000
CP0
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
0B00
0ppp
ssss
{label:}
CP0{.B}
dsPIC33F dsPIC33E
Ws
[Ws]
[Ws++]
[Ws--]
[++Ws]
[--Ws]
Operands:
Operation:
(Ws) 0x0000
Status Affected:
DC, N, OV, Z, C
Encoding:
1110
Description:
0000
0000
Compute (Ws) 0x0000 and update the STATUS register. The result of
the subtraction is not stored. Register direct or indirect addressing may be
used for Ws.
The B bit selects byte or word operation (0 for word, 1 for byte).
The p bits select the source Address mode.
The s bits select the address of the Ws source register.
Note:
Words:
Cycles:
Example 1:
CP0.B
[W4--]
Before
Instruction
W4
1001
Data 1000
0034
SR
0000
Example 2:
CP0
[--W5]
After
Instruction
W4
1000
Data 1000
0034
SR
0002 (Z = 1)
; Compare [--W5] with 0 (Word mode)
After
Instruction
W5
23FE
Data 23FE
9000
SR
0008 (N = 1)
5
Instruction
Descriptions
Before
Instruction
W5
2400
Data 23FE
9000
SR
0000
DS70157E-page 201
CPB
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
1B0f
ffff
ffff
ffff
Syntax:
{label:}
Operands:
f [0 ...8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
CPB{.B}
1110
0011
dsPIC33F dsPIC33E
Compute (f) (WREG) (C), and update the STATUS register. This
instruction is equivalent to the SUBB instruction, but the result of the
subtraction is not stored.
Description:
The B bit selects byte or word operation (0 for word, 1 for byte).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
3: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR. These
instructions can only clear Z.
Words:
Cycles:
Example 1:
CPB.B
RAM400
Before
Instruction
WREG
8823
RAM400
0823
SR
0000
Example 2:
CPB
0x1200
After
Instruction
WREG
8823
RAM400
0823
SR
0008 (N = 1)
; Compare (0x1200) with WREG using C (Word mode)
Before
After
Instruction
Instruction
WREG
2377
WREG
2377
Data 1200
2377
Data 1200
2377
SR
0001 (C = 1)
SR
0001 (C = 1)
DS70157E-page 202
CPB
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
CPB{.B}
1110
Description:
0001
PIC24E
Wb,
1www
dsPIC30F
dsPIC33F dsPIC33E
wB00
011k
#lit5
kkkk
Compute (Wb) lit5 (C), and update the STATUS register. This
instruction is equivalent to the SUBB instruction, but the result of the
subtraction is not stored. Register direct addressing must be used for Wb.
The w bits select the address of the Wb source register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits provide the literal operand, a five bit integer number.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR. These
instructions can only clear Z.
Words:
Cycles:
Example 1:
CPB.B
W4, #0x12
Before
Instruction
W4
7711
SR
0001 (C = 1)
Example 2:
CPB.B
W4, #0x12
Before
Instruction
W4
7711
SR
0000
Example 3:
CPB
W12, #0x1F
After
Instruction
W4
7711
SR
0008 (N = 1)
; Compare W4 with 0x12 using C (Byte mode)
After
Instruction
W4
7711
SR
0008 (N = 1)
; Compare W12 with 0x1F using C (Word mode)
After
Instruction
W12
0020
SR
0003 (Z, C = 1)
Instruction
Descriptions
Before
Instruction
W12
0020
SR
0002 (Z = 1)
DS70157E-page 203
CPB
W12, #0x1F
Before
Instruction
W12
0020
SR
0003 (Z, C = 1)
DS70157E-page 204
After
Instruction
W12
0020
SR
0001 (C = 1)
CPB
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
CPB{.B}
1110
Description:
0001
Wb,
1www
X
#lit8
wBkk
k11k
kkkk
Compute (Wb) lit8 (C), and update the STATUS register. This
instruction is equivalent to the SUBB instruction, but the result of the
subtraction is not stored. Register direct addressing must be used for Wb.
The w bits select the address of the Wb source register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits provide the literal operand, a five bit integer number.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR. These
instructions can only clear Z.
Words:
Cycles:
Example 1:
CPB.B
W4, #0x12
Before
Instruction
W4
7711
SR
0001 (C = 1)
Example 2:
CPB.B
W4, #0x12
Before
Instruction
W4
7711
SR
0000
Example 3:
CPB
W12, #0x1F
After
Instruction
W4
7711
SR
0008 (N = 1)
; Compare W4 with 0x12 using C (Byte mode)
After
Instruction
W4
7711
SR
0008 (N = 1)
; Compare W12 with 0x1F using C (Word mode)
After
Instruction
W12
0020
SR
0003 (Z, C = 1)
Instruction
Descriptions
Before
Instruction
W12
0020
SR
0002 (Z = 1)
DS70157E-page 205
CPB
W12, #0x1F
Before
Instruction
W12
0020
SR
0003 (Z, C = 1)
DS70157E-page 206
After
Instruction
W12
0020
SR
0001 (C = 1)
CPB
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
0ppp
ssss
{label:}
CPB{.B}
Wb,
Ws
[Ws]
[Ws++]
[Ws--]
[++Ws]
[--Ws]
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
1110
0001
1www
wB00
Compute (Wb) (Ws) (C), and update the STATUS register. This
instruction is equivalent to the SUBB instruction, but the result of the
subtraction is not stored. Register direct addressing must be used for Wb.
Register direct or indirect addressing may be used for Ws.
The w bits select the address of the Wb source register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The p bits select the source Address mode.
The s bits select the address of the Ws source register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR. These
instructions can only clear Z.
Words:
Cycles:
Example 1:
CPB.B
W0, [W1++]
Before
After
Instruction
Instruction
W0 ABA9
W0 ABA9
W1
1000
W1
1001
Data 1000 D0A9
Data 1000 D0A9
SR
0002 (Z = 1)
SR
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 207
CPB.B
W0, [W1++]
Before
After
Instruction
Instruction
W0 ABA9
W0 ABA9
W1
1000
W1
1001
Data 1000 D0A9
Data 1000 D0A9
SR
0001 (C = 1)
SR
0001 (C = 1)
Example 3:
CPB
W4, W5
Before
Instruction
W4
4000
W5
3000
SR
0001 (C = 1)
DS70157E-page 208
After
Instruction
W4
4000
W5
3000
SR
0001 (C = 1)
CPBEQ
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
If (Wb) = (Wn), [(PC+2) + 2 * Expr] PC and NOP Instruction Register
Status Affected:
None
Encoding:
CPSEQ{.B}
1110
Description:
0111
Wb,
1www
Wn, Expr
wBnn
nnnn
ssss
Words:
Cycles:
1 (5 if branch taken)
Example 1:
PC
W0
W1
SR
Before
Instruction
00 2000
1000
1000
0000
PC
W0
W1
SR
After
Instruction
00 2008
1000
1000
0002 (z = 1)
5
Instruction
Descriptions
DS70157E-page 209
CPBGT
Signed Compare Wb with Wn, Branch if Greater Than (Wb > Wn)
Implemented in:
PIC24F
PIC24H
PIC24E
X
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
If (Wb) = (Wn), [(PC+2) + 2 * Expr] PC and NOP Instruction Register
Status Affected:
None
Encoding:
CPSGT{.B}
1110
Description:
0110
Wb,
0www
Wn, Expr
wBnn
nnnn
ssss
Words:
Cycles:
1 (5 if branch taken)
Example 1:
PC
W0
W1
SR
DS70157E-page 210
Before
Instruction
00 2000
30FF
26FE
0000
PC
W0
W1
SR
After
Instruction
00 2008
00FF
26FE
0000 (N, C = 0)
CPBLT
Signed Compare Wb with Wn, Branch if Less Than (Wb < Wn)
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
If (Wb) = (Wn), [(PC+2) + 2 * Expr] PC and NOP Instruction Register
Status Affected:
None
Encoding:
CPSLT{.B}
1110
Description:
0110
Wb,
1www
Wn, Expr
wBnn
nnnn
ssss
Words:
Cycles:
1 (5 if branch taken)
Example 1:
002000 HERE:
002002
002004
002006
002008 BYPASS:
00200A
PC
W8
W9
SR
Before
Instruction
00 2000
00FF
26FE
0000
PC
W8
W9
SR
After
Instruction
00 2008
00FF
26FE
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 211
CPBNE
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
If (Wb) = (Wn), [(PC+2) + 2 * Expr] PC and NOP Instruction Register
Status Affected:
None
Encoding:
CPSNE{.B}
1110
Description:
0111
Wb,
0www
Wn, Expr
wBnn
nnnn
ssss
Compare the contents of Wb with the contents of Wn by performing the subtraction (Wb) (Wn), but do not store the result. If (Wb) = (Wn), the next
instruction (fetched during the current instruction execution) is discarded,
the PC is recalculated based on the 6-bit signed offset specified by Expr,
and on the next cycle, a NOP is executed instead. If (Wb) (Wn), the next
instruction is executed as normal (branch is not taken).
The w bits select the address of the Wb source register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The s bits select the address of the Ws source register.
The n bits select the offset of the branch destination.
Note:
Words:
Cycles:
1 (5 if branch taken)
Example 1:
002000 HERE:
002002
002004
002006
002008 BYPASS:
00200A
PC
W2
W3
SR
DS70157E-page 212
Before
Instruction
00 2000
00FF
26FE
0000
PC
W2
W3
SR
After
Instruction
00 200A
00FF
26FE
0001 (C = 1)
CPSEQ
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
Skip if (Wb) = (Wn)
Status Affected:
None
Encoding:
CPSEQ{.B}
1110
Description:
0111
PIC24E
Wb,
1www
dsPIC30F
dsPIC33F dsPIC33E
wB00
0000
Wn
ssss
Words:
Cycles:
1 (2 or 3 if skip taken)
Example 1:
PC
W0
W1
SR
Example 2:
018000 HERE:
018002
018006
018008
PC
W0
W1
SR
CPSEQ
CALL
...
...
Before
Instruction
01 8000
3344
3344
0002 (Z = 1)
After
Instruction
00 2002
1001
1000
0000
PC
W4
W8
SR
5
Instruction
Descriptions
PC
W4
W8
SR
Before
Instruction
00 2000
1001
1000
0000
After
Instruction
01 8006
3344
3344
0002 (Z = 1)
DS70157E-page 213
CPSEQ
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
Skip if (Wb) = (Wn)
Status Affected:
None
Encoding:
CPSEQ{.B}
1110
Description:
0111
Wb,
1www
X
Wn
wB00
0001
ssss
Words:
Cycles:
1 (2 or 3 if skip taken)
Example 1:
PC
W0
W1
SR
DS70157E-page 214
Before
Instruction
00 2000
1001
1000
0000
PC
W0
W1
SR
After
Instruction
00 2002
1001
1000
0000
018000 HERE:
018002
018006
018008
PC
W4
W8
SR
CPSEQ
CALL
...
...
Before
Instruction
01 8000
3344
3344
0002 (Z = 1)
PC
W4
W8
SR
After
Instruction
01 8006
3344
3344
0002 (Z = 1)
5
Instruction
Descriptions
DS70157E-page 215
CPSGT
Signed Compare Wb with Wn, Skip if Greater Than (Wb > Wn)
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
Skip if (Wb) > (Wn)
Status Affected:
None
Encoding:
CPSGT{.B}
1110
Description:
PIC24E
Wb,
0110
0www
wB00
0000
Wn
ssss
Words:
Cycles:
1 (2 or 3 if skip taken)
Example 1:
002000 HERE:
002002
002006
002008
00200A BYPASS
00200C
PC
W0
W1
SR
Example 2:
CPSGT.B
GOTO
. . .
. . .
. . .
. . .
Before
Instruction
00 2000
00FF
26FE
0009 (N, C = 1)
018000 HERE:
018002
018006
018008
PC
W4
W5
SR
DS70157E-page 216
CPSGT
CALL
...
...
Before
Instruction
01 8000
2600
2600
0004 (OV = 1)
PC
W0
W1
SR
After
Instruction
00 2006
00FF
26FE
0009 (N, C = 1)
PC
W4
W5
SR
After
Instruction
01 8002
2600
2600
0004 (OV = 1)
CPSGT
Signed Compare Wb with Wn, Skip if Greater Than (Wb > Wn)
Implemented in:
PIC24F
PIC24H
PIC24E
X
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
Skip if (Wb) > (Wn)
Status Affected:
None
Encoding:
CPSGT{.B}
1110
Description:
Wb,
0110
0www
X
Wn
wB00
0001
ssss
Words:
Cycles:
1 (2 or 3 if skip taken)
Example 1:
002000 HERE:
002002
002006
002008
00200A BYPASS
00200C
PC
W0
W1
SR
Example 2:
CPSGT
CALL
...
...
Before
Instruction
01 8000
2600
2600
0004 (OV = 1)
PC
W0
W1
SR
After
Instruction
00 2006
00FF
26FE
0009 (N, C = 1)
PC
W4
W5
SR
After
Instruction
01 8002
2600
2600
0004 (OV = 1)
DS70157E-page 217
5
Instruction
Descriptions
Before
Instruction
00 2000
00FF
26FE
0009 (N, C = 1)
018000 HERE:
018002
018006
018008
PC
W4
W5
SR
CPSGT.B
GOTO
. . .
. . .
. . .
. . .
CPSLT
Signed Compare Wb with Wn, Skip if Less Than (Wb < Wn)
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
Skip if (Wb) < (Wn)
Status Affected:
None
Encoding:
CPSLT{.B}
1110
Description:
0110
PIC24E
Wb,
1www
dsPIC30F
dsPIC33F dsPIC33E
wB00
0000
Wn
ssss
Words:
Cycles:
1 (2 or 3 if skip taken)
Example 1:
002000 HERE:
002002
002006
002008
00200A BYPASS:
00200C
PC
W8
W9
SR
Example 2:
CPSLT.B
GOTO
. . .
. . .
. . .
. . .
Before
Instruction
00 2000
00FF
26FE
0008 (N = 1)
018000 HERE:
018002
018006
018008
PC
W3
W6
SR
DS70157E-page 218
CPSLT
CALL
. . .
. . .
Before
Instruction
01 8000
2600
3000
0000
PC
W8
W9
SR
After
Instruction
00 2002
00FF
26FE
0008 (N = 1)
PC
W3
W6
SR
After
Instruction
01 8006
2600
3000
0000
CPSLT
Signed Compare Wb with Wn, Skip if Less Than (Wb < Wn)
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
Skip if (Wb) < (Wn)
Status Affected:
None
Encoding:
CPSLT{.B}
1110
Description:
0110
Wb,
1www
X
Wn
wB00
0001
ssss
Words:
Cycles:
1 (2 or 3 if skip taken)
Example 1:
002000 HERE:
002002
002006
002008
00200A BYPASS:
00200C
PC
W8
W9
SR
Example 2:
CPSLT
CALL
. . .
. . .
Before
Instruction
01 8000
2600
3000
0000
PC
W8
W9
SR
After
Instruction
00 2002
00FF
26FE
0008 (N = 1)
PC
W3
W6
SR
5
Instruction
Descriptions
Before
Instruction
00 2000
00FF
26FE
0008 (N = 1)
018000 HERE:
018002
018006
018008
PC
W3
W6
SR
CPSLT.B
GOTO
. . .
. . .
. . .
. . .
After
Instruction
01 8006
2600
3000
0000
DS70157E-page 219
CPSNE
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
Skip if (Wb) (Wn)
Status Affected:
None
Encoding:
CPSNE{.B}
1110
Description:
PIC24E
0111
Wb,
0www
dsPIC30F
dsPIC33F dsPIC33E
wB00
0000
Wn
ssss
Words:
Cycles:
1 (2 or 3 if skip taken)
Example 1:
002000 HERE:
002002
002006
002008
00200A BYPASS:
00200C
PC
W2
W3
SR
Example 2:
CPSNE.B
GOTO
. . .
. . .
. . .
. . .
Before
Instruction
00 2000
00FF
26FE
0001 (C = 1)
018000 HERE:
018002
018006
018008
PC
W0
W8
SR
DS70157E-page 220
Before
Instruction
01 8000
3000
3000
0000
CPSNE
CALL
...
...
PC
W2
W3
SR
After
Instruction
00 2006
00FF
26FE
0001 (C = 1)
PC
W0
W8
SR
After
Instruction
01 8002
3000
3000
0000
CPSNE
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(Wb) (Wn)
Skip if (Wb) (Wn)
Status Affected:
None
Encoding:
CPSNE{.B}
1110
Description:
0111
Wb,
0www
X
Wn
wB00
0001
ssss
Words:
Cycles:
1 (2 or 3 if skip taken)
Example 1:
002000 HERE:
002002
002006
002008
00200A BYPASS:
00200C
PC
W2
W3
SR
Example 2:
Before
Instruction
01 8000
3000
3000
0000
CPSNE
CALL
...
...
PC
W2
W3
SR
After
Instruction
00 2006
00FF
26FE
0001 (C = 1)
PC
W0
W8
SR
5
Instruction
Descriptions
Before
Instruction
00 2000
00FF
26FE
0001 (C = 1)
018000 HERE:
018002
018006
018008
PC
W0
W8
SR
CPSNE.B
GOTO
. . .
. . .
. . .
. . .
After
Instruction
01 8002
3000
3000
0000
DS70157E-page 221
DAW.B
Decimal Adjust Wn
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
0100
0000
0000
ssss
Syntax:
{label:}
DAW.B
Operands:
Operation:
dsPIC33F dsPIC33E
Wn
If (Wn<7:4> > 9) or (C = 1)
(Wn<7:4>) + 6 Wn<7:4>
Else
(Wn<7:4>) Wn<7:4>
Status Affected:
Encoding:
Description:
1111
1101
Words:
Cycles:
Example 1:
DAW.B
W0
; Decimal adjust W0
Before
Instruction
W0 771A
SR
0002 (DC = 1)
Example 2:
DAW.B
W3
Before
Instruction
W3 77AA
SR
0000
DS70157E-page 222
After
Instruction
W0
7720
SR
0002 (DC = 1)
; Decimal adjust W3
After
Instruction
W3
7710
SR
0001 (C = 1)
DEC
Decrement f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
DEC{.B}
1110
Description:
1101
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
0BDf
ffff
Subtract one from the contents of the file register and place the result in the
destination register. The optional WREG operand determines the
destination register. If WREG is specified, the result is stored in WREG. If
WREG is not specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
DEC.B
0x200
Before
Instruction
Data 200 80FF
SR
0000
Example 2:
DEC
After
Instruction
Data 200 80FE
SR
0009 (N, C = 1)
RAM400, WREG
Before
Instruction
WREG
1211
RAM400
0823
SR
0000
After
Instruction
WREG
0822
RAM400
0823
SR
0000
5
Instruction
Descriptions
DS70157E-page 223
DEC
Decrement Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
DEC{.B}
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
dppp
ssss
Operands:
Operation:
(Ws) 1 Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
Ws,
dsPIC33F dsPIC33E
1110
1001
0Bqq
qddd
Subtract one from the contents of the source register Ws and place the
result in the destination register Wd. Either register direct or indirect
addressing may be used by Ws and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
DEC.B
[W7++], [W8++]
Before
Instruction
W7
2301
W8
2400
Data 2300
5607
Data 2400 ABCD
SR
0000
DS70157E-page 224
After
Instruction
W7
2302
W8
2401
Data 2300
5607
Data 2400
AB55
SR
0000
DEC
W5, [W6++]
Before
Instruction
W5
D004
W6
2000
Data 2000 ABA9
SR
0000
After
Instruction
W5
D004
W6
2002
Data 2000
D003
SR
0009 (N, C = 1)
5
Instruction
Descriptions
DS70157E-page 225
DEC2
Decrement f by 2
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
DEC2{.B}
1110
Description:
1101
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
1BDf
ffff
Subtract two from the contents of the file register and place the result in the
destination register. The optional WREG operand determines the
destination register. If WREG is specified, the result is stored in WREG. If
WREG is not specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note:
Words:
Cycles:
Example 1:
DEC2.B
0x200
Before
Instruction
Data 200 80FF
SR
0000
Example 2:
DEC2
After
Instruction
Data 200 80FD
SR
0009 (N, C = 1)
RAM400, WREG
Before
Instruction
WREG
1211
RAM400
0823
SR
0000
DS70157E-page 226
After
Instruction
WREG
0821
RAM400
0823
SR
0000
DEC2
Decrement Ws by 2
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
DEC2{.B}
Operands:
Operation:
(Ws) 2 Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
1110
Description:
1001
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
1Bqq
qddd
dsPIC33F dsPIC33E
X
dppp
ssss
Subtract two from the contents of the source register Ws and place the
result in the destination register Wd. Either register direct or indirect
addressing may be used by Ws and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
Before
Instruction
W7
2301
W8
2400
Data 2300
0107
Data 2400 ABCD
SR
0000
Example 2:
DEC2
W5, [W6++]
After
Instruction
W5
D004
W6
1002
Data 1000
D002
SR
0009 (N, C = 1)
5
Instruction
Descriptions
Before
Instruction
W5
D004
W6
1000
Data 1000 ABA9
SR
0000
After
Instruction
W7
2300
W8
23FF
Data 2300
0107
Data 2400
ABFF
SR
0008 (N = 1)
DS70157E-page 227
DISI
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
kkkk
kkkk
kkkk
Syntax:
{label:}
Operands:
Operation:
lit14 DISICNT
1 DISI
Disable interrupts for (lit14 + 1) cycles
Status Affected:
None
Encoding:
1111
Description:
Words:
Cycles:
Example 1:
#lit14
1100
00kk
002000 HERE:
002002
002004
PC
DISICNT
INTCON2
SR
DS70157E-page 228
DISI
dsPIC33F dsPIC33E
Before
Instruction
00 2000
0000
0000
0000
DISI
#100
. . .
PC
DISICNT
INTCON2
SR
After
Instruction
00 2002
0100
4000 (DISI = 1)
0000
DIV.S
Implemented in:
Syntax:
PIC24H
PIC24E
dsPIC30F
{label:}
DIV.S{W}
Wm, Wn
DIV.SD
Wm, Wn
Operands:
Operation:
dsPIC33F dsPIC33E
X
vW00
ssss
N, OV, Z, C
1101
1000
0ttt
tvvv
DS70157E-page 229
5
Instruction
Descriptions
Cycles:
Example 1:
REPEAT #17
DIV.S W3, W4
Before
Instruction
W0
5555
W1
1234
W3
3000
W4
0027
SR
0000
Example 2:
REPEAT
DIV.SD
#17
W0, W12
Before
Instruction
W0
2500
W1
FF42
W12
2200
SR
0000
DS70157E-page 230
After
Instruction
W0
013B
W1
0003
W3
3000
W4
0027
SR
0000
; Execute DIV.SD 18 times
; Divide W1:W0 by W12
; Store quotient to W0, remainder to W1
After
Instruction
W0
FA6B
W1
EF00
W12
2200
SR
0008 (N = 1)
DIV.U
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
DIV.U{W}
Wm, Wn
DIV.UD
Wm, Wn
Operands:
Operation:
dsPIC33F dsPIC33E
X
vW00
ssss
N, OV, Z, C
Encoding:
Description:
1101
1000
1ttt
tvvv
Words:
Cycles:
DS70157E-page 231
5
Instruction
Descriptions
REPEAT #17
DIV.U W2, W4
Before
Instruction
W0
5555
W1
1234
W2
8000
W4
0200
SR
0000
Example 2:
REPEAT
DIV.UD
#17
W10, W12
Before
Instruction
W0
5555
W1
1234
W10
2500
W11
0042
W12
2200
SR
0000
DS70157E-page 232
After
Instruction
W0
0040
W1
0000
W2
8000
W4
0200
SR
0002 (Z = 1)
; Execute DIV.UD 18 times
; Divide W11:W10 by W12
; Store quotient to W0, remainder to W1
After
Instruction
W0
01F2
W1
0100
W10
2500
W11
0042
W12
2200
SR
0000
DIVF
Fractional Divide
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Wm W0 ... W15]
Wn W2 ... W15]
Operation:
0x0 W0
Wm W1
W1:W0/Wn W0
Remainder W1
Status Affected:
N, OV, Z, C
Encoding:
Description:
1101
DIVF
1001
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
t000
0000
ssss
Wm, Wn
0ttt
Words:
Cycles:
5
Instruction
Descriptions
DS70157E-page 233
REPEAT
DIVF
#17
W8, W9
Before
Instruction
W0
8000
W1
1234
W8
1000
W9
4000
SR
0000
Example 2:
REPEAT #17
DIVF
W8, W9
Before
Instruction
W0
8000
W1
1234
W8
1000
W9
8000
SR
0000
Example 3:
REPEAT #17
DIVF
W0, W1
Before
Instruction
W0
8002
W1
8001
SR
0000
DS70157E-page 234
After
Instruction
W0
2000
W1
0000
W8
1000
W9
4000
SR
0002 (Z = 1)
; Execute DIVF 18 times
; Divide W8 by W9
; Store quotient to W0, remainder to W1
After
Instruction
W0
F000
W1
0000
W8
1000
W9
8000
SR
0002 (Z = 1)
; Execute DIVF 18 times
; Divide W0 by W1
; Store quotient to W0, remainder to W1
After
Instruction
W0
7FFE
W1
8002
SR
0008 (N = 1)
DO
Implemented in:
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Status Affected:
DA
Encoding:
Description:
DO
#lit14,
Expr
0000
1000
00kk
kkkk
kkkk
kkkk
0000
0000
nnnn
nnnn
nnnn
nnnn
DS70157E-page 235
5
Instruction
Descriptions
Cycles:
Example 1:
002000 LOOP6:
002004
002006
002008
00200A END6:
00200C
PC
DCOUNT
DOSTART
DOEND
CORCON
SR
Example 2:
Before
Instruction
00 2000
0000
FF FFFF
FF FFFF
0000
0001 (C = 1)
PC
DCOUNT
DOSTART
DOEND
CORCON
SR
After
Instruction
00 2004
0005
00 2004
00 200A
0100 (DL = 1)
0201 (DA, C = 1)
PC
DCOUNT
DOSTART
DOEND
CORCON
SR
DS70157E-page 236
DO
#5, END6; Initiate DO loop (6 reps)
ADD
W1, W2, W3; First instruction in loop
. . .
. . .
SUB
W2, W3, W4; Last instruction in loop
. . .
Before
Instruction
01 C000
0000
FF FFFF
FF FFFF
0000
0008 (N = 1)
PC
DCOUNT
DOSTART
DOEND
CORCON
SR
After
Instruction
01 C004
0160
01 C004
01 C014
0100 (DL = 1)
0208 (DA, N = 1)
DO
Implemented in:
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Status Affected:
DA
Encoding:
Description:
DO
#lit15,
Expr
0000
1000
0kkk
kkkk
kkkk
kkkk
0000
0000
nnnn
nnnn
nnnn
nnnn
DS70157E-page 237
5
Instruction
Descriptions
5.
Cycles:
Example 1:
002000 LOOP6:
002004
002006
002008
00200A END6:
00200C
PC
DCOUNT
DOSTART
DOEND
CORCON
SR
Example 2:
Before
Instruction
00 2000
0000
FF FFFF
FF FFFF
0000
0001 (C = 1)
PC
DCOUNT
DOSTART
DOEND
CORCON
SR
After
Instruction
00 2004
0005
00 2004
00 200A
0100 (DL = 1)
0201 (DA, C = 1)
PC
DCOUNT
DOSTART
DOEND
CORCON
SR
DS70157E-page 238
DO
#5, END6; Initiate DO loop (6 reps)
ADD
W1, W2, W3; First instruction in loop
. . .
. . .
SUB
W2, W3, W4; Last instruction in loop
. . .
Before
Instruction
01 C000
0000
FF FFFF
FF FFFF
0000
0008 (N = 1)
PC
DCOUNT
DOSTART
DOEND
CORCON
SR
After
Instruction
01 C004
0160
01 C004
01 C014
0100 (DL = 1)
0208 (DA, N = 1)
DO
Implemented in:
PIC24F
PIC24H
dsPIC33F
dsPIC33E
{label:}
Operands:
Operation:
Status Affected:
DA
Description:
Wn,
dsPIC30F
Syntax:
Encoding:
DO
PIC24E
Expr
0000
1000
1000
0000
0000
ssss
0000
0000
nnnn
nnnn
nnnn
nnnn
2: The linker will convert the specified expression into the offset to
be used.
Words:
Cycles:
DS70157E-page 239
5
Instruction
Descriptions
002000 LOOP6:
002004
002006
002008
00200A
00200C
00200E
002010 END6:
PC
W0
DCOUNT
DOSTART
DOEND
CORCON
SR
Example 2:
DS70157E-page 240
Before
Instruction
00 2000
0012
0000
FF FFFF
FF FFFF
0000
0000
002000 LOOPA:
002004
002006
002008
00200A
002010 ENDA:
PC
W7
DCOUNT
DOSTART
DOEND
CORCON
SR
DO
ADD
. . .
. . .
. . .
REPEAT
SUB
NOP
Before
Instruction
00 2000
E00F
0000
FF FFFF
FF FFFF
0000
0000
W0, END6
; Initiate DO loop (W0 reps)
W1, W2, W3 ; First instruction in loop
#6
W2, W3, W4
; Last instruction in loop
; (Required NOP filler)
PC
W0
DCOUNT
DOSTART
DOEND
CORCON
SR
DO
SWAP
. . .
. . .
. . .
MOV
W7, ENDA
W0
After
Instruction
00 2004
0012
0012
00 2004
00 2010
0100 (DL = 1)
0080 (DA = 1)
; Initiate DO loop (W7 reps)
; First instruction in loop
PC
W7
DCOUNT
DOSTART
DOEND
CORCON
SR
After
Instruction
00 2004
E00F
200F
00 2004
00 2010
0100 (DL = 1)
0080 (DA = 1)
DO
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Status Affected:
DA
Encoding:
Description:
DO
Wn,
Expr
0000
1000
1000
0000
0000
ssss
0000
0000
nnnn
nnnn
nnnn
nnnn
Cycles:
DS70157E-page 241
5
Instruction
Descriptions
Words:
The first instruction of the DO loop cannot be a PSV read or Table read.
Note 1: The DO instruction is interruptible and supports 1 level of nesting.
Nesting up to an additional 5 levels may be provided in software
by the user. See the specific device family reference manual for
details.
2: The linker will convert the specified expression into the offset to
be used.
002000 LOOP6:
002004
002006
002008
00200A
00200C
00200E
002010 END6:
PC
W0
DCOUNT
DOSTART
DOEND
CORCON
SR
Example 2:
DS70157E-page 242
Before
Instruction
00 2000
0012
0000
FF FFFF
FF FFFF
0000
0000
002000 LOOPA:
002004
002006
002008
00200A
002010 ENDA:
PC
W7
DCOUNT
DOSTART
DOEND
CORCON
SR
DO
ADD
. . .
. . .
. . .
REPEAT
SUB
NOP
Before
Instruction
00 2000
E00F
0000
FF FFFF
FF FFFF
0000
0000
W0, END6
; Initiate DO loop (W0 reps)
W1, W2, W3 ; First instruction in loop
#6
W2, W3, W4
; Last instruction in loop
; (Required NOP filler)
PC
W0
DCOUNT
DOSTART
DOEND
CORCON
SR
DO
SWAP
. . .
. . .
. . .
MOV
W7, ENDA
W0
After
Instruction
00 2004
0012
0012
00 2004
00 2010
0100 (DL = 1)
0080 (DA = 1)
; Initiate DO loop (W7 reps)
; First instruction in loop
PC
W7
DCOUNT
DOSTART
DOEND
CORCON
SR
After
Instruction
00 2004
E00F
200F
00 2004
00 2010
0100 (DL = 1)
0080 (DA = 1)
ED
Implemented in:
Syntax:
PIC24F
{label:} ED
PIC24H
PIC24E
Wm * Wm, Acc,
dsPIC30F
dsPIC33F
dsPIC33E
[Wx],
[Wy],
Wxd
[W11 +
W12],
Operands:
Acc [A,B]
Wm * Wm [W4 * W4, W5 * W5, W6 * W6, W7 * W7]
Wx [W8, W9]; kx [-6, -4, -2, 2, 4, 6]
Wy [W10, W11]; ky [-6, -4, -2, 2, 4, 6]
Wxd [W4 ... W7]
Operation:
Status Affected:
Encoding:
1111
Description:
00mm
A1xx
00ii
iijj
jj11
Compute the square of Wm, and optionally compute the difference of the
prefetch values specified by [Wx] and [Wy]. The results of Wm * Wm are
sign-extended to 40 bits and stored in the specified accumulator. The
results of [Wx] [Wy] are stored in Wxd, which may be the same as Wm.
Operands Wx, Wxd and Wyd specify the prefetch operations which
support indirect and register offset addressing as described in
Section 4.14.1 MAC Prefetches.
The m bits select the operand register Wm for the square.
The A bit selects the accumulator for the result.
The x bits select the prefetch difference Wxd destination.
The i bits select the Wx prefetch operation.
The j bits select the Wy prefetch operation.
Words:
Cycles:
Example 1:
ED
Before
Instruction
009A
1100
2300
00 3D0A 0000
007F
0028
0000
W4
W8
W10
ACCA
Data 1100
Data 2300
SR
;
;
;
;
Square W4 to ACCA
[W8]-[W10] to W4
Post-increment W8
Post-decrement W10
After
Instruction
0057
1102
22FE
00 0000 5CA4
007F
0028
0000
DS70157E-page 243
5
Instruction
Descriptions
W4
W8
W10
ACCA
Data 1100
Data 2300
SR
ED
W5
W9
W11
W12
ACCB
Data 1200
Data 2508
SR
DS70157E-page 244
Before
Instruction
43C2
1200
2500
0008
00 28E3 F14C
6A7C
2B3D
0000
W5
W9
W11
W12
ACCB
Data 1200
Data 2508
SR
After
Instruction
3F3F
1202
2500
0008
00 11EF 1F04
6A7C
2B3D
0000
EDAC
Euclidean Distance
Implemented in:
Syntax:
PIC24F
{label:} EDAC
PIC24H
PIC24E
Wm * Wm, Acc,
dsPIC30F
dsPIC33F
dsPIC33E
[Wx],
[Wy],
[Wx] + =
kx,
[Wy] + = ky,
Wxd
[W11 +
W12],
Operands:
Acc [A,B]
Wm * Wm [W4 * W4, W5 * W5, W6 * W6, W7 * W7]
Wx [W8, W9]; kx [-6, -4, -2, 2, 4, 6]
Wy [W10, W11]; ky [-6, -4, -2, 2, 4, 6]
Wxd [W4 ... W7]
Operation:
Status Affected:
Encoding:
1111
Description:
00mm
A1xx
00ii
iijj
jj10
Compute the square of Wm, and also the difference of the prefetch
values specified by [Wx] and [Wy]. The results of Wm * Wm are
sign-extended to 40 bits and added to the specified accumulator. The
results of [Wx] [Wy] are stored in Wxd, which may be the same as Wm.
Operands Wx, Wxd and Wyd specify the prefetch operations which
support indirect and register offset addressing as described in
Section 4.14.1 MAC Prefetches.
The m bits select the operand register Wm for the square.
The A bit selects the accumulator for the result.
The x bits select the prefetch difference Wxd destination.
The i bits select the Wx prefetch operation.
The j bits select the Wy prefetch operation.
Words:
Cycles:
Example 1:
EDAC
Before
Instruction
009A
1100
2300
00 3D0A 3D0A
007F
0028
0000
W4
W8
W10
ACCA
Data 1100
Data 2300
SR
;
;
;
;
;
Square W4 and
add to ACCA
[W8]-[W10] to W4
Post-increment W8
Post-decrement W10
After
Instruction
0057
1102
22FE
00 3D0A 99AE
007F
0028
0000
Instruction
Descriptions
W4
W8
W10
ACCA
Data 1100
Data 2300
SR
DS70157E-page 245
W5
W9
W11
W12
ACCB
Data 1200
Data 2508
SR
DS70157E-page 246
Before
Instruction
43C2
1200
2500
0008
00 28E3 F14C
6A7C
2B3D
0000
W5
W9
W11
W12
ACCB
Data 1200
Data 2508
SR
;
;
;
;
Square W5 and
add to ACCB
[W9]-[W11+W12] to W5
Post-increment W9
After
Instruction
3F3F
1202
2500
0008
00 3AD3 1050
6A7C
2B3D
0000
EXCH
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
0ddd
d000
ssss
Syntax:
{label:}
Operands:
Operation:
(Wns) (Wnd)
Status Affected:
None
Encoding:
EXCH
1111
Description:
1101
Wns,
0000
dsPIC33F dsPIC33E
Wnd
Words:
Cycles:
Example 1:
EXCH
W1
W9
SR
Example 2:
EXCH
W4
W5
SR
W1, W9
Before
Instruction
55FF
A3A3
0000
W4, W5
Before
Instruction
ABCD
4321
0000
After
Instruction
W1
A3A3
W9
55FF
SR
0000
; Exchange the contents of W4 and W5
After
Instruction
W4
4321
W5
ABCD
SR
0000
5
Instruction
Descriptions
DS70157E-page 247
FBCL
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
{label:}
FBCL
Ws,
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Max_Shift = 15
Sign = (Ws) & 0x8000
Temp = (Ws) << 1
Shift = 0
While ( (Shift < Max_Shift) && ( (Temp & 0x8000) == Sign) )
Temp = Temp << 1
Shift = Shift + 1
-Shift (Wnd)
Status Affected:
Encoding:
Description:
1101
1111
0000
0ddd
dppp
ssss
Find the first occurrence of a one (for a positive value), or zero (for a
negative value), starting from the Most Significant bit after the sign bit of
Ws and working towards the Least Significant bit of the word operand. The
bit number result is sign-extended to 16 bits and placed in Wnd.
The next Most Significant bit after the sign bit is allocated bit number 0 and
the Least Significant bit is allocated bit number -14. This bit ordering
allows for the immediate use of Wd with the SFTAC instruction for scaling
values up. If a bit change is not found, a result of -15 is returned and the C
flag is set. When a bit change is found, the C flag is cleared.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
FBCL
W1, W9
Before
Instruction
W1
55FF
W9
FFFF
SR
0000
DS70157E-page 248
After
Instruction
W1
55FF
W9
0000
SR
0000
FBCL
W1, W9
Before
Instruction
W1 FFFF
W9 BBBB
SR
0000
Example 3:
FBCL
[W1++], W9
Before
Instruction
W1
2000
W9 BBBB
Data 2000
FF0A
SR
0000
After
Instruction
W1 FFFF
W9 FFF1
SR 0001 (C = 1)
; Find 1st bit change from left in [W1]
; and store result to W9
; Post-increment W1
After
Instruction
W1 2002
W9 FFF9
Data 2000 FF0A
SR 0000
5
Instruction
Descriptions
DS70157E-page 249
FF1L
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
FF1L
Ws,
dsPIC33F dsPIC33E
X
dppp
ssss
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Max_Shift = 17
Temp = (Ws)
Shift = 1
While ( (Shift < Max_Shift) && !(Temp & 0x8000) )
Temp = Temp << 1
Shift = Shift + 1
If (Shift == Max_Shift)
0 (Wnd)
Else
Shift (Wnd)
Status Affected:
Encoding:
Description:
1100
1111
1000
0ddd
Finds the first occurrence of a 1 starting from the Most Significant bit of
Ws and working towards the Least Significant bit of the word operand.
The bit number result is zero-extended to 16 bits and placed in Wnd.
Bit numbering begins with the Most Significant bit (allocated number 1)
and advances to the Least Significant bit (allocated number 16). A result
of zero indicates a 1 was not found, and the C flag will be set. If a 1 is
found, the C flag is cleared.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
FF1L
W2, W5
Before
Instruction
W2
000A
W5 BBBB
SR
0000
DS70157E-page 250
After
Instruction
W2
000A
W5
000D
SR
0000
FF1L
[W2++], W5
Before
Instruction
W2
2000
W5 BBBB
Data 2000
0000
SR
0000
After
Instruction
W2
2002
W5
0000
Data 2000
0000
SR
0001 (C = 1)
5
Instruction
Descriptions
DS70157E-page 251
FF1R
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
FF1R
Ws,
dsPIC33F dsPIC33E
X
dppp
ssss
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Max_Shift = 17
Temp = (Ws)
Shift = 1
While ( (Shift < Max_Shift) && !(Temp & 0x1) )
Temp = Temp >> 1
Shift = Shift + 1
If (Shift == Max_Shift)
0 (Wnd)
Else
Shift (Wnd)
Status Affected:
Encoding:
Description:
1100
1111
0000
0ddd
Finds the first occurrence of a 1 starting from the Least Significant bit of
Ws and working towards the Most Significant bit of the word operand. The
bit number result is zero-extended to 16 bits and placed in Wnd.
Bit numbering begins with the Least Significant bit (allocated number 1)
and advances to the Most Significant bit (allocated number 16). A result of
zero indicates a 1 was not found, and the C flag will be set. If a 1 is
found, the C flag is cleared.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
FF1R
W1, W9
Before
Instruction
W1
000A
W9 BBBB
SR
0000
DS70157E-page 252
After
Instruction
W1
000A
W9
0002
SR
0000
FF1R
[W1++], W9
Before
Instruction
W1
2000
W9 BBBB
Data 2000
8000
SR
0000
After
Instruction
W1
2002
W9
0010
Data 2000
8000
SR
0000
5
Instruction
Descriptions
DS70157E-page 253
GOTO
Unconditional Jump
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
Syntax:
{label:}
GOTO
Operands:
Operation:
lit23 PC
NOP Instruction Register
Status Affected:
None
Expr
Encoding:
1st word
0000
0100
nnnn
nnnn
nnnn
nnn0
2nd word
0000
0000
0000
0000
0nnn
nnnn
Description:
Words:
Cycles:
Example 1:
026000
GOTO
026004
MOV
.
...
.
...
027844 _THERE: MOV
027846
...
PC
SR
Example 2:
_THERE
W0, W1
Before
Instruction
02 6000
0000
; Jump to _THERE
#0x400, W2
Before
Instruction
02 6000
0000
000100 _code:
.
026000
026004
PC
SR
DS70157E-page 254
The linker will resolve the specified expression into the lit23 to be
used.
PC
SR
...
...
GOTO
...
; Code execution
; resumes here
After
Instruction
02 7844
0000
; start of code
_code+2
; Jump to _code+2
PC
SR
After
Instruction
00 0102
0000
GOTO
Implemented in:
PIC24F
PIC24H
PIC24E
{label:}
GOTO
Operands:
Operation:
0 PC<22:16>
(Wn<15:1>) PC<15:1>
0 PC<0>
NOP Instruction Register
Status Affected:
None
0000
Description:
dsPIC33F dsPIC33E
Syntax:
Encoding:
dsPIC30F
Wn
0001
0100
0000
0000
ssss
Unconditional indirect jump within the first 32K words of program memory.
Zero is loaded into PC<22:16> and the value specified in (Wn) is loaded
into PC<15:1>. Since the PC must always reside on an even address
boundary, Wn<0> is ignored.
The s bits select the source register.
Words:
Cycles:
Example 1:
006000
GOTO
006002
MOV
.
...
.
...
007844 _THERE: MOV
007846
...
W4
PC
SR
Before
Instruction
7844
00 6000
0000
W4
W0, W1
; Jump unconditionally
; to 16-bit value in W4
#0x400, W2
W4
PC
SR
; Code execution
; resumes here
After
Instruction
7844
00 7844
0000
5
Instruction
Descriptions
DS70157E-page 255
GOTO
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
0 PC<22:16>
(Wn<15:1>) PC<15:1>
0 PC<0>
NOP Instruction Register
Status Affected:
None
Encoding:
GOTO
0000
Description:
Wn
0001
0000
0100
0000
ssss
Unconditional indirect jump within the first 32K words of program memory.
Zero is loaded into PC<22:16> and the value specified in (Wn) is loaded
into PC<15:1>. Since the PC must always reside on an even address
boundary, Wn<0> is ignored.
The s bits select the source register.
Words:
Cycles:
Example 1:
006000
GOTO
006002
MOV
.
...
.
...
007844 _THERE: MOV
007846
...
W4
PC
SR
DS70157E-page 256
Before
Instruction
7844
00 6000
0000
W4
W0, W1
; Jump unconditionally
; to 16-bit value in W4
#0x400, W2
W4
PC
SR
; Code execution
; resumes here
After
Instruction
7844
00 7844
0000
GOTO.L
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Status Affected:
None
Encoding:
0000
Description:
GOTO.L
0001
Wn
1www
w100
0000
ssss
Words:
Cycles:
Example 1:
026000
026004
.
.
026844 _FIR:
026846
PC
W4
W5
W15
Data A268
Data A26A
SR
Before
Instruction
02 6000
6844
0002
A268
FFFF
FFFF
0000
GOTO.L W4
MOV
W0, W1
...
...
MOV
#0x400, W2
...
PC
W4
W5
W15
Data A268
Data A26A
SR
After
Instruction
02 6844
6844
0002
A26C
6004
0002
0000
5
Instruction
Descriptions
DS70157E-page 257
INC
Increment f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
1110
Description:
INC{.B}
1100
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
0BDf
ffff
Add one to the contents of the file register, and place the result in the
destination register. The optional WREG operand determines the
destination register. If WREG is specified, the result is stored in WREG. If
WREG is not specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
INC.B
0x1000
Before
Instruction
Data 1000
8FFF
SR
0000
Example 2:
INC
0x1000, WREG
Before
Instruction
WREG ABCD
Data 1000 8FFF
SR
0000
DS70157E-page 258
After
Instruction
Data 1000
8F00
SR
0101 (DC, C = 1)
; Increment 0x1000 and store to WREG
; (Word mode)
After
Instruction
WREG
9000
Data 1000
8FFF
SR
0108 (DC, N = 1)
INC
Increment Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
INC{.B}
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
dsPIC33F dsPIC33E
X
dppp
ssss
Operands:
Operation:
(Ws) + 1 Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
1110
Description:
1000
0Bqq
qddd
Add 1 to the contents of the source register Ws and place the result in the
destination register Wd. Register direct or indirect addressing may be
used for Ws and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
INC.B
W1, [++W2]
Before
Instruction
W1
FF7F
W2
2000
Data 2000 ABCD
SR
0000
Example 2:
INC
W1, W2
; Pre-increment W2
; Increment W1 and store to W2
; (Byte mode)
After
Instruction
W1
FF7F
W2
2001
Data 2000
80CD
SR
010C (DC, N, OV = 1)
After
Instruction
W1
FF7F
W2
FF80
SR
0108 (DC, N = 1)
DS70157E-page 259
Instruction
Descriptions
Before
Instruction
W1
FF7F
W2
2000
SR
0000
INC2
Increment f by 2
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
INC2{.B}
1110
1100
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
1BDf
ffff
Add 2 to the contents of the file register and place the result in the
destination register. The optional WREG operand determines the
destination register. If WREG is specified, the result is stored in WREG. If
WREG is not specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note:
Words:
Cycles:
Example 1:
INC2.B
0x1000
Before
Instruction
Data 1000
8FFF
SR
0000
Example 2:
INC2
; Increment 0x1000 by 2
; (Byte mode)
After
Instruction
Data 1000
8F01
SR
0101 (DC, C = 1)
0x1000, WREG
Before
Instruction
WREG ABCD
Data 1000
8FFF
SR
0000
DS70157E-page 260
After
Instruction
WREG
9001
Data 1000
8FFF
SR
0108 (DC, N = 1)
INC2
Increment Ws by 2
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
dppp
ssss
{label:}
Operands:
INC2{.B}
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
Operation:
(Ws) + 2 Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
Ws,
1110
1000
1Bqq
qddd
Add 2 to the contents of the source register Ws and place the result in the
destination register Wd. Register direct or indirect addressing may be used
for Ws and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
INC2.B
W1, [++W2]
Before
Instruction
W1
FF7F
W2
2000
Data 2000 ABCD
SR
0000
Example 2:
INC2
W1, W2
After
Instruction
W1
FF7F
W2
2001
Data 2000
81CD
SR
010C (DC, N, OV = 1)
After
Instruction
W1
FF7F
W2
FF81
SR
0108 (DC, N = 1)
DS70157E-page 261
Instruction
Descriptions
Before
Instruction
W1
FF7F
W2
2000
SR
0000
; Pre-increment W2
; Increment by 2 and store to W1
; (Byte mode)
IOR
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
N, Z
Encoding:
1011
Description:
IOR{.B}
0111
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
0BDf
ffff
Words:
Cycles:
Example 1:
IOR.B
0x1000
Before
Instruction
WREG
1234
Data 1000
FF00
SR
0000
Example 2:
IOR
0x1000, WREG
After
Instruction
WREG
1234
Data 1000
FF34
SR
0000
; IOR (0x1000) to WREG
; (Word mode)
Before
After
Instruction
Instruction
WREG
1234
WREG
1FBF
Data 1000
0FAB
Data 1000
0FAB
SR
0008 (N = 1)
SR
0000
DS70157E-page 262
IOR
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
kkkk
kkkk
dddd
Syntax:
{label:}
IOR{.B}
Operands:
Operation:
lit10.IOR.(Wn) Wn
Status Affected:
N, Z
Encoding:
1011
Description:
0011
#lit10,
dsPIC33F dsPIC33E
Wn
0Bkk
Words:
Cycles:
Example 1:
IOR.B #0xAA, W9
Before
Instruction
W9
1234
SR
0000
Example 2:
IOR
#0x2AA, W4
Before
Instruction
W4
A34D
SR
0000
; IOR 0xAA to W9
; (Byte mode)
After
Instruction
W9
12BE
SR
0008 (N = 1)
; IOR 0x2AA to W4
; (Word mode)
After
Instruction
W4
A3EF
SR
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 263
IOR
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
IOR{.B}
Wb,
#lit5,
dsPIC33F dsPIC33E
X
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
(Wb).IOR.lit5 Wd
Status Affected:
N, Z
Encoding:
Description:
0111
0www
wBqq
qddd
d11k
kkkk
Words:
Cycles:
Example 1:
IOR.B
Before
Instruction
W1 AAAA
W9
2000
Data 2000
0000
SR
0000
DS70157E-page 264
After
Instruction
W1 AAAA
W9
2001
Data 2000
00AF
SR
0008 (N = 1)
IOR
W1, #0x0, W9
Before
Instruction
W1
0000
W9
A34D
SR
0000
After
Instruction
W1
0000
W9
0000
SR
0002 (Z = 1)
5
Instruction
Descriptions
DS70157E-page 265
IOR
Inclusive OR Wb and Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
{label:}
IOR{.B}
Operands:
Operation:
(Wb).IOR.(Ws) Wd
Status Affected:
N, Z
Encoding:
Description:
0111
Wb,
0www
wBqq
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
qddd
dppp
ssss
Words:
Cycles:
Example 1:
IOR.B
Before
Instruction
W1 AAAA
W5
2000
W9
2400
Data 2000
1155
Data 2400
0000
SR
0000
DS70157E-page 266
After
Instruction
W1 AAAA
W5
2001
W9
2401
Data 2000
1155
Data 2400
00FF
SR
0008 (N = 1)
IOR
W1
W5
W9
SR
W1, W5, W9
Before
Instruction
AAAA
5555
A34D
0000
After
Instruction
W1 AAAA
W5
5555
W9
FFFF
SR
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 267
LAC
Load Accumulator
Implemented in:
Syntax:
PIC24F
{label:}
PIC24H
LAC
PIC24E
Ws,
dsPIC30F
dsPIC33F
dsPIC33E
rggg
ssss
{#Slit4,}
Acc
[Ws],
[Ws++],
[Ws--],
[--Ws],
[++Ws],
[Ws+Wb],
Operands:
Operation:
ShiftSlit4(Extend(Ws)) Acc(A or B)
Status Affected:
Encoding:
Description:
1100
1010
Awww
wrrr
Read the contents of the source register, optionally perform a signed 4-bit
shift and store the result in the specified accumulator. The shift range is -8:7,
where a negative operand indicates an arithmetic left shift and a positive
operand indicates an arithmetic right shift. The data stored in the source
register is assumed to be 1.15 fractional data and is automatically
sign-extended (through bit 39) and zero-backfilled (bits [15:0]), prior to
shifting.
The A bit specifies the destination accumulator.
The w bits specify the offset register Wb.
The r bits encode the accumulator pre-shift.
The g bits select the source Address mode.
The s bits specify the source register Ws.
Note:
Words:
Cycles:
Example 1:
LAC
W4
ACCB
Data 2000
SR
DS70157E-page 268
[W4++], #-3, B
Before
Instruction
2000
00 5125 ABCD
1221
0000
;
;
;
;
;
W4
ACCB
Data 2000
SR
After
Instruction
2002
FF 9108 0000
1221
4800 (OB, OAB = 1)
LAC
[--W2], #7, A
W2
ACCA
Data 4000
Data 4002
SR
Before
Instruction
4002
00 5125 ABCD
9108
1221
0000
;
;
;
;
;
Pre-decrement W2
Load ACCA with [W2] >> 7
Contents of [W2] do not change
Assume saturation disabled
(SATA = 0)
W2
ACCA
Data 4000
Data 4002
SR
After
Instruction
4000
FF FF22 1000
9108
1221
0000
5
Instruction
Descriptions
DS70157E-page 269
LNK
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(W14) (TOS)
(W15) + 2 W15
(W15) W14
(W15) + lit14 W15
Status Affected:
None
Encoding:
1111
Description:
LNK
1010
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
kkkk
kkkk
#lit14
00kk
kkk0
Words:
Cycles:
Example 1:
LNK
W14
W15
Data 2000
SR
DS70157E-page 270
#0xA0
Before
Instruction
2000
2000
0000
0000
W14
W15
Data 2000
SR
After
Instruction
2002
20A2
2000
0000
LNK
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(W14) (TOS)
(W15) + 2 W15
(W15) W14
1 SFA bit
(W15) + lit14 W15
Status Affected:
SFA
Encoding:
1111
Description:
LNK
1010
#lit14
00kk
kkkk
kkkk
kkk0
Words:
Cycles:
Example 1:
LNK
W14
W15
Data 2000
SR
CORCON
#0xA0
Before
Instruction
2000
2000
0000
0000
0000
W14
W15
Data 2000
SR
CORCON
After
Instruction
2002
20A2
2000
0000
0004
5
Instruction
Descriptions
DS70157E-page 271
LSR
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
ffff
ffff
{label:}
LSR{.B}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
N, Z, C
Encoding:
1101
Description:
{,WREG}
0101
0BDf
ffff
Shift the contents of the file register one bit to the right and place the result
in the destination register. The Least Significant bit of the file register is
shifted into the Carry bit of the STATUS register. Zero is shifted into the
Most Significant bit of the destination register.
The optional WREG operand determines the destination register. If WREG
is specified, the result is stored in WREG. If WREG is not specified, the
result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
LSR.B
0x600
Before
Instruction
Data 600
55FF
SR
0000
DS70157E-page 272
After
Instruction
Data 600
557F
SR
0001 (C = 1)
LSR
0x600, WREG
Before
Instruction
Data 600
55FF
WREG
0000
SR
0000
After
Instruction
Data 600
55FF
WREG
2AFF
SR
0001 (C = 1)
5
Instruction
Descriptions
DS70157E-page 273
LSR
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
LSR{.B}
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
Operands:
Operation:
dppp
ssss
N, Z, C
Encoding:
Description:
Status Affected:
dsPIC33F dsPIC33E
1101
0001
0Bqq
qddd
Shift the contents of the source register Ws one bit to the right, and place
the result in the destination register Wd. The Least Significant bit of Ws is
shifted into the Carry bit of the STATUS register. Zero is shifted into the
Most Significant bit of Wd. Either register direct or indirect addressing
may be used for Ws and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
LSR.B
W0, W1
Before
Instruction
W0
FF03
W1
2378
SR
0000
DS70157E-page 274
After
Instruction
W0
FF03
W1
2301
SR
0001 (C = 1)
LSR
W0, W1
Before
Instruction
W0
8000
W1
2378
SR
0000
After
Instruction
W0
8000
W1
4000
SR
0000
5
Instruction
Descriptions
DS70157E-page 275
LSR
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
lit4<3:0> Shift_Val
0 Wnd<15:15-Shift_Val + 1>
Wb<15:Shift_Val> Wnd<15-Shift_Val:0>
Status Affected:
N, Z
Encoding:
1101
Description:
LSR
1110
Wb,
0www
#lit4,
dsPIC33F dsPIC33E
X
d100
kkkk
Wnd
wddd
Logical shift right the contents of the source register Wb by the 4-bit
unsigned literal and store the result in the destination register Wnd. Direct
addressing must be used for Wb and Wnd.
The w bits select the address of the base register.
The d bits select the destination register.
The k bits provide the literal operand.
Note:
Words:
Cycles:
Example 1:
LSR
W4, #14, W5
Before
Instruction
W4
C800
W5
1200
SR
0000
Example 2:
LSR
W4, #1, W5
Before
Instruction
W4
0505
W5
F000
SR
0000
DS70157E-page 276
; LSR W4 by 14
; Store result to W5
After
Instruction
W4
C800
W5
0003
SR
0000
; LSR W4 by 1
; Store result to W5
After
Instruction
W4
0505
W5
0282
SR
0000
LSR
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Wns<4:0> Shift_Val
0 Wnd<15:15-Shift_Val + 1>
Wb<15:Shift_Val> Wnd<15 - Shift_Val:0>
Status Affected:
N, Z
Encoding:
1101
Description:
LSR
1110
Wb,
0www
Wns,
dsPIC33F dsPIC33E
X
d000
ssss
Wnd
wddd
Logical shift right the contents of the source register Wb by the 5 Least
Significant bits of Wns (only up to 15 positions) and store the result in the
destination register Wnd. Direct addressing must be used for Wb and
Wnd.
The w bits select the address of the base register.
The d bits select the destination register.
The s bits select the source register.
Note 1: This instruction operates in Word mode only.
2: If Wns is greater than 15, Wnd will be loaded with 0x0.
Words:
Cycles:
Example 1:
LSR
W0, W1, W2
Before
Instruction
W0
C00C
W1
0001
W2
2390
SR
0000
Example 2:
LSR
W5, W4, W3
After
Instruction
W0
C00C
W1
0001
W2
6006
SR
0000
; LSR W5 by W4
; Store result to W3
After
Instruction
W3
0000
W4
000C
W5
0800
SR
0002 (Z = 1)
5
Instruction
Descriptions
Before
Instruction
W3
DD43
W4
000C
W5
0800
SR
0000
; LSR W0 by W1
; Store result to W2
DS70157E-page 277
MAC
Implemented in:
Syntax:
PIC24F
{label:} MAC
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
{,[Wy], Wyd}
{,AWB}
Operands:
Operation:
Status Affected:
Encoding:
Description:
1100
0mmm
A0xx
yyii
iijj
jjaa
DS70157E-page 278
Words:
Cycles:
W4
W5
W8
W10
ACCA
Data 0A00
Data 1800
CORCON
SR
Example 2:
Before
Instruction
A022
B900
0A00
1800
00 1200 0000
2567
909C
00C0
0000
W4
W5
W8
W10
ACCA
Data 0A00
Data 1800
CORCON
SR
After
Instruction
2567
909C
0A06
1802
00 472D 2400
2567
909C
00C0
0000
W4
W5
W8
W10
W13
ACCA
ACCB
Data 0A00
Data 1800
CORCON
SR
Before
Instruction
1000
3000
0A00
1800
2000
23 5000 2000
00 0000 8F4C
5BBE
C967
00D0
0000
W4
W5
W8
W10
W13
ACCA
ACCB
Data 0A00
Data 1800
CORCON
SR
After
Instruction
5BBE
C967
09FE
1802
0001
23 5600 2000
00 0000 1F4C
5BBE
C967
00D0
8800 (OA, OAB = 1)
5
Instruction
Descriptions
DS70157E-page 279
MAC
Implemented in:
Syntax:
PIC24F
{label:} MAC
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
{,[Wy], Wyd}
Operands:
Operation:
Status Affected:
Encoding:
Description:
1111
00mm
A0xx
yyii
iijj
jj00
DS70157E-page 280
Words:
Cycles:
W4
W5
W9
W10
W12
ACCB
Data 0C20
Data 1900
CORCON
SR
Example 2:
Before
Instruction
A022
B200
0C00
1900
0020
00 2000 0000
A230
650B
00C0
0000
W4
W5
W9
W10
W12
ACCB
Data 0C20
Data 1900
CORCON
SR
After
Instruction
A230
650B
0C00
18FE
0020
00 67CD 0908
A230
650B
00C0
0000
W7
W11
ACCA
Data 2000
CORCON
SR
Before
Instruction
76AE
2000
FE 9834 4500
23FF
00D0
0000
W7
W11
ACCA
Data 2000
CORCON
SR
After
Instruction
23FF
1FFE
FF 063E 0188
23FF
00D0
8800 (OA, OAB = 1)
5
Instruction
Descriptions
DS70157E-page 281
MOV
Move f to Destination
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
ffff
ffff
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
N, Z
Encoding:
1011
Description:
MOV{.B}
1111
{,WREG}
1BDf
ffff
Move the contents of the specified file register to the destination register.
The optional WREG operand determines the destination register. If
WREG is specified, the result is stored in WREG. If WREG is not
specified, the result is stored back to the file register and the only effect is
to modify the STATUS register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
3: When moving word data from file register memory, the MOV f
to Wnd (page 5-147) instruction allows any working register
(W0:W15) to be the destination register.
Words:
Cycles:
Example 1:
MOV.B
TMR0, WREG
Before
Instruction
WREG (W0)
9080
TMR0
2355
SR
0000
Example 2:
MOV
0x800
Before
Instruction
Data 0800 B29F
SR
0000
DS70157E-page 282
After
Instruction
WREG (W0)
9055
TMR0
2355
SR
0000
; update SR based on (0x800) (Word mode)
After
Instruction
Data 0800 B29F
SR
0008 (N = 1)
MOV
Move WREG to f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
ffff
ffff
ffff
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
(WREG) f
Status Affected:
None
Encoding:
1011
Description:
MOV{.B}
0111
WREG,
dsPIC33F dsPIC33E
1B1f
Move the contents of the default working register WREG into the
specified file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte move rather
than a word move. You may use a .W extension to denote a
word move, but it is not required.
2: The WREG is set to working register W0.
3: When moving word data from the working register array to file
register memory, the MOV Wns to f (page 5-148) instruction
allows any working register (W0:W15) to be the source register.
Words:
Cycles:
Example 1:
MOV.B
WREG, 0x801
Before
Instruction
WREG (W0)
98F3
Data 0800
4509
SR
0000
Example 2:
MOV
After
Instruction
WREG (W0)
98F3
Data 0800
F309
SR
0008 (N = 1)
WREG, DISICNT
Before
Instruction
WREG (W0)
00A0
DISICNT
0000
SR
0000
After
Instruction
WREG (W0)
00A0
DISICNT
00A0
SR
0000
5
Instruction
Descriptions
DS70157E-page 283
MOV
Move f to Wnd
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
ffff
ffff
dddd
Syntax:
{label:}
Operands:
f [0 ... 65534]
Wnd [W0 ... W15]
Operation:
(f) Wnd
Status Affected:
None
Encoding:
1000
Description:
MOV
f,
0fff
dsPIC33F dsPIC33E
Wnd
ffff
Move the word contents of the specified file register to Wnd. The file
register may reside anywhere in the 32K words of data memory, but must
be word-aligned. Register direct addressing must be used for Wnd.
The f bits select the address of the file register.
The d bits select the destination register.
Note 1: This instruction operates on word operands only.
2: Since the file register address must be word-aligned, only the
upper 15 bits of the file register address are encoded (bit 0 is
assumed to be 0).
3: To move a byte of data from file register memory, the MOV f
to Destination instruction (page 5-145) may be used.
Words:
Cycles:
Example 1:
MOV
CORCON, W12
Before
Instruction
W12
78FA
CORCON
00F0
SR
0000
Example 2:
MOV
DS70157E-page 284
After
Instruction
W12
00F0
CORCON
00F0
SR
0000
0x27FE, W3
Before
Instruction
W3
0035
Data 27FE ABCD
SR
0000
; move (0x27FE) to W3
After
Instruction
W3 ABCD
Data 27FE ABCD
SR
0000
MOV
Move Wns to f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
ffff
ffff
ssss
Syntax:
{label:}
Operands:
f [0 ... 65534]
Wns [W0 ... W15]
Operation:
(Wns) f
Status Affected:
None
Encoding:
1000
Description:
MOV
1fff
Wns,
dsPIC33F dsPIC33E
ffff
Move the word contents of the working register Wns to the specified file
register. The file register may reside anywhere in the 32K words of data
memory, but must be word-aligned. Register direct addressing must be
used for Wn.
The f bits select the address of the file register.
The s bits select the source register.
Note 1: This instruction operates on word operands only.
2: Since the file register address must be word-aligned, only the
upper 15 bits of the file register address are encoded (bit 0 is
assumed to be 0).
3: To move a byte of data to file register memory, the MOV WREG
to f instruction (page 5-146) may be used.
Words:
Cycles:
Example 1:
MOV
W4, XMDOSRT
Before
Instruction
W4
1200
XMODSRT
1340
SR
0000
Example 2:
MOV
After
Instruction
W4
1200
XMODSRT
1200
SR
0000
W8, 0x1222
Before
Instruction
W8
F200
Data 1222
FD88
SR
0000
; move W4 to XMODSRT
After
Instruction
W8
F200
Data 1222
F200
SR
0000
5
Instruction
Descriptions
DS70157E-page 285
MOV.B
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
kkkk
kkkk
dddd
Syntax:
{label:}
Operands:
Operation:
lit8 Wnd
Status Affected:
None
Encoding:
Description:
1011
MOV.B
0011
#lit8,
dsPIC33F dsPIC33E
Wnd
1100
The unsigned 8-bit literal k is loaded into the lower byte of Wnd. The
upper byte of Wnd is not changed. Register direct addressing must be
used for Wnd.
The k bits specify the value of the literal.
The d bits select the address of the working register.
Note:
Words:
Cycles:
Example 1:
MOV.B
#0x17, W5
Before
Instruction
W5
7899
SR
0000
Example 2:
MOV.B
#0xFE, W9
Before
Instruction
W9
AB23
SR
0000
DS70157E-page 286
After
Instruction
W5
7817
SR
0000
; load W9 with #0xFE (Byte mode)
After
Instruction
W9
ABFE
SR
0000
MOV
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
kkkk
kkkk
dddd
Syntax:
{label:}
Operands:
Operation:
lit16 Wnd
Status Affected:
None
Encoding:
MOV
0010
Description:
kkkk
#lit16,
dsPIC33F dsPIC33E
Wnd
kkkk
The 16-bit literal k is loaded into Wnd. Register direct addressing must
be used for Wnd.
The k bits specify the value of the literal.
The d bits select the address of the working register.
Note 1: This instruction operates only in Word mode.
2: The literal may be specified as a signed value [-32768:32767],
or unsigned value [0:65535].
Words:
Cycles:
Example 1:
MOV
#0x4231, W13
Before
Instruction
W13
091B
SR
0000
Example 2:
Example 3:
MOV
#0x4, W2
After
Instruction
W13
4231
SR
0000
; load W2 with #0x4
Before
Instruction
W2
B004
SR
0000
After
Instruction
W2
0004
SR
0000
MOV
#-1000, W8
Before
Instruction
W8
23FF
SR
0000
After
Instruction
W8
FC18
SR
0000
5
Instruction
Descriptions
DS70157E-page 287
MOV
Implemented in:
PIC24F
PIC24H
PIC24E
dkkk
ssss
Syntax:
{label:}
Operands:
Operation:
Status Affected:
None
Encoding:
1001
Description:
MOV{.B}
0kkk
kBkk
kddd
The contents of [Ws + Slit10] are loaded into Wnd. In Word mode, the
range of Slit10 is increased to [-1024 ... 1022] and Slit10 must be even to
maintain word address alignment. Register indirect addressing must be
used for the source, and direct addressing must be used for Wnd.
The k bits specify the value of the literal.
The B bit selects byte or word operation (0 for word, 1 for byte).
The d bits select the destination register.
The s bits select the source register.
Note 1: The extension .B in the instruction denotes a byte move rather
than a word move. You may use a .W extension to denote a
word move, but it is not required.
2: In Byte mode, the range of Slit10 is not reduced as specified in
Section 4.6 Using 10-bit Literal Operands, since the literal
represents an address offset from Ws.
Words:
Cycles:
Example 1:
MOV.B
[W8+0x13], W10
Before
Instruction
W8
1008
W10
4009
Data 101A
3312
SR
0000
Example 2:
MOV
DS70157E-page 288
After
Instruction
W8
1008
W10
4033
Data 101A
3312
SR
0000
[W4+0x3E8], W2
Before
Instruction
W2
9088
W4
0800
Data 0BE8
5634
SR
0000
After
Instruction
W2
5634
W4
0800
Data 0BE8
5634
SR
0000
MOV
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Status Affected:
None
Encoding:
1001
Description:
MOV{.B}
1kkk
Wns,
dsPIC33F dsPIC33E
X
dkkk
ssss
[Wd + Slit10]
kBkk
kddd
The contents of Wns are stored to [Wd + Slit10]. In Word mode, the range
of Slit10 is increased to [-1024 ... 1022] and Slit10 must be even to
maintain word address alignment. Register direct addressing must be
used for Wns, and indirect addressing must be used for the destination.
The k bits specify the value of the literal.
The B bit selects byte or word operation (0 for word, 1 for byte).
The d bits select the destination register.
The s bits select the address of the destination register.
Note 1: The extension .B in the instruction denotes a byte move rather
than a word move. You may use a .W extension to denote a
word move, but it is not required.
2: In Byte mode, the range of Slit10 is not reduced as specified in
Section 4.6 Using 10-bit Literal Operands, since the literal
represents an address offset from Wd.
Words:
Cycles:
Example 1:
MOV.B
W0, [W1+0x7]
Before
Instruction
W0
9015
W1
1800
Data 1806
2345
SR
0000
Example 2:
MOV
After
Instruction
W1
1000
W11
8813
Data 0C00
8813
SR
0000
Instruction
Descriptions
After
Instruction
W0
9015
W1
1800
Data 1806
1545
SR
0000
W11, [W1-0x400]
Before
Instruction
W1
1000
W11
8813
Data 0C00
FFEA
SR
0000
; store W0 to [W1+0x7]
; (Byte mode)
DS70157E-page 289
MOV
Move Ws to Wd
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
MOV{.B}
Ws,
dsPIC33F dsPIC33E
X
dggg
ssss
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[--Ws],
[--Wd]
[++Ws],
[++Wd]
Operation:
(Ws) Wd
Status Affected:
None
Encoding:
Description:
0111
1www
wBhh
hddd
Move the contents of the source register into the destination register.
Either register direct or indirect addressing may be used for Ws and Wd.
The w bits define the offset register Wb.
The B bit selects byte or word operation (0 for word, 1 for byte).
The h bits select the destination Address mode.
The d bits select the destination register.
The g bits select the source Address mode.
The s bits select the source register.
Note 1: The extension .B in the instruction denotes a byte move rather
than a word move. You may use a .W extension to denote a
word move, but it is not required.
2: When Register Offset Addressing mode is used for both the
source and destination, the offset must be the same because
the w encoding bits are shared by Ws and Wd.
3: The instruction PUSH Ws translates to MOV Ws, [W15++].
4: The instruction POP Wd translates to MOV [--W15], Wd.
Words:
Cycles:
Example 1:
MOV.B
[W0--], W4
Before
Instruction
W0
0A01
W4
2976
Data 0A00
8988
SR
0000
DS70157E-page 290
After
Instruction
W0
0A00
W4
2989
Data 0A00
8988
SR
0000
MOV
[W6++], [W2+W3]
Before
Instruction
W2
0800
W3
0040
W6
1228
Data 0840
9870
Data 1228
0690
SR
0000
After
Instruction
W2
0800
W3
0040
W6
122A
Data 0840
0690
Data 1228
0690
SR
0000
5
Instruction
Descriptions
DS70157E-page 291
MOV.D
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
MOV.D
0ddd
0ppp
ssss
Wns,
dsPIC33F dsPIC33E
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1110
0000
Words:
Cycles:
Example 1:
MOV.D
W2, W6
Before
Instruction
W2
12FB
W3
9877
W6
9833
W7
FCC6
SR
0000
DS70157E-page 292
After
Instruction
W2
12FB
W3
9877
W6
12FB
W7
9877
SR
0000
MOV.D
[W7--], W4
Before
Instruction
W4
B012
W5
FD89
W7
0900
Data 0900
A319
Data 0902
9927
SR
0000
After
Instruction
W4
A319
W5
9927
W7
08FC
Data 0900
A319
Data 0902
9927
SR
0000
5
Instruction
Descriptions
DS70157E-page 293
MOVPAG
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MOVPAG
#lit10,
DSRPAG
#lit9,
DSWPAG
#lit8,
TBLPAG
Operands:
Operation:
Status Affected:
None
Encoding:
1111
Description:
1110
1100
PPkk
kkkk
kkkk
The appropriate number of bits from the unsigned literal k are loaded
into the DSRPAG, DSWPAG, or TBLPAG register. The assembler
restricts the literal to a 9-bit unsigned value when the destination is DSWPAG, and an 8-bit unsigned value when the destination is TBLPAG.
The P bits select the destination register.
The k bits specify the value of the literal.
Note:
Words:
Cycles:
Example 1:
Before
Instruction
DSRPAG
0000
DS70157E-page 294
After
Instruction
DSRPAG
0002
MOVPAGW
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MOVPAGW Ws,
X
DSRPAG
DSWPAG
TBLPAG
Operands:
Operation:
Status Affected:
None
Encoding:
1111
Description:
1110
1101
PP00
0000
ssss
The appropriate number of bits from the register Ws are loaded into the
DSRPAG, DSWPAG, or TBLPAG register. The assembler restricts the literal to a 9-bit unsigned value when the destination is DSWPAG, and an
8-bit unsigned value when the destination is TBLPAG.
The P bits select the destination register.
The s bits specify the source register.
Note:
Words:
Cycles:
Example 1:
Before
Instruction
DSRPAG
0000
W2
0002
After
Instruction
DSRPAG
0002
W2
0002
5
Instruction
Descriptions
DS70157E-page 295
MOVSAC
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
{,[Wy], Wyd}
{,AWB}
Operands:
Acc [A,B]
Wx [W8, W9]; kx [-6, -4, -2, 2, 4, 6]; Wxd [W4 ... W7]
Wy [W10, W11]; ky [-6, -4, -2, 2, 4, 6]; Wyd [W4 ... W7]
AWB [W13, [W13] + = 2]
Operation:
Status Affected:
None
Encoding:
Description:
1100
0111
A0xx
yyii
iijj
jjaa
DS70157E-page 296
Words:
Cycles:
MOVSAC
; Fetch
; Fetch
; Store
W6
W7
W9
W11
W13
ACCA
Data 0800
Data 1900
SR
Example 2:
Before
Instruction
A022
B200
0800
1900
0020
00 3290 5968
7811
B2AF
0000
MOVSAC
; Fetch
; Fetch
; Store
W4
W6
W9
W11
W12
W13
ACCB
Data 1200
Data 2024
Data 2300
SR
W6
W7
W9
W11
W13
ACCA
Data 0800
Data 1900
SR
After
Instruction
7811
B2AF
0800
1904
3290
00 3290 5968
7811
B2AF
0000
Before
Instruction
76AE
2000
1200
2000
0024
2300
00 9834 4500
BB00
52CE
23FF
0000
W4
W6
W9
W11
W12
W13
ACCB
Data 1200
Data 2024
Data 2300
SR
After
Instruction
BB00
52CE
11FE
2000
0024
2302
00 9834 4500
BB00
52CE
9834
0000
5
Instruction
Descriptions
DS70157E-page 297
MPY
Multiply Wm by Wn to Accumulator
Implemented in:
Syntax:
PIC24F
{label:} MPY
PIC24H
Wm * Wn, Acc
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
{,[Wx], Wxd}
{,[Wy], Wyd}
Operands:
Operation:
Status Affected:
Encoding:
Description:
1100
0mmm
A0xx
yyii
iijj
jj11
DS70157E-page 298
Words:
Cycles:
MPY
;
;
;
;
W4
W5
W6
W7
W8
W10
ACCA
Data 1780
Data 2400
CORCON
SR
Example 2:
Before
Instruction
C000
9000
0800
B200
1780
2400
FF F780 2087
671F
E3DC
0000
0000
W4
W5
W6
W7
W8
W10
ACCA
Data 1780
Data 2400
CORCON
SR
After
Instruction
C000
9000
671F
E3DC
1782
23FE
00 3800 0000
671F
E3DC
0000
0000
W4
W5
W6
W7
W8
W10
ACCB
Data 1782
Data 23FE
CORCON
SR
Before
Instruction
C000
9000
671F
E3DC
1782
23FE
00 9834 4500
8FDC
0078
0000
0000
W4
W5
W6
W7
W8
W10
ACCB
Data 1782
Data 23FE
CORCON
SR
After
Instruction
8FDC
0078
671F
E3DC
1784
23FC
FF E954 3748
8FDC
0078
0000
0000
5
Instruction
Descriptions
DS70157E-page 299
MPY
Square to Accumulator
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
{,[Wx], Wxd}
{,[Wy], Wyd}
Operands:
Operation:
Status Affected:
Encoding:
1111
Description:
00mm
A0xx
yyii
iijj
jj01
Words:
Cycles:
Example 1:
MPY
W6*W6, A, [W9]+=2, W6
W6
W9
ACCA
Data 0900
CORCON
SR
DS70157E-page 300
Before
Instruction
6500
0900
00 7C80 0908
B865
0000
0000
W6
W9
ACCA
Data 0900
CORCON
SR
After
Instruction
B865
0902
00 4FB2 0000
B865
0000
0000
W4
W5
W9
W10
W12
ACCB
Data 1600
Data 1B00
CORCON
SR
Before
Instruction
E228
9000
1700
1B00
FF00
00 9834 4500
8911
F678
0000
0000
W4
W5
W9
W10
W12
ACCB
Data 1600
Data 1B00
CORCON
SR
After
Instruction
8911
F678
1700
1B02
FF00
00 06F5 4C80
8911
F678
0000
0000
5
Instruction
Descriptions
DS70157E-page 301
MPY.N
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
{,[Wx], Wxd}
{,[Wy], Wyd}
Operands:
Operation:
Status Affected:
Encoding:
Description:
1100
0mmm
A1xx
yyii
iijj
jj11
DS70157E-page 302
Words:
Cycles:
MPY.N
;
;
;
;
W4
W5
W8
W10
ACCA
Data 0B00
Data 2000
CORCON
SR
Example 2:
MPY.N
;
;
;
;
Before
Instruction
3023
1290
0B00
2000
00 0000 2387
0054
660A
0001
0000
W4
W5
W8
W10
ACCA
Data 0B00
Data 2000
CORCON
SR
After
Instruction
0054
660A
0B02
2002
FF FC82 7650
0054
660A
0001
0000
W4
W5
W8
W10
ACCA
Data 0B00
Data 2000
CORCON
SR
Before
Instruction
3023
1290
0B00
2000
00 0000 2387
0054
660A
0000
0000
W4
W5
W8
W10
ACCA
Data 0B00
Data 2000
CORCON
SR
After
Instruction
0054
660A
0B02
2002
FF F904 ECA0
0054
660A
0000
0000
5
Instruction
Descriptions
DS70157E-page 303
MSC
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F
dsPIC33E
{,[Wx], Wxd}
{,[Wy], Wyd}
{,AWB}
Operands:
Operation:
Status Affected:
Encoding:
Description:
1100
0mmm
A1xx
yyii
iijj
jjaa
DS70157E-page 304
Words:
Cycles:
MSC
;
;
;
;
W6
W7
W8
W10
ACCA
Data 0C00
Data 1C00
CORCON
SR
Example 2:
MSC
;
;
;
;
Before
Instruction
9051
7230
0C00
1C00
00 0567 8000
D309
100B
0001
0000
W6
W7
W8
W10
ACCA
Data 0C00
Data 1C00
CORCON
SR
After
Instruction
D309
100B
0BFC
1BFC
00 3738 5ED0
D309
100B
0001
0000
W4
W5
W11
W12
W13
ACCA
ACCB
Data 2000
CORCON
SR
Before
Instruction
0500
2000
1800
0800
6233
00 3738 5ED0
00 1000 0000
3579
0000
0000
W4
W5
W11
W12
W13
ACCA
ACCB
Data 2000
CORCON
SR
After
Instruction
0500
3579
1800
0800
3738
00 3738 5ED0
00 0EC0 0000
3579
0000
0000
5
Instruction
Descriptions
DS70157E-page 305
MUL
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
ffff
ffff
ffff
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
None
Encoding:
1011
Description:
MUL{.B}
dsPIC33F dsPIC33E
1100
0B0f
Multiply the default working register WREG with the specified file
register and place the result in the W2:W3 register pair. Both operands
and the result are interpreted as unsigned integers. If this instruction is
executed in Byte mode, the 16-bit result is stored in W2. In Word mode,
the most significant word of the 32-bit result is stored in W3, and the
least significant word of the 32-bit result is stored in W2.
The B bit selects byte or word operation (0 for word, 1 for byte).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
3: The IF bit, CORCON<0>, has no effect on this operation.
4: This is the only instruction, which provides for an 8-bit
multiply.
Words:
Cycles:
Example 1:
MUL.B
0x800
Before
Instruction
WREG (W0)
9823
W2
FFFF
W3
FFFF
Data 0800
2690
SR
0000
Example 2:
MUL
TMR1
Before
Instruction
WREG (W0)
F001
W2
0000
W3
0000
TMR1
3287
SR
0000
DS70157E-page 306
WREG (W0)
W2
W3
Data 0800
SR
After
Instruction
9823
13B0
FFFF
2690
0000
WREG (W0)
W2
W3
TMR1
SR
After
Instruction
F001
C287
2F5E
3287
0000
MUL.SS
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
MUL.SS
Wb,
Ws,
dsPIC33F dsPIC33E
X
dppp
ssss
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1001
1www
wddd
Multiply the contents of Wb with the contents of Ws, and store the 32-bit
result in two successive working registers. The least significant word of
the result is stored in Wnd (which must be an even numbered working
register), and the most significant word of the result is stored in
Wnd + 1. Both source operands and the result Wnd are interpreted as
twos complement signed integers. Register direct addressing must be
used for Wb and Wnd. Register direct or register indirect addressing
may be used for Ws.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1: This instruction operates in Word mode only.
2: Since the product of the multiplication is 32 bits, Wnd must be
an even working register. See Figure 4-2 for information on
how double words are aligned in memory.
3: Wnd may not be W14, since W15<0> is fixed to zero.
4: The IF bit, CORCON<0>, has no effect on this operation.
Words:
Cycles:
Example 1:
MUL.SS
After
Instruction
W0
9823
W1
67DC
W12
D314
W13 D5DC
SR
0000
5
Instruction
Descriptions
Before
Instruction
W0
9823
W1
67DC
W12
FFFF
W13
FFFF
SR
0000
; Multiply W0*W1
; Store the result to W12:W13
DS70157E-page 307
MUL.SS
W2, [--W4], W0
Before
Instruction
W0
FFFF
W1
FFFF
W2
0045
W4
27FE
Data 27FC
0098
SR
0000
DS70157E-page 308
; Pre-decrement W4
; Multiply W2*[W4]
; Store the result to W0:W1
After
Instruction
W0
28F8
W1
0000
W2
0045
W4
27FC
Data 27FC
0098
SR
0000
MUL.SS
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MUL.SS
Wb,
Ws,
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
1011
Description:
1001
1www
w111
Appp
ssss
Words:
Cycles:
Example 1:
MUL.SS
Before
Instruction
9823
67DC
00 0000 0000
0000
W0
W1
Acc A
SR
After
Instruction
9823
67DC
FF D5DC D314
0000
Instruction
Descriptions
W0
W1
Acc A
SR
W0, W1, A
DS70157E-page 309
MUL.SU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
MUL.SU
Wb,
Operands:
#lit5,
Status Affected:
None
Description:
1011
1001
0www
d11k
kkkk
Wnd
Operation:
Encoding:
dsPIC33F dsPIC33E
wddd
Multiply the contents of Wb with the 5-bit literal, and store the 32-bit
result in two successive working registers. The least significant word of
the result is stored in Wnd (which must be an even numbered working
register), and the most significant word of the result is stored in Wnd + 1.
The Wb operand and the result Wnd are interpreted as a twos
complement signed integer. The literal is interpreted as an unsigned integer. Register direct addressing must be used for Wb and Wnd.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The k bits define a 5-bit unsigned integer literal.
Note 1: This instruction operates in Word mode only.
2: Since the product of the multiplication is 32 bits, Wnd must be
an even working register. See Figure 4-3 for information on
how double words are aligned in memory.
3: Wnd may not be W14, since W15<0> is fixed to zero.
4: The IF bit, CORCON<0>, has no effect on this operation.
Words:
Cycles:
Example 1:
MUL.SU
W0, #0x1F, W2
Before
Instruction
W0
C000
W2
1234
W3
C9BA
SR
0000
DS70157E-page 310
After
Instruction
W0
C000
W2
4000
W3
FFF8
SR
0000
MUL.SU
W2, #0x10, W0
Before
Instruction
W0 ABCD
W1
89B3
W2
F240
SR
0000
After
Instruction
W0
2400
W1
000F
W2
F240
SR
0000
5
Instruction
Descriptions
DS70157E-page 311
MUL.SU
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
MUL.SU
Wb,
Ws,
dsPIC33F dsPIC33E
X
dppp
ssss
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1001
0www
wddd
Multiply the contents of Wb with the contents of Ws, and store the 32-bit
result in two successive working registers. The least significant word of
the result is stored in Wnd (which must be an even numbered working
register), and the most significant word of the result is stored in Wnd + 1.
The Wb operand and the result Wnd are interpreted as a twos
complement signed integer. The Ws operand is interpreted as an
unsigned integer. Register direct addressing must be used for Wb and
Wnd. Register direct or register indirect addressing may be used for Ws.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1: This instruction operates in Word mode only.
2: Since the product of the multiplication is 32 bits, Wnd must be
an even working register. See Figure 4-3 for information on
how double words are aligned in memory.
3: Wnd may not be W14, since W15<0> is fixed to zero.
4: The IF bit, CORCON<0>, has no effect on this operation.
Words:
Cycles:
Example 1:
MUL.SU
W8, [W9], W0
Before
Instruction
W0
68DC
W1
AA40
W8
F000
W9
178C
Data 178C
F000
SR
0000
DS70157E-page 312
; Multiply W8*[W9]
; Store the result to W0:W1
After
Instruction
W0
0000
W1
F100
W8
F000
W9
178C
Data 178C
F000
SR
0000
MUL.SU
W2, [++W3], W4
Before
Instruction
W2
0040
W3
0280
W4
1819
W5
2021
Data 0282
0068
SR
0000
; Pre-Increment W3
; Multiply W2*[W3]
; Store the result to W4:W5
After
Instruction
W2
0040
W3
0282
W4
1A00
W5
0000
Data 0282
0068
SR
0000
5
Instruction
Descriptions
DS70157E-page 313
MUL.SU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MUL.SU
Wb,
Ws,
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
1011
Description:
1001
0www
w111
Appp
ssss
Words:
Cycles:
Example 1:
MUL.SU
W8
W9
Acc A
SR
DS70157E-page 314
W8, W9, A
Before
Instruction
F000
F000
00 0000 0000
0000
W8
W9
Acc A
SR
After
Instruction
F000
F000
FF F100 0000
0000
MUL.SU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MUL.SU
Wb,
#lit5,
A
B
Operands:
Operation:
Status Affected:
None
Encoding:
1011
Description:
1001
0www
w111
A11k
kkkk
Words:
Cycles:
Example 1:
MUL.SU
W8
Acc A
SR
W8, #0x02, A
Before
Instruction
0042
00 0000 0000
0000
W8
Acc A
SR
After
Instruction
0042
00 0000 0084
0000
5
Instruction
Descriptions
DS70157E-page 315
MUL.US
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
MUL.US
Wb,
Ws,
dsPIC33F dsPIC33E
X
dppp
ssss
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1000
1www
wddd
Multiply the contents of Wb with the contents of Ws, and store the 32-bit
result in two successive working registers. The least significant word of
the result is stored in Wnd (which must be an even numbered working
register), and the most significant word of the result is stored in Wnd + 1.
The Wb operand is interpreted as an unsigned integer. The Ws operand
and the result Wnd are interpreted as a twos complement signed
integer. Register direct addressing must be used for Wb and Wnd.
Register direct or register indirect addressing may be used for Ws.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1: This instruction operates in Word mode only.
2: Since the product of the multiplication is 32 bits, Wnd must be
an even working register. See Figure 4-3 for information on
how double words are aligned in memory.
3: Wnd may not be W14, since W15<0> is fixed to zero.
4: The IF bit, CORCON<0>, has no effect on this operation.
Words:
Cycles:
Example 1:
MUL.US
W0, [W1], W2
Before
Instruction
W0
C000
W1
2300
W2
00DA
W3
CC25
Data 2300
F000
SR
0000
DS70157E-page 316
After
Instruction
W0
C000
W1
2300
W2
0000
W3
F400
Data 2300
F000
SR
0000
MUL.US
Before
Instruction
W5
0C00
W6
FFFF
W10
0908
W11
6EEB
Data 0C00
7FFF
SR
0000
After
Instruction
W5
0C02
W6
FFFF
W10
8001
W11
7FFE
Data 0C00
7FFF
SR
0000
5
Instruction
Descriptions
DS70157E-page 317
MUL.US
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MUL.US
Wb,
Ws,
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
1011
Description:
1000
0www
w111
Appp
ssss
Words:
Cycles:
Example 1:
MUL.US
W0
W1
Acc B
SR
DS70157E-page 318
W0, W1, B
Before
Instruction
C000
F000
00 0000 0000
0000
W0
W1
Acc B
SR
After
Instruction
0000
F000
FF F400 0000
0000
MUL.UU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
MUL.UU
Wb,
Operands:
#lit5,
Operation:
Status Affected:
None
Encoding:
Description:
1011
1000
0www
wddd
dsPIC33F dsPIC33E
X
d11k
kkkk
Wnd
Multiply the contents of Wb with the 5-bit literal, and store the 32-bit
result in two successive working registers. The least significant word of
the result is stored in Wnd (which must be an even numbered working
register), and the most significant word of the result is stored in Wnd + 1.
Both operands and the result are interpreted as unsigned integers.
Register direct addressing must be used for Wb and Wnd.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The k bits define a 5-bit unsigned integer literal.
Note 1: This instruction operates in Word mode only.
2: Since the product of the multiplication is 32 bits, Wnd must be
an even working register. See Figure 4-3 for information on
how double words are aligned in memory.
3: Wnd may not be W14, since W15<0> is fixed to zero.
4: The IF bit, CORCON<0>, has no effect on this operation.
Words:
Cycles:
Example 1:
MUL.UU
Before
Instruction
W0
2323
W12
4512
W13
7821
SR
0000
Example 2:
MUL.UU
W7, #0x1F, W0
After
Instruction
W0
2323
W12
0F0D
W13
0002
SR
0000
; Multiply W7 by literal 0x1F
; Store the result to W0:W1
After
Instruction
W0
55C0
W1
001D
W7
F240
SR
0000
5
Instruction
Descriptions
Before
Instruction
W0
780B
W1
3805
W7
F240
SR
0000
DS70157E-page 319
MUL.UU
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
MUL.UU
Wb,
Ws,
dsPIC33F dsPIC33E
X
dppp
ssss
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1000
0www
wddd
Multiply the contents of Wb with the contents of Ws, and store the 32-bit
result in two successive working registers. The least significant word of
the result is stored in Wnd (which must be an even numbered working
register), and the most significant word of the result is stored in
Wnd + 1. Both source operands and the result are interpreted as
unsigned integers. Register direct addressing must be used for Wb and
Wnd. Register direct or indirect addressing may be used for Ws.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1: This instruction operates in Word mode only.
2: Since the product of the multiplication is 32 bits, Wnd must be
an even working register. See Figure 4-3 for information on
how double words are aligned in memory.
3: Wnd may not be W14, since W15<0> is fixed to zero.
4: The IF bit, CORCON<0>, has no effect on this operation.
Words:
Cycles:
Example 1:
MUL.UU
W4, W0, W2
Before
Instruction
W0
FFFF
W2
2300
W3
00DA
W4
FFFF
SR
0000
DS70157E-page 320
After
Instruction
W0
FFFF
W2
0001
W3
FFFE
W4
FFFF
SR
0000
Before
Instruction
W0
1024
W1
2300
W4
9654
W5 BDBC
Data 2300
D625
SR
0000
After
Instruction
W0
1024
W1
2302
W4
6D34
W5
0D80
Data 2300
D625
SR
0000
5
Instruction
Descriptions
DS70157E-page 321
MUL.UU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MUL.UU
Wb,
Ws,
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
1011
Description:
1000
0www
w111
Appp
ssss
Words:
Cycles:
Example 1:
MUL.UU
W0
W4
Acc B
SR
DS70157E-page 322
W4, W0, B
Before
Instruction
FFFFF
FFFFF
00 0000 0000
0000
W0
W4
Acc B
SR
After
Instruction
FFFFF
FFFFF
FF FFFE 0001
0000
MUL.UU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MUL.UU
Wb,
#lit5,
A
B
Operands:
Operation:
Status Affected:
None
Encoding:
1011
Description:
1000
0www
w111
A11k
kkkk
Words:
Cycles:
Example 1:
MUL.UU
Before
Instruction
0042
00 0000 0000
0000
W8
Acc A
SR
After
Instruction
0042
00 0000 0084
0000
Instruction
Descriptions
W8
Acc A
SR
W8, #0x02, A
DS70157E-page 323
MULW.SS
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
Syntax:
{label:}
MULW.SS
Wb,
Ws,
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1001
1www
wddd
dppp
ssss
Multiply the contents of Wb with the contents of Ws, and store the result
in a working register, which must be an even numbered working register.
Both source operands and the result Wnd are interpreted as twos
complement signed integers. Register direct addressing must be used
for Wb and Wnd. Register direct or register indirect addressing may be
used for Ws.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1:
2:
3:
4:
Words:
Cycles:
Example 1:
MULW.SS
Before
Instruction
W0
9823
W1
67DC
W12
FFFF
SR
0000
DS70157E-page 324
; Multiply W0*W1
; Store the result to W12
After
Instruction
W0
9823
W1
67DC
W12
D314
SR
0000
MULW.SS
W2, [--W4], W0
Before
Instruction
W0
FFFF
W2
0045
W4
27FE
Data 27FC
0098
SR
0000
; Pre-decrement W4
; Multiply W2*[W4]
; Store the result to W0
After
Instruction
W0
28F8
W2
0045
W4
27FC
Data 27FC
0098
SR
0000
5
Instruction
Descriptions
DS70157E-page 325
MULW.SU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MUL.SU
Wb,
X
Ws,
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1001
0www
wddd
dppp
ssss
Multiply the contents of Wb with the contents of Ws, and store the result
in a working register, which must be an even numbered working register.
The Wb operand and the result Wnd are interpreted as a twos
complement signed integer. The Ws operand is interpreted as an
unsigned integer. Register direct addressing must be used for Wb and
Wnd. Register direct or register indirect addressing may be used for Ws.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1:
2:
3:
4:
Words:
Cycles:
Example 1:
MULW.SU
W8, [W9], W0
Before
Instruction
W0
68DC
W8
F000
W9
178C
Data 178C
F000
SR
0000
DS70157E-page 326
; Multiply W8*[W9]
; Store the result to W0
After
Instruction
W0
0000
W8
F000
W9
178C
Data 178C
F000
SR
0000
MULW.SU
Before
Instruction
W2
0040
W3
0280
W4
1819
Data 0282
0068
SR
0000
After
Instruction
W2
0040
W3
0282
W4
1A00
Data 0282
0068
SR
0000
5
Instruction
Descriptions
DS70157E-page 327
MULW.SU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
MULW.SU
1001
Wb,
0www
X
#lit5,
Wnd
wddd
d11k
kkkk
Multiply the contents of Wb with a 5-bit literal value, and store the result
in a working register, which must be an even numbered working register.
The Wb operand and the result Wnd are interpreted as a twos
complement signed integer. Register direct addressing must be used for
Wb and Wnd.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The k bits select the 5-bit literal value.
Note 1:
2:
3:
4:
Words:
Cycles:
Example 1:
MULW.SU
W8, #0x04, W0
Before
Instruction
W0
68DC
W8
1000
SR
0000
DS70157E-page 328
; Multiply W8 * #0x04
; Store the result to W0
After
Instruction
W0
4000
W8
1000
SR
0000
MULW.US
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MULW.US
Wb,
X
Ws,
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1000
1www
wddd
dppp
ssss
Multiply the contents of Wb with the contents of Ws, and store the result
in a working register, which must be an even numbered working register.
The Wb operand is interpreted as an unsigned integer. The Ws operand
and the result Wnd are interpreted as a twos complement signed
integer. Register direct addressing must be used for Wb and Wnd.
Register direct or register indirect addressing may be used for Ws.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1:
2:
3:
4:
Words:
Cycles:
Example 1:
MULW.US
After
Instruction
W0
C000
W1
2300
W2
0000
Data 2300
F000
SR
0000
5
Instruction
Descriptions
Before
Instruction
W0
C000
W1
2300
W2
00DA
Data 2300
F000
SR
0000
DS70157E-page 329
MULW.US
Before
Instruction
W5
0C00
W6
FFFF
W10
0908
Data 0C00
7FFF
SR
0000
DS70157E-page 330
After
Instruction
W5
0C02
W6
FFFF
W10
8001
Data 0C00
7FFF
SR
0000
MULW.UU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MULW.UU
Wb,
X
Ws,
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1000
0www
wddd
dppp
ssss
Multiply the contents of Wb with the contents of Ws, and store the result
in a working registers, which must be an even numbered working register). Both source operands and the result are interpreted as unsigned
integers. Register direct addressing must be used for Wb and Wnd.
Register direct or indirect addressing may be used for Ws.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1:
2:
3:
4:
Words:
Cycles:
Example 1:
MULW.UU
Before
Instruction
W0
FFFF
W2
2300
W4
FFFF
SR
0000
After
Instruction
W0
FFFF
W2
0001
W4
FFFF
SR
0000
5
Instruction
Descriptions
DS70157E-page 331
MULW.UU
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
MULW.UU
Wb,
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1000
0www
X
#lit5,
Wnd
wddd
d11k
kkkk
Multiply the contents of Wb with a 5-bit literal value, and store the result
in a working registers, which must be an even numbered working register). Both source operands and the result are interpreted as unsigned
integers. Register direct addressing must be used for Wb and Wnd.
The w bits select the address of the base register.
The d bits select the address of the lower destination register.
The k bits select the 5-bit literal value.
Note 1:
2:
3:
4:
Words:
Cycles:
Example 1:
MULW.UU
Before
Instruction
W2
2300
W4
1000
SR
0000
DS70157E-page 332
After
Instruction
W2
4000
W4
1000
SR
0000
NEG
Negate f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
1110
Description:
NEG{.B}
1110
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
0BDf
ffff
Compute the twos complement of the contents of the file register and
place the result in the destination register. The optional WREG operand
determines the destination register. If WREG is specified, the result is
stored in WREG. If WREG is not specified, the result is stored in the file
register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
NEG.B
0x880, WREG
Before
Instruction
WREG (W0)
9080
Data 0880
2355
SR
0000
Example 2:
NEG
0x1200
Before
Instruction
Data 1200
8923
SR
0000
After
Instruction
WREG (W0) 90AB
Data 0880
2355
SR
0008 (N = 1)
; Negate (0x1200) (Word mode)
After
Instruction
Data 1200 76DD
SR
0000
5
Instruction
Descriptions
DS70157E-page 333
NEG
Negate Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
NEG{.B}
Operands:
Operation:
(Ws) + 1 Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
1110
Description:
1010
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
0Bqq
qddd
dsPIC33F dsPIC33E
X
dppp
ssss
Words:
Cycles:
Example 1:
NEG.B
W3, [W4++]
Before
Instruction
W3
7839
W4
1005
Data 1004
2355
SR
0000
Example 2:
NEG
After
Instruction
W3
7839
W4
1006
Data 1004 C755
SR
0008 (N = 1)
[W2++], [--W4]
Before
Instruction
W2
0900
W4
1002
Data 0900
870F
Data 1000
5105
SR
0000
DS70157E-page 334
After
Instruction
W2
0902
W4
1000
Data 0900
870F
Data 1000
78F1
SR
0000
NEG
Negate Accumulator
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Acc [A,B]
Operation:
If (Acc = A):
-ACCA ACCA
Else:
-ACCB ACCB
Status Affected:
Encoding:
NEG
PIC24E
1100
Description:
1011
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
0000
Acc
A001
Words:
Cycles:
Example 1:
NEG
ACCA
CORCON
SR
Example 2:
NEG
ACCB
CORCON
SR
; Negate ACCA
; Store result to ACCA
; CORCON = 0x0000 (no saturation)
Before
Instruction
00 3290 59C8
0000
0000
B
ACCA
CORCON
SR
After
Instruction
FF CD6F A638
0000
0000
; Negate ACCB
; Store result to ACCB
; CORCON = 0x00C0 (normal saturation)
Before
Instruction
FF F230 10DC
00C0
0000
ACCB
CORCON
SR
After
Instruction
00 0DCF EF24
00C0
0000
5
Instruction
Descriptions
DS70157E-page 335
NOP
No Operation
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
0000
xxxx
xxxx
xxxx
xxxx
Syntax:
{label:}
Operands:
None
Operation:
No Operation
Status Affected:
None
Encoding:
0000
Description:
dsPIC33F dsPIC33E
NOP
No Operation is performed.
The x bits can take any value.
Words:
Cycles:
Example 1:
NOP
PC
SR
Example 2:
DS70157E-page 336
Before
Instruction
00 1092
0000
NOP
PC
SR
; execute no operation
After
Instruction
PC
00 1094
SR
0000
; execute no operation
Before
Instruction
00 08AE
0000
After
Instruction
PC
00 08B0
SR
0000
NOPR
No Operation
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
xxxx
xxxx
xxxx
xxxx
Syntax:
{label:}
Operands:
None
Operation:
No Operation
Status Affected:
None
Encoding:
1111
Description:
dsPIC33F dsPIC33E
NOPR
1111
No Operation is performed.
The x bits can take any value.
Words:
Cycles:
Example 1:
NOPR
PC
SR
Example 2:
Before
Instruction
00 2430
0000
NOPR
PC
SR
; execute no operation
After
Instruction
PC
00 2432
SR
0000
; execute no operation
Before
Instruction
00 1466
0000
After
Instruction
PC
00 1468
SR
0000
5
Instruction
Descriptions
DS70157E-page 337
POP
Pop TOS to f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
ffff
ffff
ffff
fff0
Syntax:
{label:}
Operands:
f [0 ... 65534]
Operation:
(W15) 2 W15
(TOS) f
Status Affected:
None
Encoding:
1111
Description:
POP
1001
dsPIC33F dsPIC33E
Words:
Cycles:
Example 1:
POP
0x1230
Before
Instruction
W15
1006
Data 1004 A401
Data 1230
2355
SR
0000
Example 2:
POP
0x880
Before
Instruction
W15
2000
Data 0880 E3E1
Data 1FFE A090
SR
0000
DS70157E-page 338
After
Instruction
W15
1004
Data 1004 A401
Data 1230 A401
SR
0000
; Pop TOS to 0x880
After
Instruction
W15 1FFE
Data 0880 A090
Data 1FFE A090
SR
0000
POP
Pop TOS to Wd
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
hddd
d100
1111
{label:}
POP
dsPIC33F dsPIC33E
Wd
[Wd]
[Wd++]
[Wd--]
[--Wd]
[++Wd]
[Wd+Wb]
Operands:
Operation:
(W15) 2 W15
(TOS) Wd
Status Affected:
None
Encoding:
0111
Description:
1www
w0hh
Words:
Cycles:
Example 1:
POP
W4
Before
Instruction
W4 EDA8
W15
1008
Data 1006 C45A
SR
0000
Example 2:
After
Instruction
W4 C45A
W15
1006
Data 1006 C45A
SR
0000
[++W10]
; Pre-increment W10
; Pop TOS to [W10]
Before
Instruction
W10 0E02
W15
1766
Data 0E04 E3E1
Data 1764 C7B5
SR
0000
After
Instruction
W10 0E04
W15
1764
Data 0E04 C7B5
Data 1764 C7B5
SR
0000
5
Instruction
Descriptions
POP
; Pop TOS to W4
DS70157E-page 339
POP.D
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
0ddd
0100
1111
Syntax:
{label:}
Operands:
Operation:
(W15) 2 W15
(TOS) Wnd + 1
(W15) 2 W15
(TOS) Wnd
Status Affected:
None
Encoding:
1011
Description:
POP.D
1110
dsPIC33F dsPIC33E
Wnd
0000
Words:
Cycles:
Example 1:
POP.D
W6
Before
Instruction
W6 07BB
W7 89AE
W15
0850
Data 084C
3210
Data 084E
7654
SR
0000
Example 2:
POP.D
W0
Before
Instruction
W0 673E
W1 DD23
W15 0BBC
Data 0BB8 791C
Data 0BBA D400
SR
0000
DS70157E-page 340
After
Instruction
W6
3210
W7
7654
W15 084C
Data 084C
3210
Data 084E
7654
SR
0000
; Double pop TOS to W0
After
Instruction
W0 791C
W1 D400
W15 0BB8
Data 0BB8 791C
Data 0BBA D400
SR
0000
POP.S
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
1000
0000
0000
0000
Syntax:
{label:}
Operands:
None
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
1111
Description:
dsPIC33F dsPIC33E
POP.S
1110
The values in the shadow registers are copied into their respective
primary registers. The following registers are affected: W0-W3, and the
C, Z, OV, N and DC STATUS register flags.
Note 1: The shadow registers are not directly accessible. They may
only be accessed with PUSH.S and POP.S.
2: The shadow registers are only one-level deep.
Words:
Cycles:
Example 1:
POP.S
Before
Instruction
W0 07BB
W1 03FD
W2
9610
W3
7249
SR 00E0 (IPL = 7)
Note:
After
Instruction
W0
0000
W1
1000
W2
2000
W3
3000
SR 00E1 (IPL = 7, C = 1)
5
Instruction
Descriptions
DS70157E-page 341
PUSH
Push f to TOS
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
ffff
ffff
ffff
fff0
Syntax:
{label:}
Operands:
f [0 ... 65534]
Operation:
(f) (TOS)
(W15) + 2 W15
Status Affected:
None
Encoding:
1111
Description:
PUSH
1000
dsPIC33F dsPIC33E
The contents of the specified file register are written to the Top-of-Stack
(TOS) location and then the Stack Pointer (W15) is incremented by 2.
The file register may reside anywhere in the lower 32K words of data
memory.
The f bits select the address of the file register.
Note 1: This instruction operates in Word mode only.
2: The file register address must be word-aligned.
Words:
Cycles:
Example 1:
PUSH
0x2004
Before
Instruction
W15 0B00
Data 0B00 791C
Data 2004 D400
SR
0000
Example 2:
PUSH
0xC0E
Before
Instruction
W15
0920
Data 0920
0000
Data 0C0E 67AA
SR
0000
DS70157E-page 342
After
Instruction
W15 0B02
Data 0B00 D400
Data 2004 D400
SR
0000
; Push (0xC0E) to TOS
After
Instruction
W15
0922
Data 0920 67AA
Data 2004 67AA
SR
0000
PUSH
Push Ws to TOS
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
{label:}
PUSH
1111
1ggg
ssss
Ws
[Ws]
[Ws++]
[Ws--]
[--Ws]
[++Ws]
[Ws+Wb]
Operands:
Operation:
(Ws) (TOS)
(W15) + 2 W15
Status Affected:
None
Encoding:
0111
Description:
1www
w001
Words:
Cycles:
Example 1:
PUSH
W2
Before
Instruction
W2
6889
W15
1566
Data 1566
0000
SR
0000
; Push W2 to TOS
After
Instruction
W2
6889
W15
1568
Data 1566
6889
SR
0000
5
Instruction
Descriptions
DS70157E-page 343
PUSH
[W5+W10]
Before
Instruction
W5
1200
W10
0044
W15
0806
Data 0806
216F
Data 1244 B20A
SR
0000
DS70157E-page 344
After
Instruction
W5
1200
W10
0044
W15
0808
Data 0806 B20A
Data 1244 B20A
SR
0000
PUSH.D
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
1001
1111
1000
sss0
Syntax:
{label:}
Operands:
Operation:
(Wns) (TOS)
(W15) + 2 W15
(Wns + 1) (TOS)
(W15) + 2 W15
Status Affected:
None
Encoding:
Description:
1011
PUSH.D
1110
dsPIC33F dsPIC33E
Wns
Words:
Cycles:
Example 1:
PUSH.D
W6
Before
Instruction
W6 C451
W7
3380
W15
1240
Data 1240 B004
Data 1242
0891
SR
0000
Example 2:
PUSH.D
W10
After
Instruction
W6 C451
W7
3380
W15
1244
Data 1240 C451
Data 1242
3380
SR
0000
; Push W10:W11 to TOS
After
Instruction
W10 80D3
W11
4550
W15 0C0C
Data 0C08 80D3
Data 0C0A
4550
SR
0000
Instruction
Descriptions
Before
Instruction
W10 80D3
W11
4550
W15 0C08
Data 0C08 79B5
Data 0C0A 008E
SR
0000
DS70157E-page 345
PUSH.S
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
1010
0000
0000
0000
Syntax:
{label:}
Operands:
None
Operation:
Status Affected:
None
Encoding:
PUSH.S
1111
Description:
dsPIC33F dsPIC33E
1110
The contents of the primary registers are copied into their respective
shadow registers. The following registers are shadowed: W0-W3, and
the C, Z, OV, N and DC STATUS register flags.
Note 1: The shadow registers are not directly accessible. They may
only be accessed with PUSH.S and POP.S.
2: The shadow registers are only one-level deep.
Words:
Cycles:
Example 1:
PUSH.S
Before
Instruction
W0
0000
W1
1000
W2
2000
W3
3000
SR
0001 (C = 1)
Note:
DS70157E-page 346
After
Instruction
W0
0000
W1
1000
W2
2000
W3
3000
SR
0001 (C = 1)
PWRSAV
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
0100
0000
0000
000k
Syntax:
{label:}
Operands:
lit1 [0,1]
Operation:
Status Affected:
None
Encoding:
Description:
1111
PWRSAV
1110
dsPIC33F dsPIC33E
#lit1
Place the processor into the specified Power Saving mode. If lit1 = 0,
Sleep mode is entered. In Sleep mode, the clock to the CPU and
peripherals are shutdown. If an on-chip oscillator is being used, it is also
shutdown. If lit1 = 1, Idle mode is entered. In Idle mode, the clock to the
CPU shuts down, but the clock source remains active and the
peripherals continue to operate.
This instruction resets the Watchdog Timer Count register and the
Prescaler Count registers. In addition, the WDTO, Sleep and Idle flags of
the Reset System and Control (RCON) register are reset.
Note 1: The processor will exit from Idle or Sleep through an interrupt,
processor Reset or Watchdog Time-out. See the specific
device data sheet for details.
2: If awakened from Idle mode, Idle (RCON<2>) is set to 1 and
the clock source is applied to the CPU.
3: If awakened from Sleep mode, Sleep (RCON<3>) is set to 1
and the clock source is started.
4: If awakened from a Watchdog Time-out, WDTO (RCON<4>)
is set to 1.
Words:
Cycles:
Example 1:
PWRSAV
#0
Before
Instruction
SR
0040 (IPL = 2)
PWRSAV
#1
Before
Instruction
SR
0020 (IPL = 1)
Instruction
Descriptions
Example 2:
After
Instruction
SR
0040 (IPL = 2)
After
Instruction
SR
0020 (IPL = 1)
DS70157E-page 347
RCALL
Relative Call
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
RCALL
Operands:
Operation:
(PC) + 2 PC
(PC<15:0>) (TOS)
(W15) + 2 W15
(PC<22:16>) (TOS)
(W15) + 2 W15
(PC) + (2 * Slit16) PC
NOP Instruction Register
Status Affected:
None
Encoding:
0000
Description:
0111
PIC24E
dsPIC30F
X
dsPIC33F dsPIC33E
X
Expr
nnnn
nnnn
nnnn
nnnn
Relative subroutine call with a range of 32K program words forward or back
from the current PC. Before the call is made, the return address (PC + 2) is
PUSHed onto the stack. After the return address is stacked, the
sign-extended 17-bit value (2 * Slit16) is added to the contents of the PC
and the result is stored in the PC.
The n bits are a signed literal that specifies the size of the relative call (in
program words) from (PC + 2).
Note:
Words:
Cycles:
Example 1:
012004
012006
.
.
012458 _Task1:
01245A
PC
W15
Data 0810
Data 0812
SR
DS70157E-page 348
Before
Instruction
01 2004
0810
FFFF
FFFF
0000
RCALL
ADD
...
...
SUB
...
_Task1
W0, W1, W2
; Call _Task1
W0, W2, W3
; _Task1 subroutine
After
Instruction
PC
01 2458
W15
0814
Data 0810
2006
Data 0812
0001
SR
0000
00620E
006210
.
.
007000 _Init:
007002
PC
W15
Data 0C50
Data 0C52
SR
Before
Instruction
00 620E
0C50
FFFF
FFFF
0000
RCALL
MOV
...
...
CLR
...
_Init
W0, [W4++]
; Call _Init
W2
; _Init subroutine
After
Instruction
PC
00 7000
W15
0C54
Data 0C50
6210
Data 0C52
0000
SR
0000
5
Instruction
Descriptions
DS70157E-page 349
RCALL
Relative Call
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(PC) + 2 PC
(PC<15:1>) TOS<15:1>, SFA bit TOS<0>
(W15) + 2 W15
(PC<22:16>) (TOS)
(W15) + 2 W15
0 SFA bit
(PC) + (2 * Slit16) PC
NOP Instruction Register
Status Affected:
SFA
Encoding:
RCALL
0000
Description:
0111
Expr
nnnn
nnnn
nnnn
nnnn
Relative subroutine call with a range of 32K program words forward or back
from the current PC. Before the call is made, the return address (PC + 2) is
PUSHed onto the stack. After the return address is stacked, the
sign-extended 17-bit value (2 * Slit16) is added to the contents of the PC
and the result is stored in the PC.
The n bits are a signed literal that specifies the size of the relative call (in
program words) from (PC + 2).
Note:
Words:
Cycles:
Example 1:
012004
012006
.
.
012458 _Task1:
01245A
PC
W15
Data 0810
Data 0812
SR
DS70157E-page 350
Before
Instruction
01 2004
0810
FFFF
FFFF
0000
RCALL
ADD
...
...
SUB
...
_Task1
W0, W1, W2
; Call _Task1
W0, W2, W3
; _Task1 subroutine
After
Instruction
PC
01 2458
W15
0814
Data 0810
2006
Data 0812
0001
SR
0000
00620E
006210
.
.
007000 _Init:
007002
PC
W15
Data 0C50
Data 0C52
SR
Before
Instruction
00 620E
0C50
FFFF
FFFF
0000
RCALL
MOV
...
...
CLR
...
_Init
W0, [W4++]
; Call _Init
W2
; _Init subroutine
After
Instruction
PC
00 7000
W15
0C54
Data 0C50
6210
Data 0C52
0000
SR
0000
5
Instruction
Descriptions
DS70157E-page 351
RCALL
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(PC) + 2 PC
(PC<15:0>) (TOS)
(W15) + 2 W15
(PC<22:16>) (TOS)
(W15) + 2 W15
(PC) + (2 * (Wn)) PC
NOP Instruction Register
Status Affected:
None
Encoding:
0000
Description:
RCALL
PIC24E
0001
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
Wn
0010
ssss
Computed, relative subroutine call specified by the working register Wn. The
range of the call is 32K program words forward or back from the current PC.
Before the call is made, the return address (PC + 2) is PUSHed onto the
stack. After the return address is stacked, the sign-extended 17-bit value (2 *
(Wn)) is added to the contents of the PC and the result is stored in the PC.
Register direct addressing must be used for Wn.
The s bits select the source register.
Words:
Cycles:
Example 1:
00FF8C
00FF8E
.
.
010008
01000A
01000C
PC
W6
W15
Data 1004
Data 1006
SR
DS70157E-page 352
EX1:
Before
Instruction
01 000A
FFC0
1004
98FF
2310
0000
INC
...
...
...
W2, W3
; Destination of RCALL
RCALL
MOVE
W6
W4, [W10]
; RCALL with W6
After
Instruction
PC
00 FF8C
W6
FFC0
W15
1008
Data 1004
000C
Data 1006
0001
SR
0000
000302
000304
.
.
000450
000452
PC
W2
W15
Data 1004
Data 1006
SR
EX2:
Before
Instruction
00 0302
00A6
1004
32BB
901A
0000
RCALL
FF1L
...
...
CLR
...
W2
W0, W1
; RCALL with W2
W2
; Destination of RCALL
After
Instruction
PC
00 0450
W2
00A6
W15
1008
Data 1004
0304
Data 1006
0000
SR
0000
5
Instruction
Descriptions
DS70157E-page 353
RCALL
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(PC) + 2 PC
(PC<15:1>) TOS<15:1>, SFA bit TOS<0>
(W15) + 2 W15
(PC<22:16>) (TOS)
(W15) + 2 W15
0 SFA bit
(PC) + (2 * (Wn)) PC
NOP Instruction Register
Status Affected:
SFA
Encoding:
0000
Description:
RCALL
0001
Wn
0000
0010
0000
ssss
Computed, relative subroutine call specified by the working register Wn. The
range of the call is 32K program words forward or back from the current PC.
Before the call is made, the return address (PC + 2) is PUSHed onto the
stack. After the return address is stacked, the sign-extended 17-bit value (2 *
(Wn)) is added to the contents of the PC and the result is stored in the PC.
Register direct addressing must be used for Wn.
The s bits select the source register.
Words:
Cycles:
Example 1:
00FF8C
00FF8E
.
.
010008
01000A
01000C
PC
W6
W15
Data 1004
Data 1006
SR
DS70157E-page 354
EX1:
Before
Instruction
01 000A
FFC0
1004
98FF
2310
0000
INC
...
...
...
W2, W3
; Destination of RCALL
RCALL
MOVE
W6
W4, [W10]
; RCALL with W6
After
Instruction
PC
00 FF8C
W6
FFC0
W15
1008
Data 1004
000C
Data 1006
0001
SR
0000
000302
000304
.
.
000450
000452
PC
W2
W15
Data 1004
Data 1006
SR
EX2:
Before
Instruction
00 0302
00A6
1004
32BB
901A
0000
RCALL
FF1L
...
...
CLR
...
W2
W0, W1
; RCALL with W2
W2
; Destination of RCALL
After
Instruction
PC
00 0450
W2
00A6
W15
1008
Data 1004
0304
Data 1006
0000
SR
0000
5
Instruction
Descriptions
DS70157E-page 355
REPEAT
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(lit14) RCOUNT
(PC) + 2 PC
Enable Code Looping
Status Affected:
RA
Encoding:
0000
Description:
REPEAT
1001
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
kkkk
kkkk
#lit14
00kk
kkkk
Words:
Cycles:
Example 1:
000452
000454
PC
RCOUNT
SR
DS70157E-page 356
REPEAT #9
ADD
[W0++], W1, [W2++]
Before
Instruction
00 0452
0000
0000
After
Instruction
PC
00 0454
RCOUNT
0009
SR
0010 (RA = 1)
00089E
0008A0
PC
RCOUNT
SR
REPEAT
CLR
Before
Instruction
00 089E
0000
0000
#0x3FF
[W6++]
After
Instruction
PC
00 08A0
RCOUNT
03FF
SR
0010 (RA = 1)
5
Instruction
Descriptions
DS70157E-page 357
REPEAT
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(lit15) RCOUNT
(PC) + 2 PC
Enable Code Looping
Status Affected:
RA
Encoding:
0000
Description:
REPEAT
1001
#lit15
0kkk
kkkk
kkkk
kkkk
Words:
Cycles:
Example 1:
000452
000454
PC
RCOUNT
SR
DS70157E-page 358
REPEAT #9
ADD
[W0++], W1, [W2++]
Before
Instruction
00 0452
0000
0000
After
Instruction
PC
00 0454
RCOUNT
0009
SR
0010 (RA = 1)
00089E
0008A0
PC
RCOUNT
SR
REPEAT
CLR
Before
Instruction
00 089E
0000
0000
#0x3FF
[W6++]
After
Instruction
PC
00 08A0
RCOUNT
03FF
SR
0010 (RA = 1)
5
Instruction
Descriptions
DS70157E-page 359
REPEAT
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Operation:
(Wn<13:0>) RCOUNT
(PC) + 2 PC
Enable Code Looping
Status Affected:
RA
Encoding:
0000
Description:
REPEAT
PIC24E
1001
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
Wn
1000
ssss
Words:
Cycles:
Example 1:
000A26
000A28
PC
W4
RCOUNT
SR
DS70157E-page 360
REPEAT
COM
Before
Instruction
00 0A26
0023
0000
0000
W4
[W0++], [W2++]
After
Instruction
PC
00 0A28
W4
0023
RCOUNT
0023
SR
0010 (RA = 1)
00089E
0008A0
PC
W10
RCOUNT
SR
REPEAT
TBLRDL
Before
Instruction
00 089E
00FF
0000
0000
W10
; Execute TBLRD (W10+1) times
[W2++], [W3++] ; Decrement (0x840)
After
Instruction
PC
00 08A0
W10
00FF
RCOUNT
00FF
SR
0010 (RA = 1)
5
Instruction
Descriptions
DS70157E-page 361
REPEAT
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
(Wn) RCOUNT
(PC) + 2 PC
Enable Code Looping
Status Affected:
RA
Encoding:
0000
Description:
REPEAT
1001
Wn
1000
0000
0000
ssss
Words:
Cycles:
Example 1:
000A26
000A28
PC
W4
RCOUNT
SR
DS70157E-page 362
REPEAT
COM
Before
Instruction
00 0A26
0023
0000
0000
W4
[W0++], [W2++]
After
Instruction
PC
00 0A28
W4
0023
RCOUNT
0023
SR
0010 (RA = 1)
00089E
0008A0
PC
W10
RCOUNT
SR
REPEAT
TBLRDL
Before
Instruction
00 089E
00FF
0000
0000
W10
; Execute TBLRD (W10+1) times
[W2++], [W3++] ; Decrement (0x840)
After
Instruction
PC
00 08A0
W10
00FF
RCOUNT
00FF
SR
0010 (RA = 1)
5
Instruction
Descriptions
DS70157E-page 363
RESET
Reset
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
None
Operation:
Force all registers that are affected by a MCLR Reset to their Reset
condition.
1 SWR (RCON<6>)
0 PC
Status Affected:
OA, OB, OAB, SA, SB, SAB, DA, DC, IPL<2:0>, RA, N, OV, Z, C, SFA
Encoding:
Description:
1111
RESET
1110
0000
0000
0000
0000
This instruction provides a way to execute a software Reset. All core and
peripheral registers will take their power-on value. The PC will be set to
0, the location of the RESET GOTO instruction. The SWR bit,
RCON<6>, will be set to 1 to indicate that the RESET instruction was
executed.
Note:
DS70157E-page 364
dsPIC33F dsPIC33E
Words:
Cycles:
00202A
PC
W0
W1
W2
W3
W4
W5
W6
W7
W8
W9
W10
W11
W12
W13
W14
W15
SPLIM
TBLPAG
PSVPAG
CORCON
RCON
SR
RESET
Before
After
Instruction
Instruction
00 202A
PC
00 0000
8901
W0
0000
08BB
W1
0000
B87A
W2
0000
872F
W3
0000
C98A
W4
0000
AAD4
W5
0000
981E
W6
0000
1809
W7
0000
C341
W8
0000
90F4
W9
0000
F409
W10
0000
1700
W11
0000
1008
W12
0000
6556
W13
0000
231D
W14
0000
1704
W15
0800
1800
SPLIM
0000
007F
TBLPAG
0000
0001
PSVPAG
0000
00F0
CORCON
0020 (SATDW = 1)
0000
RCON
0040 (SWR = 1)
0021 (IPL, C = 1)
SR
0000
5
Instruction
Descriptions
DS70157E-page 365
RETFIE
Implemented in:
PIC24F
PIC24H
PIC24E
Syntax:
{label:}
Operands:
None
Operation:
(W15) - 2 W15
(TOS<15:8>) (SR<7:0>)
(TOS<7>) (IPL3, CORCON<3>)
(TOS<6:0>) (PC<22:16>)
(W15) - 2 W15
(TOS<15:0>) (PC<15:0>)
NOP Instruction Register
Status Affected:
Encoding:
0000
Description:
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
RETFIE
0110
0100
0000
Words:
Cycles:
3 (2 if exception pending)
Example 1:
000A26
PC
W15
Data 0830
Data 0832
CORCON
SR
Example 2:
DS70157E-page 366
Before
Instruction
00 0A26
0834
0230
8101
0001
0000
008050
PC
W15
Data 0922
Data 0924
CORCON
SR
RETFIE
RETFIE
Before
Instruction
00 8050
0926
7008
0300
0000
0000
After
Instruction
PC
01 0230
W15
0830
Data 0830
0230
Data 0832
8101
CORCON
0001
SR
0081 (IPL = 4, C = 1)
; Return from ISR
After
Instruction
PC
00 7008
W15
0922
Data 0922
7008
Data 0924
0300
CORCON
0000
SR
0003 (Z, C = 1)
RETFIE
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
None
Operation:
(W15) - 2 W15
(TOS<15:8>) (SR<7:0>)
(TOS<7>) (IPL3, CORCON<3>)
(TOS<6:0>) (PC<22:16>)
(W15) - 2 W15
(TOS<15:1>) (PC<15:1>)
TOS<0> SFA bit
NOP Instruction Register
Status Affected:
Encoding:
0000
Description:
RETFIE
0110
0100
0000
0000
0000
Words:
Cycles:
6 (5 if exception pending)
Example 1:
000A26
PC
W15
Data 0830
Data 0832
CORCON
SR
Example 2:
RETFIE
Before
Instruction
00 8050
0926
7008
0300
0000
0000
After
Instruction
PC
01 0230
W15
0830
Data 0830
0230
Data 0832
8101
CORCON
0001
SR
0081 (IPL = 4, C = 1)
; Return from ISR
After
Instruction
PC
00 7008
W15
0922
Data 0922
7008
Data 0924
0300
CORCON
0000
SR
0003 (Z, C = 1)
DS70157E-page 367
5
Instruction
Descriptions
Before
Instruction
00 0A26
0834
0230
8101
0001
0000
008050
PC
W15
Data 0922
Data 0924
CORCON
SR
RETFIE
RETLW
Implemented in:
PIC24F
PIC24H
PIC24E
Syntax:
{label:}
Operands:
Operation:
(W15) 2 W15
TOS<15:8> SR<7:0>
TOS<7:0> IPL<3> : PC<22:16>
(W15) 2 W15
(TOS) (PC<15:0>)
lit10 Wn
Status Affected:
None
Encoding:
0000
Description:
RETLW{.B} #lit10,
0101
0Bkk
dsPIC30F
dsPIC33F dsPIC33E
kkkk
kkkk
Wn
dddd
Return from subroutine with the specified, unsigned 10-bit literal stored
in Wn. The software stack is POPped twice to restore the PC and the
signed literal is stored in Wn. Since two POPs are made, the Stack
Pointer (W15) is decremented by 4.
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits specify the value of the literal.
The d bits select the destination register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: For byte operations, the literal must be specified as an unsigned
value [0:255]. See Section 4.6 Using 10-bit Literal Operands
for information on using 10-bit literal operands in Byte mode.
Words:
Cycles:
3 (2 if exception pending)
Example 1:
000440
PC
W0
W15
Data 1984
Data 1986
SR
DS70157E-page 368
RETLW.B #0xA, W0
Before
Instruction
00 0440
9846
1988
7006
0000
0000
After
Instruction
PC
00 7006
W0
980A
W15
1984
Data 1984
7006
Data 1986
0000
SR
0000
00050A
PC
W2
W15
Data 11FC
Data 11FE
SR
RETLW
Before
Instruction
00 050A
0993
1200
7008
0001
0000
#0x230, W2
PC
W2
W15
Data 11FC
Data 11FE
SR
After
Instruction
01 7008
0230
11FC
7008
0001
0000
5
Instruction
Descriptions
DS70157E-page 369
RETLW
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Operation:
RETLW{.B} #lit10,
X
Wn
Status Affected:
Encoding:
SFA
0000
Description:
Return from subroutine with the specified, unsigned 10-bit literal stored
in Wn. The software stack is POPped twice to restore the PC and the
signed literal is stored in Wn. Since two POPs are made, the Stack
Pointer (W15) is decremented by 4.
0101
0Bkk
kkkk
kkkk
dddd
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits specify the value of the literal.
The d bits select the destination register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: For byte operations, the literal must be specified as an unsigned
value [0:255]. See Section 4.6 Using 10-bit Literal Operands
for information on using 10-bit literal operands in Byte mode.
Words:
Cycles:
1
6 (5 if exception pending)
Example 1:
000440
PC
W0
W15
Data 1984
Data 1986
SR
DS70157E-page 370
RETLW.B #0xA, W0
Before
Instruction
00 0440
9846
1988
7006
0000
0000
After
Instruction
PC
00 7006
W0
980A
W15
1984
Data 1984
7006
Data 1986
0000
SR
0000
00050A
PC
W2
W15
Data 11FC
Data 11FE
SR
RETLW
Before
Instruction
00 050A
0993
1200
7008
0001
0000
#0x230, W2
PC
W2
W15
Data 11FC
Data 11FE
SR
After
Instruction
01 7008
0230
11FC
7008
0001
0000
5
Instruction
Descriptions
DS70157E-page 371
RETURN
Return
Implemented in:
PIC24H
PIC24E
Syntax:
{label:}
Operands:
None
Operation:
(W15) 2 W15
(TOS) (PC<22:16>)
(W15) 2 W15
(TOS) (PC<15:0>)
NOP Instruction Register
Status Affected:
None
Encoding:
0000
Description:
dsPIC33F dsPIC33E
0110
0000
0000
0000
0000
Cycles:
3 (2 if exception pending)
001A06
PC
W15
Data 1244
Data 1246
SR
Example 2:
dsPIC30F
RETURN
Words:
Example 1:
RETURN
Before
Instruction
00 1A06
1248
0004
0001
0000
005404
PC
W15
Data 0906
Data 0908
SR
DS70157E-page 372
PIC24F
RETURN
Before
Instruction
00 5404
090A
0966
0000
0000
After
Instruction
PC
01 0004
W15
1244
Data 1244
0004
Data 1246
0001
SR
0000
; Return from subroutine
After
Instruction
PC
00 0966
W15
0906
Data 0906
0966
Data 0908
0000
SR
0000
RETURN
Return
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
None
Operation:
(W15) 2 W15
(TOS) (PC<22:16>)
(W15) 2 W15
(TOS<15:1) (PC<15:1>)
TOS<0> SFA bit
NOP Instruction Register
Status Affected:
SFA
Encoding:
0000
RETURN
0110
0000
0000
0000
0000
Description:
Words:
Cycles:
6 (5 if exception pending)
Example 1:
001A06
PC
W15
Data 1244
Data 1246
SR
Example 2:
Before
Instruction
00 1A06
1248
0004
0001
0000
005404
PC
W15
Data 0906
Data 0908
SR
RETURN
RETURN
Before
Instruction
00 5404
090A
0966
0000
0000
After
Instruction
PC
01 0004
W15
1244
Data 1244
0004
Data 1246
0001
SR
0000
; Return from subroutine
After
Instruction
PC
00 0966
W15
0906
Data 0906
0966
Data 0908
0000
SR
0000
5
Instruction
Descriptions
DS70157E-page 373
RLC
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
RLC{.B}
Operands:
f [0 ... 8191]
Operation:
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
Status Affected:
N, Z, C
Encoding:
1101
Description:
0110
1BDf
ffff
Rotate the contents of the file register f one bit to the left through the
Carry flag and place the result in the destination register. The Carry flag
of the STATUS Register is shifted into the Least Significant bit of the
destination, and it is then overwritten with the Most Significant bit of Ws.
The optional WREG operand determines the destination register. If
WREG is specified, the result is stored in WREG. If WREG is not
specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for f, 1 for WREG).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
RLC.B
0x1233
Before
Instruction
Data 1232 E807
SR
0000
DS70157E-page 374
After
Instruction
Data 1232 D007
SR
0009 (N, C = 1)
RLC
0x820, WREG
Before
After
Instruction
Instruction
WREG (W0)
5601
WREG (W0) 42DD
Data 0820 216E
Data 0820 216E
SR
0001 (C = 1)
SR
0000 (C = 0)
5
Instruction
Descriptions
DS70157E-page 375
RLC
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
RLC{.B}
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
Operands:
Operation:
dsPIC33F dsPIC33E
X
dppp
ssss
Status Affected:
N, Z, C
Encoding:
1101
Description:
0010
1Bqq
qddd
Rotate the contents of the source register Ws one bit to the left through
the Carry flag and place the result in the destination register Wd. The
Carry flag of the STATUS register is shifted into the Least Significant bit
of Wd, and it is then overwritten with the Most Significant bit of Ws.
Either register direct or indirect addressing may be used for Ws and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
RLC.B
W0, W3
Before
Instruction
W0
9976
W3
5879
SR
0001 (C = 1)
DS70157E-page 376
After
Instruction
W0
9976
W3 58ED
SR
0009 (N = 1)
RLC
[W2++], [W8]
Before
After
Instruction
Instruction
W2
2008
W2 200A
W8 094E
W8 094E
Data 094E
3689
Data 094E
8082
Data 2008 C041
Data 2008 C041
SR
0001 (C = 1)
SR
0009 (N, C = 1)
5
Instruction
Descriptions
DS70157E-page 377
RLNC
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
N, Z
Encoding:
RLNC{.B}
1101
Description:
0110
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
0BDf
ffff
Rotate the contents of the file register f one bit to the left and place the
result in the destination register. The Most Significant bit of f is stored in
the Least Significant bit of the destination, and the Carry flag is not
affected.
The optional WREG operand determines the destination register. If
WREG is specified, the result is stored in WREG. If WREG is not
specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
RLNC.B
0x1233
Before
Instruction
Data 1232 E807
SR
0000
Example 2:
RLNC
After
Instruction
Data 1233 D107
SR
0008 (N = 1)
0x820, WREG
Before
After
Instruction
Instruction
WREG (W0)
5601
WREG (W0) 42DC
Data 0820 216E
Data 0820 216E
SR
0001 (C = 1)
SR
0000 (C = 0)
DS70157E-page 378
RLNC
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
RLNC{.B}
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
Operands:
Operation:
Status Affected:
N, Z
Encoding:
Description:
1101
0010
0Bqq
dsPIC33F dsPIC33E
qddd
dppp
ssss
Rotate the contents of the source register Ws one bit to the left and place
the result in the destination register Wd. The Most Significant bit of Ws is
stored in the Least Significant bit of Wd, and the Carry flag is not
affected. Either register direct or indirect addressing may be used for Ws
and Wd.
The B bit selects byte or word operation (0 for byte, 1 for word).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
RLNC.B
W0, W3
Instruction
Descriptions
Before
Instruction
W0
9976
W3
5879
SR
0001 (C = 1)
After
Instruction
W0
9976
W3 58EC
SR
0009 (N, C = 1)
DS70157E-page 379
RLNC
Before
After
Instruction
Instruction
W2
2008
W2 200A
W8 094E
W8 094E
Data 094E
3689
Data 094E
8083
Data 2008 C041
Data 2008 C041
SR
0001 (C = 1)
SR
0009 (N, C = 1)
DS70157E-page 380
RRC
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
RRC{.B}
Operands:
f [0 ... 8191]
Operation:
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
Status Affected:
N, Z, C
Encoding:
1101
Description:
0111
1BDf
ffff
Rotate the contents of the file register f one bit to the right through the
Carry flag and place the result in the destination register. The Carry flag
of the STATUS Register is shifted into the Most Significant bit of the
destination, and it is then overwritten with the Least Significant bit of Ws.
The optional WREG operand determines the destination register. If
WREG is specified, the result is stored in WREG. If WREG is not
specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for byte, 1 for word).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
RRC.B
0x1233
Before
Instruction
Data 1232 E807
SR
0000
RRC
0x820, WREG
After
Instruction
Data 1232
7407
SR
0000
Before
After
Instruction
Instruction
WREG (W0)
5601
WREG (W0) 90B7
Data 0820 216E
Data 0820 216E
SR
0001 (C = 1)
SR
0008 (N = 1)
DS70157E-page 381
Instruction
Descriptions
Example 2:
RRC
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
RRC{.B}
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
Operands:
Operation:
dsPIC33F dsPIC33E
X
dppp
ssss
Status Affected:
N, Z, C
Encoding:
1101
Description:
0011
1Bqq
qddd
Rotate the contents of the source register Ws one bit to the right through
the Carry flag and place the result in the destination register Wd. The
Carry flag of the STATUS Register is shifted into the Most Significant bit
of Wd, and it is then overwritten with the Least Significant bit of Ws.
Either register direct or indirect addressing may be used for Ws and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
RRC.B
W0, W3
Before
Instruction
W0
9976
W3
5879
SR
0001 (C = 1)
DS70157E-page 382
After
Instruction
W0
9976
W3 58BB
SR
0008 (N = 1)
RRC
[W2++], [W8]
Before
After
Instruction
Instruction
W2
2008
W2 200A
W8 094E
W8 094E
Data 094E
3689
Data 094E E020
Data 2008 C041
Data 2008 C041
SR
0001 (C = 1)
SR
0009 (N, C = 1)
5
Instruction
Descriptions
DS70157E-page 383
RRNC
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
N, Z
Encoding:
RRNC{.B}
1101
Description:
0111
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
0BDf
ffff
Rotate the contents of the file register f one bit to the right and place the
result in the destination register. The Least Significant bit of f is stored in
the Most Significant bit of the destination, and the Carry flag is not
affected.
The optional WREG operand determines the destination register. If
WREG is specified, the result is stored in WREG. If WREG is not
specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
RRNC.B
0x1233
Before
Instruction
Data 1232 E807
SR
0000
Example 2:
RRNC
After
Instruction
Data 1232
7407
SR
0000
0x820, WREG
Before
After
Instruction
Instruction
WREG (W0)
5601
WREG (W0) 10B7
Data 0820 216E
Data 0820 216E
SR
0001 (C = 1)
SR
0001 (C = 1)
DS70157E-page 384
RRNC
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
RRNC{.B}
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
Operands:
Operation:
Status Affected:
N, Z
Encoding:
Description:
1101
0011
0Bqq
qddd
dsPIC33F dsPIC33E
X
dppp
ssss
Rotate the contents of the source register Ws one bit to the right and
place the result in the destination register Wd. The Least Significant bit
of Ws is stored in the Most Significant bit of Wd, and the Carry flag is not
affected. Either register direct or indirect addressing may be used for Ws
and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
RRNC.B
W0, W3
After
Instruction
W0
9976
W3 583B
SR
0001 (C = 1)
5
Instruction
Descriptions
Before
Instruction
W0
9976
W3
5879
SR
0001 (C = 1)
DS70157E-page 385
RRNC
[W2++], [W8]
Before
Instruction
W2
2008
W8 094E
Data 094E
3689
Data 2008 C041
SR
0000
DS70157E-page 386
After
Instruction
W2 200A
W8 094E
Data 094E E020
Data 2008 C041
SR
0008 (N = 1)
SAC
Store Accumulator
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
SAC
Acc,
{#Slit4,}
Wd
[Wd]
[Wd++]
[Wd--]
[--Wd]
[++Wd]
[Wd + Wb]
Operands:
Acc [A,B]
Slit4 [-8 ... +7]
Wb, Wd [W0 ... W15]
Operation:
ShiftSlit4(Acc) (optional)
(Acc[31:16]) Wd
Status Affected:
None
Encoding:
1100
Description:
1100
Awww
wrrr
rhhh
dddd
Words:
Cycles:
Example 1:
SAC A, #4, W5
; Right shift ACCA by 4
; Store result to W5
; CORCON = 0x0010 (SATDW = 1)
W5
ACCA
CORCON
SR
Instruction
Descriptions
W5
ACCA
CORCON
SR
Before
Instruction
B900
00 120F FF00
0010
0000
5
After
Instruction
0120
00 120F FF00
0010
0000
DS70157E-page 387
W5
ACCB
Data 2000
CORCON
SR
DS70157E-page 388
Before
Instruction
2000
FF C891 8F4C
5BBE
0010
0000
W5
ACCB
Data 2000
CORCON
SR
After
Instruction
2002
FF C891 1F4C
8000
0010
0000
SAC.R
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
SAC.R
Acc,
{#Slit4,}
Wd
[Wd]
[Wd++]
[Wd--]
[--Wd]
[++Wd]
[Wd + Wb]
Operands:
Acc [A,B]
Slit4 [-8 ... +7]
Wb [W0 ... W15]
Wd [W0 ... W15]
Operation:
ShiftSlit4(Acc) (optional)
Round(Acc)
(Acc[31:16]) Wd
Status Affected:
None
Encoding:
Description:
1100
1101
Awww
wrrr
rhhh
dddd
Words:
Cycles:
5
Instruction
Descriptions
DS70157E-page 389
SAC.R A, #4, W5
; Right shift ACCA by 4
; Store rounded result to W5
; CORCON = 0x0010 (SATDW = 1)
W5
ACCA
CORCON
SR
Example 2:
W5
ACCA
CORCON
SR
After
Instruction
0121
00 120F FF00
0010
0000
W5
ACCB
Data 2000
CORCON
SR
DS70157E-page 390
Before
Instruction
B900
00 120F FF00
0010
0000
Before
Instruction
2000
FF F891 8F4C
5BBE
0010
0000
W5
ACCB
Data 2000
CORCON
SR
After
Instruction
2002
FF F891 8F4C
8919
0010
0000
SE
Sign-Extend Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
0ddd
dppp
ssss
{label:}
SE
Ws,
dsPIC33F dsPIC33E
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Ws<7:0> Wnd<7:0>
If (Ws<7> = 1):
0xFF Wnd<15:8>
Else:
0 Wnd<15:8>
Status Affected:
N, Z, C
Encoding:
1111
Description:
1011
0000
Sign-extend the byte in Ws and store the 16-bit result in Wnd. Either
register direct or indirect addressing may be used for Ws, and register
direct addressing must be used for Wnd. The C flag is set to the
complement of the N flag.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1: This operation converts a byte to a word, and it uses no .B or
.W extension.
2: The source Ws is addressed as a byte operand, so any
address modification is by 1.
Words:
Cycles:
Example 1:
SE
W3, W4
Before
Instruction
W3
7839
W4
1005
SR
0000
Example 2:
SE
[W2++], W12
Instruction
Descriptions
Before
Instruction
W2
0900
W12
1002
Data 0900
008F
SR
0000
After
Instruction
W3
7839
W4
0039
SR
0001 (C = 1)
After
Instruction
W2
0901
W12 FF8F
Data 0900
008F
SR
0008 (N = 1)
DS70157E-page 391
SETM
Set f or WREG
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SETM{.B}
dsPIC33F dsPIC33E
X
ffff
ffff
f
WREG
Operands:
f [0 ... 8191]
Operation:
Status Affected:
None
Encoding:
1110
Description:
1111
1BDf
ffff
All the bits of the specified register are set to 1. If WREG is specified,
the bits of WREG are set. Otherwise, the bits of the specified file register
are set.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
SETM.B
0x891
Before
Instruction
Data 0890
2739
SR
0000
Example 2:
SETM
WREG
Before
Instruction
WREG (W0)
0900
SR
0000
DS70157E-page 392
After
Instruction
Data 0890 FF39
SR
0000
; Set WREG (Word mode)
After
Instruction
WREG (W0) FFFF
SR
0000
SETM
Set Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
qddd
d000
0000
{label:}
SETM{.B}
dsPIC33F dsPIC33E
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
Status Affected:
None
Encoding:
1110
Description:
1011
1Bqq
All the bits of the specified register are set to 1. Either register direct or
indirect addressing may be used for Wd.
The B bits selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
Words:
Cycles:
Example 1:
SETM.B
Note:
W13
Before
Instruction
W13
2739
SR
0000
Example 2:
SETM
[--W6]
After
Instruction
W6 124E
Data 124E FFFF
SR
0000
5
Instruction
Descriptions
Before
Instruction
W6
1250
Data 124E 3CD9
SR
0000
After
Instruction
W13 27FF
SR
0000
DS70157E-page 393
SFTAC
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
Acc [A,B]
Slit6 [-16 ... 16]
Operation:
Shiftk(Acc) Acc
Status Affected:
Encoding:
1100
Description:
SFTAC
1000
Acc,
A000
01kk
kkkk
#Slit6
0000
Words:
Cycles:
Example 1:
SFTAC A, #12
; Arithmetic right shift ACCA by 12
; Store result to ACCA
; CORCON = 0x0080 (SATA = 1)
ACCA
CORCON
SR
Example 2:
ACCA
CORCON
SR
After
Instruction
00 0001 20FF
0080
0000
SFTAC B, #-10
; Arithmetic left shift ACCB by 10
; Store result to ACCB
; CORCON = 0x0040 (SATB = 1)
ACCB
CORCON
SR
DS70157E-page 394
Before
Instruction
00 120F FF00
0080
0000
Before
Instruction
FF FFF1 8F4C
0040
0000
ACCB
CORCON
SR
After
Instruction
FF C63D 3000
0040
0000
SFTAC
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Acc [A,B]
Wb [W0 ... W15]
Operation:
Shift(Wb)(Acc) Acc
Status Affected:
Encoding:
1100
Description:
SFTAC
PIC24E
1000
Acc,
A000
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
ssss
Wb
Arithmetic shift the 40-bit contents of the specified accumulator and store
the result back into the accumulator. The Least Significant 6 bits of Wb
are used to specify the shift amount. The shift range is -16:16, where a
negative value indicates a left shift and a positive value indicates a right
shift. Any bits which are shifted out of the accumulator are lost.
The A bit selects the accumulator for the source/destination.
The s bits select the address of the shift count register.
Note 1: If saturation is enabled for the target accumulator (SATA,
CORCON<7> or SATB, CORCON<6>), the value stored to
the accumulator is subject to saturation.
2: If the shift amount is greater than 16 or less than -16, no
modification will be made to the accumulator, and an
arithmetic trap will occur.
Words:
Cycles:
Example 1:
SFTAC A, W0
; Arithmetic shift ACCA by (W0)
; Store result to ACCA
; CORCON = 0x0000 (saturation disabled)
W0
ACCA
CORCON
SR
Example 2:
W0
ACCA
CORCON
SR
After
Instruction
FFFC
03 20FA B090
0000
8800 (OA, OAB = 1)
SFTAC B, W12
; Arithmetic shift ACCB by (W12)
; Store result to ACCB
; CORCON = 0x0040 (SATB = 1)
Before
Instruction
000F
FF FFF1 8F4C
0040
0000
W12
ACCB
CORCON
SR
5
After
Instruction
000F
FF FFFF FFE3
0040
0000
Instruction
Descriptions
W12
ACCB
CORCON
SR
Before
Instruction
FFFC
00 320F AB09
0000
0000
DS70157E-page 395
SL
Shift Left f
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
SL{.B}
Operands:
f [0... 8191]
Operation:
Status Affected:
ffff
ffff
{,WREG}
N, Z, C
Encoding:
1101
Description:
dsPIC33F dsPIC33E
0100
0BDf
ffff
Shift the contents of the file register one bit to the left and place the result
in the destination register. The Most Significant bit of the file register is
shifted into the Carry bit of the STATUS register, and zero is shifted into
the Least Significant bit of the destination register.
The optional WREG operand determines the destination register. If
WREG is specified, the result is stored in WREG. If WREG is not
specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
SL.B
0x909
Before
Instruction
Data 0908
9439
SR
0000
Example 2:
SL
After
Instruction
Data 0908
0839
SR
0001 (C = 1)
0x1650, WREG
Before
Instruction
WREG (W0)
0900
Data 1650
4065
SR
0000
DS70157E-page 396
After
Instruction
WREG (W0) 80CA
Data 1650
4065
SR
0008 (N = 1)
SL
Shift Left Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SL{.B}
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
Operands:
Operation:
Status Affected:
dsPIC33F dsPIC33E
X
dppp
ssss
N, Z, C
Encoding:
1101
Description:
0000
0Bqq
qddd
Shift the contents of the source register Ws one bit to the left and place
the result in the destination register Wd. The Most Significant bit of Ws is
shifted into the Carry bit of the STATUS register, and 0 is shifted into the
Least Significant bit of Wd. Either register direct or indirect addressing
may be used for Ws and Wd.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
SL.B
W3, W4
5
; Shift left W3 (Byte mode)
; Store result to W4
Instruction
Descriptions
Before
Instruction
W3 78A9
W4
1005
SR
0000
After
Instruction
W3 78A9
W4
1052
SR
0001 (C = 1)
DS70157E-page 397
SL
[W2++], [W12]
Before
Instruction
W2
0900
W12
1002
Data 0900
800F
Data 1002
6722
SR
0000
DS70157E-page 398
After
Instruction
W2
0902
W12
1002
Data 0900
800F
Data 1002 001E
SR
0001 (C = 1)
SL
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
lit4<3:0> Shift_Val
Wnd<15:Shift_Val> = Wb<15-Shift_Val:0>
Wd<Shift_Val 1:0> = 0
Status Affected:
N, Z
Encoding:
1101
Description:
SL
Wb,
1101
#lit4,
0www
wddd
dsPIC33F dsPIC33E
X
d100
kkkk
Wnd
Shift left the contents of the source register Wb by the 4-bit unsigned
literal and store the result in the destination register Wnd. Any bits
shifted out of the source register are lost. Direct addressing must be
used for Wb and Wnd.
The w bits select the address of the base register.
The d bits select the destination register.
The k bits provide the literal operand, a five-bit integer number.
Note:
Words:
Cycles:
Example 1:
SL
W2, #4, W2
Before
Instruction
W2 78A9
SR
0000
Example 2:
SL
W3, #12, W8
Before
Instruction
W3
0912
W8
1002
SR
0000
; Shift left W2 by 4
; Store result to W2
After
Instruction
W2 8A90
SR
0008 (N = 1)
; Shift left W3 by 12
; Store result to W8
After
Instruction
W3
0912
W8
2000
SR
0000
5
Instruction
Descriptions
DS70157E-page 399
SL
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
Operation:
Wns<4:0> Shift_Val
Wnd<15:Shift_Val> = Wb<15 Shift_Val:0>
Wd<Shift_Val 1:0> = 0
Status Affected:
N, Z
Encoding:
1101
Description:
SL
Wb,
1101
0www
Wns,
dsPIC33F dsPIC33E
X
d000
ssss
Wnd
wddd
Shift left the contents of the source register Wb by the 5 Least Significant
bits of Wns (only up to 15 positions) and store the result in the destination register Wnd. Any bits shifted out of the source register are lost.
Register direct addressing must be used for Wb, Wns and Wnd.
The w bits select the address of the base register.
The d bits select the destination register.
The s bits select the source register.
Note 1: This instruction operates in Word mode only.
2: If Wns is greater than 15, Wnd will be loaded with 0x0.
Words:
Cycles:
Example 1:
SL
W0, W1, W2
Before
Instruction
W0 09A4
W1
8903
W2 78A9
SR
0000
Example 2:
SL
W4, W5, W6
Before
Instruction
W4 A409
W5 FF01
W6
0883
SR
0000
DS70157E-page 400
After
Instruction
W0 09A4
W1
8903
W2 4D20
SR
0000
; Shift left W4 by W5<0:4>
; Store result to W6
After
Instruction
W4 A409
W5 FF01
W6
4812
SR
0000
SUB
Implemented in:
PIC24F
PIC24H
PIC24E
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
1011
Description:
0101
Syntax:
Encoding:
SUB{.B}
ffff
ffff
{,WREG}
0BDf
ffff
Subtract the contents of the default working register WREG from the
contents of the specified file register, and place the result in the
destination register. The optional WREG operand determines the
destination register. If WREG is specified, the result is stored in WREG.
If WREG is not specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
SUB.B 0x1FFF
Before
Instruction
WREG (W0)
7804
Data 1FFE
9439
SR
0000
Example 2:
SUB
0xA04, WREG
Before
Instruction
WREG (W0)
6234
Data 0A04
4523
SR
0000
After
Instruction
WREG (W0)
7804
Data 1FFE
9039
SR
0009 (N, C = 1)
; Sub. WREG from (0xA04) (Word mode)
; Store result to WREG
After
Instruction
WREG (W0) E2EF
Data 0A04
4523
SR
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 401
SUB
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
kkkk
kkkk
dddd
Syntax:
{label:}
SUB{.B}
Operands:
Operation:
(Wn) lit10 Wn
Status Affected:
DC, N, OV, Z, C
Encoding:
1011
Description:
0001
#lit10,
0Bkk
dsPIC33F dsPIC33E
Wn
Subtract the 10-bit unsigned literal operand from the contents of the
working register Wn, and store the result back in the working register
Wn. Register direct addressing must be used for Wn.
The B bit selects byte or word operation.
The k bits specify the literal operand.
The d bits select the address of the working register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: For byte operations, the literal must be specified as an unsigned
value [0:255]. See Section 4.6 Using 10-bit Literal Operands for information on using 10-bit literal operands in Byte
mode.
Words:
Cycles:
Example 1:
SUB.B
#0x23, W0
Before
Instruction
W0
7804
SR
0000
Example 2:
SUB
#0x108, W4
Before
Instruction
W4
6234
SR
0000
DS70157E-page 402
After
Instruction
W0 78E1
SR
0008 (N = 1)
; Sub. 0x108 from W4 (Word mode)
; Store result to W4
After
Instruction
W4 612C
SR
0001 (C = 1)
SUB
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SUB{.B}
Wb,
#lit5,
dsPIC33F dsPIC33E
X
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
(Wb) lit5 Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
0101
Description:
0www
wBqq
qddd
d11k
kkkk
Subtract the 5-bit unsigned literal operand from the contents of the base
register Wb, and place the result in the destination register Wd. Register
direct addressing must be used for Wb. Register direct or indirect
addressing must be used for Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The k bits provide the literal operand, a five-bit integer number.
Note:
Words:
Cycles:
Example 1:
SUB.B
W4, #0x10, W5
Before
Instruction
W4
1782
W5
7804
SR
0000
Example 2:
SUB
5
Instruction
Descriptions
After
Instruction
W4
1782
W5
7872
SR
0005 (OV, C = 1)
Before
Instruction
W0
F230
W2
2004
Data 2004 A557
SR
0000
After
Instruction
W0
F230
W2
2006
Data 2004
F228
SR
0009 (N, C = 1)
DS70157E-page 403
SUB
Subtract Ws from Wb
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SUB{.B}
Operands:
Operation:
(Wb) (Ws) Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
0101
Description:
0www
Wb,
wBqq
dsPIC33F dsPIC33E
X
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
qddd
dppp
ssss
Subtract the contents of the source register Ws from the contents of the
base register Wb and place the result in the destination register Wd.
Register direct addressing must be used for Wb. Either register direct or
indirect addressing may be used for Ws and Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
SUB.B
W0, W1, W0
Before
Instruction
W0
1732
W1
7844
SR
0000
DS70157E-page 404
After
Instruction
W0 17EE
W1
7844
SR
0108 (DC, N = 1)
SUB
Before
Instruction
W7
2450
W8
1808
W9
2020
Data 1808 92E4
Data 2020 A557
SR
0000
;
;
;
;
After
Instruction
W7
2450
W8 180A
W9
2022
Data 1808 92E4
Data 2020 916C
SR 010C (DC, N, OV = 1)
5
Instruction
Descriptions
DS70157E-page 405
SUB
Subtract Accumulators
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
Acc [A,B]
Operation:
If (Acc = A):
ACCA ACCB ACCA
Else:
ACCB ACCA ACCB
Status Affected:
Encoding:
SUB
PIC24E
1100
Description:
1011
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
0000
Acc
A011
Words:
Cycles:
Example 1:
SUB
Before
Instruction
76 120F 098A
23 F312 BC17
0000
0000
ACCA
ACCB
CORCON
SR
Example 2:
SUB
ACCA
ACCB
CORCON
SR
DS70157E-page 406
ACCA
ACCB
CORCON
SR
After
Instruction
52 1EFC 4D73
23 F312 BC17
0000
1100 (OA, OB = 1)
Before
Instruction
FF 9022 2EE1
00 2456 8F4C
0040
0000
ACCA
ACCB
CORCON
SR
After
Instruction
FF 9022 2EE1
00 7FFF FFFF
0040
1400 (SB, SAB = 1)
SUBB
Implemented in:
PIC24F
PIC24H
PIC24E
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Description:
1011
0101
Syntax:
Encoding:
SUBB{.B}
ffff
ffff
{,WREG}
1BDf
ffff
Subtract the contents of the default working register WREG and the
Borrow flag (Carry flag inverse, C) from the contents of the specified file
register and place the result in the destination register. The optional
WREG operand determines the destination register. If WREG is
specified, the result is stored in WREG. If WREG is not specified, the
result is stored in the file register
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
3: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR.
These instructions can only clear Z.
Words:
Cycles:
Example 1:
SUBB.B 0x1FFF
Before
Instruction
WREG (W0)
7804
Data 1FFE
9439
SR
0000
Example 2:
After
Instruction
WREG (W0)
0000
Data 0A04
6235
SR
0001 (C = 1)
5
Instruction
Descriptions
Before
Instruction
WREG (W0)
6234
Data 0A04
6235
SR
0000
After
Instruction
WREG (W0)
7804
Data 1FFE
8F39
SR
0008 (N = 1)
DS70157E-page 407
SUBB
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
kkkk
kkkk
dddd
Syntax:
{label:}
SUBB{.B}
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
1011
Description:
0001
#lit10,
1Bkk
dsPIC33F dsPIC33E
Wn
Subtract the unsigned 10-bit literal operand and the Borrow flag (Carry
flag inverse, C) from the contents of the working register Wn, and store
the result back in the working register Wn. Register direct addressing
must be used for Wn.
The B bit selects byte or word operation (0 for word, 1 for byte).
The k bits specify the literal operand.
The d bits select the address of the working register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .w extension to
denote a word operation, but it is not required.
2: For byte operations, the literal must be specified as an
unsigned value [0:255]. See Section 4.6 Using 10-bit Literal
Operands for information on using 10-bit literal operands in
Byte mode.
3: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR.
These instructions can only clear Z.
Words:
Cycles:
Example 1:
SUBB.B
#0x23, W0
Before
Instruction
W0
7804
SR
0000
Example 2:
SUBB
#0x108, W4
Before
Instruction
W4
6234
SR
0001 (C = 1)
DS70157E-page 408
After
Instruction
W0 78E0
SR
0108 (DC, N = 1)
; Sub. 0x108 and C from W4 (Word mode)
; Store result to W4
After
Instruction
W4 612C
SR
0001 (C = 1)
SUBB
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SUBB{.B}
Wb,
#lit5,
dsPIC33F dsPIC33E
X
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
0101
Description:
1www
wBqq
qddd
d11k
kkkk
Subtract the 5-bit unsigned literal operand and the Borrow flag (Carry
flag inverse, C) from the contents of the base register Wb and place the
result in the destination register Wd. Register direct addressing must be
used for Wb. Either register direct or indirect addressing may be used for
Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The k bits provide the literal operand, a five-bit integer number.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR.
These instructions can only clear Z.
Words:
Cycles:
Example 1:
SUBB.B
W4, #0x10, W5
Before
Instruction
W4
1782
W5
7804
SR
0000
After
Instruction
W4
1782
W5
7871
SR
0005 (OV, C = 1)
5
Instruction
Descriptions
DS70157E-page 409
SUBB
Before
After
Instruction
Instruction
W0
0009
W0
0009
W2
2004
W2
2006
Data 2004 A557
Data 2004
0000
SR
0020 (Z = 1)
SR
0103 (DC, Z, C = 1)
DS70157E-page 410
SUBB
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SUBB{.B}
Wb,
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
0101
Description:
1www
wBqq
dsPIC33F dsPIC33E
X
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
qddd
dppp
ssss
Subtract the contents of the source register Ws and the Borrow flag
(Carry flag inverse, C) from the contents of the base register Wb, and
place the result in the destination register Wd. Register direct addressing
must be used for Wb. Register direct or indirect addressing may be used
for Ws and Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR.
These instructions can only clear Z.
Words:
Cycles:
Example 1:
SUBB.B
W0, W1, W0
After
Instruction
W0 17ED
W1
7844
SR
0108 (DC, N = 1)
5
Instruction
Descriptions
Before
Instruction
W0
1732
W1
7844
SR
0000
DS70157E-page 411
SUBB
W7,[W8++],[W9++] ;
;
;
;
Before
Instruction
W7
2450
W8
1808
W9
2022
Data 1808 92E4
Data 2022 A557
SR
0000
DS70157E-page 412
After
Instruction
W7
2450
W8 180A
W9
2024
Data 1808 92E4
Data 2022 916C
SR 010C (DC, N, OV = 1)
SUBBR
Implemented in:
PIC24F
PIC24H
PIC24E
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
Description:
1011
SUBBR{.B} f
1101
ffff
ffff
{,WREG}
1BDf
ffff
Subtract the contents of the specified file register f and the Borrow flag
(Carry flag inverse, C) from the contents of WREG, and place the result
in the destination register. The optional WREG operand determines the
destination register. If WREG is specified, the result is stored in WREG.
If WREG is not specified, the result is stored in the file register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
3: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR.
These instructions can only clear Z.
Words:
Cycles:
Example 1:
SUBBR.B 0x803
Before
After
Instruction
Instruction
WREG (W0)
7804
WREG (W0)
7804
Data 0802
9439
Data 0802
6F39
SR
0002 (Z = 1)
SR
0000
Example 2:
SUBBR 0xA04, WREG ; Sub. (0xA04) and C from WREG (Word mode)
; Store result to WREG
Before
Instruction
WREG (W0)
6234
Data 0A04
6235
SR
0000
After
Instruction
WREG (W0) FFFE
Data 0A04
6235
SR
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 413
SUBBR
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SUBBR{.B} Wb,
#lit5,
dsPIC33F dsPIC33E
X
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
0001
Description:
1www
wBqq
qddd
d11k
kkkk
Subtract the contents of the base register Wb and the Borrow flag (Carry
flag inverse, C) from the 5-bit unsigned literal and place the result in the
destination register Wd. Register direct addressing must be used for Wb.
Register direct or indirect addressing must be used for Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The k bits provide the literal operand, a five-bit integer number.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR.
These instructions can only clear Z.
Words:
Cycles:
Example 1:
SUBBR.B
Before
Instruction
W0
F310
W1 786A
SR
0003 (Z, C = 1)
DS70157E-page 414
After
Instruction
W0
F310
W1
7800
SR
0103 (DC, Z, C = 1)
SUBBR
Before
After
Instruction
Instruction
W0
0009
W0
0009
W2
2004
W2
2006
Data 2004 A557
Data 2004 FFFE
SR
0020 (Z = 1)
SR
0108 (DC, N = 1)
5
Instruction
Descriptions
DS70157E-page 415
SUBBR
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SUBBR{.B} Wb,
Operands:
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
0001
Description:
1www
wBqq
dsPIC33F dsPIC33E
X
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
qddd
dppp
ssss
Subtract the contents of the base register Wb and the Borrow flag (Carry
flag inverse, C) from the contents of the source register Ws and place
the result in the destination register Wd. Register direct addressing must
be used for Wb. Register direct or indirect addressing may be used for
Ws and Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The Z flag is sticky for ADDC, CPB, SUBB and SUBBR.
These instructions can only clear Z.
Words:
Cycles:
Example 1:
SUBBR.B
W0, W1, W0
Before
Instruction
W0
1732
W1
7844
SR
0000
DS70157E-page 416
After
Instruction
W0
1711
W1
7844
SR
0001 (C = 1)
SUBBR W7,[W8++],[W9++] ;
;
;
;
Before
Instruction
W7
2450
W8
1808
W9
2022
Data 1808 92E4
Data 2022 A557
SR
0000
After
Instruction
W7
2450
W8 180A
W9
2024
Data 1808 92E4
Data 2022 6E93
SR
0005 (OV, C = 1)
5
Instruction
Descriptions
DS70157E-page 417
SUBR
Implemented in:
PIC24F
PIC24H
PIC24E
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
DC, N, OV, Z, C
Encoding:
SUBR{.B} f
1011
Description:
1101
ffff
ffff
{,WREG}
0BDf
ffff
Subtract the contents of the specified file register from the contents of
the default working register WREG, and place the result in the
destination register. The optional WREG operand determines the
destination register. If WREG is specified, the result is stored in WREG.
If WREG is not specified, the result is stored in the file register
The B bit selects byte or word operation (0 for word, 1 for byte).
The D bit selects the destination (0 for WREG, 1 for file register).
The f bits select the address of the file register.
Note 1: The extension .B in the instruction denotes a byte operation
rather than a word operation. You may use a .W extension to
denote a word operation, but it is not required.
2: The WREG is set to working register W0.
Words:
Cycles:
Example 1:
SUBR.B
0x1FFF
Before
Instruction
WREG (W0)
7804
Data 1FFE
9439
SR
0000
Example 2:
SUBR
After
Instruction
WREG (W0)
7804
Data 1FFE
7039
SR
0000
0xA04, WREG
Before
Instruction
WREG (W0)
6234
Data 0A04
6235
SR
0000
DS70157E-page 418
After
Instruction
WREG (W0) FFFF
Data 0A04
6235
SR
0008 (N = 1)
SUBR
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SUBR{.B}
Wb,
#lit5
dsPIC33F dsPIC33E
X
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
lit5 (Wb) Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
0001
Description:
0www
wBqq
qddd
d11k
kkkk
Subtract the contents of the base register Wb from the unsigned 5-bit
literal operand, and place the result in the destination register Wd.
Register direct addressing must be used for Wb. Either register direct or
indirect addressing may be used for Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The k bits provide the literal operand, a five-bit integer number.
Note:
Words:
Cycles:
Example 1:
SUBR.B
W0, #0x10, W1
Before
Instruction
W0
F310
W1 786A
SR
0000
Example 2:
SUBR
After
Instruction
W0
0009
W2
2006
Data 2004 FFFF
SR
0108 (DC, N = 1)
DS70157E-page 419
5
Instruction
Descriptions
After
Instruction
W0
F310
W1
7800
SR
0103 (DC, Z, C = 1)
Before
Instruction
W0
0009
W2
2004
Data 2004 A557
SR
0000
SUBR
Subtract Wb from Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
SUBR{.B}
Operands:
Operation:
(Ws) (Wb) Wd
Status Affected:
DC, N, OV, Z, C
Encoding:
0001
Description:
0www
Wb,
wBqq
dsPIC33F dsPIC33E
X
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
qddd
dppp
ssss
Subtract the contents of the base register Wb from the contents of the
source register Ws and place the result in the destination register Wd.
Register direct addressing must be used for Wb. Either register direct or
indirect addressing may be used for Ws and Wd.
The w bits select the address of the base register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
Example 1:
SUBR.B
W0, W1, W0
Before
Instruction
W0
1732
W1
7844
SR
0000
DS70157E-page 420
After
Instruction
W0
1712
W1
7844
SR
0001 (C = 1)
SUBR
Before
Instruction
W7
2450
W8
1808
W9
2022
Data 1808 92E4
Data 2022 A557
SR
0000
;
;
;
;
After
Instruction
W7
2450
W8 180A
W9
2024
Data 1808 92E4
Data 2022 6E94
SR
0005 (OV, C = 1)
5
Instruction
Descriptions
DS70157E-page 421
SWAP
Implemented in:
PIC24F
PIC24H
PIC24E
1B00
0000
0000
ssss
Syntax:
{label:}
Operands:
Operation:
Status Affected:
None
Encoding:
SWAP{.B} Wn
1111
Description:
1101
Swap the contents of the working register Wn. In Word mode, the two
bytes of Wn are swapped. In Byte mode, the two nibbles of the Least
Significant Byte of Wn are swapped, and the Most Significant Byte of
Wn is unchanged. Register direct addressing must be used for Wn.
The B bit selects byte or word operation (0 for word, 1 for byte).
The s bits select the address of the working register.
Note:
Words:
Cycles:
Example 1:
SWAP.B
W0
Before
Instruction
W0 AB87
SR
0000
Example 2:
SWAP
W0
Before
Instruction
W0
8095
SR
0000
DS70157E-page 422
After
Instruction
W0 AB78
SR
0000
; Byte swap (W0)
After
Instruction
W0
9580
SR
0000
TBLRDH
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
TBLRDH{.B} [Ws],
dsPIC33F dsPIC33E
X
Wd
[Ws++],
[Wd]
[Ws--],
[Wd++]
[++Ws],
[Wd--]
[--Ws],
[++Wd]
[--Wd]
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1010
1Bqq
qddd
dppp
ssss
Read the contents of the most significant word of program memory and
store it to the destination register Wd. The target word address of program
memory is formed by concatenating the 8-bit Table Pointer register,
TBLPAG<7:0>, with the effective address specified by Ws. Indirect
addressing must be used for Ws, and either register direct or indirect
addressing may be used for Wd.
In Word mode, zero is stored to the Most Significant Byte of the destination
register (due to non-existent program memory) and the third program
memory byte (PM<23:16>) at the specified program memory address is
stored to the Least Significant Byte of the destination register.
In Byte mode, the source address depends on the contents of Ws. If Ws is
not word-aligned, zero is stored to the destination register (due to
non-existent program memory). If Ws is word-aligned, the third program
memory byte (PM<23:16>) at the specified program memory address is
stored to the destination register.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
The extension .B in the instruction denotes a byte move rather
than a word move. You may use a .W extension to denote a
word move, but it is not required.
Words:
Cycles:
DS70157E-page 423
Instruction
Descriptions
Note:
TBLRDH.B
W0
W1
Data 0F70
Program 01 0812
TBLPAG
SR
Example 2:
DS70157E-page 424
Before
Instruction
0812
0F71
0944
EF 2042
0001
0000
TBLRDH
W6
W8
Program 00 3406
TBLPAG
SR
[W0], [W1++]
After
Instruction
W0
0812
W1
0F72
Data 0F70
EF44
Program 01 0812
EF 2042
TBLPAG
0001
SR
0000
[W6++], W8
Before
Instruction
3406
65B1
29 2E40
0000
0000
After
Instruction
W6
3408
W8
0029
Program 00 3406
29 2E40
TBLPAG
0000
SR
0000
TBLRDL
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
TBLRDL{.B} [Ws],
dsPIC33F dsPIC33E
X
dppp
ssss
Wd
[Ws++],
[Wd]
[Ws--],
[Wd++]
[++Ws],
[Wd--]
[--Ws],
[++Wd]
[--Wd]
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1010
0Bqq
qddd
Read the contents of the least significant word of program memory and
store it to the destination register Wd. The target word address of program
memory is formed by concatenating the 8-bit Table Pointer register,
TBLPAG<7:0>, with the effective address specified by Ws. Indirect
addressing must be used for Ws, and either register direct or indirect
addressing may be used for Wd.
In Word mode, the lower 2 bytes of program memory are stored to the
destination register. In Byte mode, the source address depends on the
contents of Ws. If Ws is not word-aligned, the second byte of the program
memory word (PM<15:7>) is stored to the destination register. If Ws is
word-aligned, the first byte of the program memory word (PM<7:0>) is
stored to the destination register.
The B bit selects byte or word operation (0 for word mode, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Cycles:
5
Instruction
Descriptions
Words:
DS70157E-page 425
TBLRDL.B
W0
W1
Data 0F70
Program 01 0812
TBLPAG
SR
Example 2:
DS70157E-page 426
Before
Instruction
0813
0F71
0944
EF 2042
0001
0000
TBLRDL
W6
W8
Data 1202
Program 00 3406
TBLPAG
SR
[W0++], W1
After
Instruction
W0
0814
W1
0F20
Data 0F70
EF44
Program 01 0812
EF 2042
TBLPAG
0001
SR
0000
[W6], [W8++]
Before
Instruction
3406
1202
658B
29 2E40
0000
0000
After
Instruction
W6
3408
W8
1204
Data 1202
2E40
Program 00 3406
29 2E40
TBLPAG
0000
SR
0000
TBLWTH
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
TBLWTH{.B} Ws,
dsPIC33F dsPIC33E
X
[Wd]
[Ws],
[Wd++]
[Ws++],
[Wd--]
[Ws--],
[++Wd]
[++Ws],
[--Wd]
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1011
1Bqq
qddd
dppp
ssss
Store the contents of the working source register Ws to the most significant
word of program memory. The destination word address of program memory is formed by concatenating the 8-bit Table Pointer register,
TBLPAG<7:0>, with the effective address specified by Wd. Either direct or
indirect addressing may be used for Ws, and indirect addressing must be
used for Wd.
Since program memory is 24 bits wide, this instruction can only write to the
upper byte of program memory (PM<23:16>). This may be performed using
a Wd that is word-aligned in Byte mode or Word mode. If Byte mode is
used with a Wd that is not word-aligned, no operation is performed.
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
5
Instruction
Descriptions
DS70157E-page 427
TBLWTH.B
W0
W1
Data 0812
Program 01 0F70
TBLPAG
SR
Before
Instruction
0812
0F70
0944
EF 2042
0001
0000
Note:
Example 2:
Note:
DS70157E-page 428
After
Instruction
W0
0812
W1
0F70
Data 0812
EF44
Program 01 0F70
44 2042
TBLPAG
0001
SR
0000
Only the Program Latch is written to. The contents of program memory
are not updated until the Flash memory is programmed using the
procedure described in the specific device family reference manual.
TBLWTH
W6
W8
Program 00 0870
TBLPAG
SR
[W0++], [W1]
W6, [W8++]
Before
Instruction
0026
0870
22 3551
0000
0000
After
Instruction
W6
0026
W8
0872
Program 00 0870
26 3551
TBLPAG
0000
SR
0000
Only the Program Latch is written to. The contents of program memory
are not updated until the Flash memory is programmed using the
procedure described in the specific device family reference manual.
TBLWTL
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
TBLWTL{.B} Ws,
dsPIC33F dsPIC33E
X
dppp
ssss
[Wd]
[Ws],
[Wd++]
[Ws++],
[Wd--]
[Ws--],
[++Wd]
[++Ws],
[--Wd]
[--Ws],
Operands:
Operation:
Status Affected:
None
Encoding:
Description:
1011
1011
0Bqq
qddd
Store the contents of the working source register Ws to the least significant
word of program memory. The destination word address of program
memory is formed by concatenating the 8-bit Table Pointer register,
TBLPAG<7:0>, with the effective address specified by Wd. Either direct or
indirect addressing may be used for Ws, and indirect addressing must be
used for Wd.
In Word mode, Ws is stored to the lower 2 bytes of program memory. In
Byte mode, the Least Significant bit of Wd determines the destination byte.
If Wd is not word-aligned, Ws is stored to the second byte of program
memory (PM<15:8>). If Wd is word-aligned, Ws is stored to the first byte of
program memory (PM<7:0>).
The B bit selects byte or word operation (0 for word, 1 for byte).
The q bits select the destination Address mode.
The d bits select the destination register.
The p bits select the source Address mode.
The s bits select the source register.
Note:
Words:
Cycles:
5
Instruction
Descriptions
DS70157E-page 429
TBLWTL.B
W0
W1
Program 00 1224
TBLPAG
SR
Before
Instruction
6628
1225
78 0080
0000
0000
Note:
Example 2:
Note:
DS70157E-page 430
After
Instruction
W0
6628
W1
1226
Program 01 1224
78 2880
TBLPAG
0000
SR
0000
Only the Program Latch is written to. The contents of program memory
are not updated until the Flash memory is programmed using the
procedure described in the specific device family reference manual.
TBLWTL
W6
W8
Data 1600
Program 01 7208
TBLPAG
SR
W0, [W1++]
[W6], [W8]
Before
Instruction
1600
7208
0130
09 0002
0001
0000
After
Instruction
W6
1600
W8
7208
Data 1600
0130
Program 01 7208
09 0130
TBLPAG
0001
SR
0000
Only the Program Latch is written to. The contents of program memory
are not updated until the Flash memory is programmed using the
procedure described in the specific device family reference manual.
ULNK
Implemented in:
PIC24F
PIC24H
Syntax:
{label:}
Operands:
None
Operation:
W14 W15
(W15) 2 W15
(TOS) W14
Status Affected:
None
Encoding:
1111
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
0000
0000
ULNK
1010
1000
0000
Description:
Words:
Cycles:
Example 1:
ULNK
Before
Instruction
W14
2002
W15
20A2
Data 2000
2000
SR
0000
Example 2:
ULNK
After
Instruction
W14
2000
W15
2000
Data 2000
2000
SR
0000
Before
Instruction
W14
0802
W15
0812
Data 0800
0800
SR
0000
After
Instruction
W14
0800
W15
0800
Data 0800
0800
SR
0000
5
Instruction
Descriptions
DS70157E-page 431
ULNK
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
dsPIC33F dsPIC33E
X
Syntax:
{label:}
Operands:
None
Operation:
W14 W15
(W15) 2 W15
(TOS) W14
0 SFA bit
Status Affected:
SFA
Encoding:
1111
ULNK
1010
1000
0000
0000
0000
Description:
Words:
Cycles:
Example 1:
ULNK
Before
Instruction
W14
2002
W15
20A2
Data 2000
2000
SR
0000
Example 2:
ULNK
After
Instruction
W14
2000
W15
2000
Data 2000
2000
SR
0000
Before
Instruction
W14
0802
W15
0812
Data 0800
0800
SR
0000
DS70157E-page 432
After
Instruction
W14
0800
W15
0800
Data 0800
0800
SR
0000
XOR
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
Syntax:
{label:}
Operands:
f [0 ... 8191]
Operation:
Status Affected:
N, Z
Encoding:
XOR{.B}
1011
Description:
0110
dsPIC33F dsPIC33E
X
ffff
ffff
{,WREG}
1BDf
ffff
Words:
Cycles:
Example 1:
XOR.B
0x1FFF
Before
Instruction
WREG (W0)
7804
Data 1FFE
9439
SR
0000
Example 2:
XOR
After
Instruction
WREG (W0)
7804
Data 1FFE
9039
SR
0008 (N = 1)
0xA04, WREG
Before
Instruction
WREG (W0)
6234
Data 0A04 A053
SR
0000
After
Instruction
WREG (W0) C267
Data 0A04 A053
SR
0008 (N = 1)
5
Instruction
Descriptions
DS70157E-page 433
XOR
Implemented in:
PIC24F
PIC24H
PIC24E
dsPIC30F
kkkk
kkkk
dddd
Syntax:
{label:}
Operands:
Operation:
lit10.XOR.(Wn) Wn
Status Affected:
N, Z
Encoding:
1011
Description:
XOR{.B}
0010
#lit10,
1Bkk
dsPIC33F dsPIC33E
Wn
Words:
Cycles:
Example 1:
XOR.B
#0x23, W0
Before
Instruction
W0
7804
SR
0000
Example 2:
XOR
#0x108, W4
Before
Instruction
W4
6134
SR
0000
DS70157E-page 434
After
Instruction
W0
7827
SR
0000
; XOR 0x108 and W4 (Word mode)
; Store result to W4
After
Instruction
W4 603C
SR
0000
XOR
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
XOR{.B}
Wb,
#lit5,
dsPIC33F dsPIC33E
X
Wd
[Wd]
[Wd++]
[Wd--]
[++Wd]
[--Wd]
Operands:
Operation:
(Wb).XOR.lit5 Wd
Status Affected:
N, Z
Encoding:
0110
Description:
1www
wBqq
qddd
d11k
kkkk
Words:
Cycles:
Example 1:
XOR.B
W4, #0x14, W5
Before
Instruction
W4
C822
W5
1200
SR
0000
After
Instruction
W4
C822
W5
1234
SR
0000
5
Instruction
Descriptions
DS70157E-page 435
XOR
Before
Instruction
W2
8505
W8
1004
Data 1004
6628
SR
0000
DS70157E-page 436
After
Instruction
W2
8505
W8
1006
Data 1004
851A
SR
0008 (N = 1)
XOR
Exclusive OR Wb and Ws
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
{label:}
XOR{.B}
Operands:
Operation:
(Wb).XOR.(Ws) Wd
Status Affected:
N, Z
Encoding:
0110
Description:
1www
Wb,
wBqq
dsPIC33F dsPIC33E
X
Ws,
Wd
[Ws],
[Wd]
[Ws++],
[Wd++]
[Ws--],
[Wd--]
[++Ws],
[++Wd]
[--Ws],
[--Wd]
qddd
dppp
ssss
Words:
Cycles:
Example 1:
XOR.B
After
Instruction
W1 AAAA
W5
2001
W9
2601
Data 2000
115A
Data 2600
00F0
SR
0008 (N = 1)
5
Instruction
Descriptions
Before
Instruction
W1 AAAA
W5
2000
W9
2600
Data 2000
115A
Data 2600
0000
SR
0000
DS70157E-page 437
XOR
W1, W5, W9
Before
Instruction
W1 FEDC
W5
1234
W9
A34D
SR
0000
DS70157E-page 438
After
Instruction
W1 FEDC
W5
1234
W9
ECE8
SR
0008 (N = 1)
ZE
Zero-Extend Wn
Implemented in:
Syntax:
PIC24F
PIC24H
PIC24E
dsPIC30F
0ddd
dppp
ssss
{label:}
ZE
Ws,
dsPIC33F dsPIC33E
Wnd
[Ws],
[Ws++],
[Ws--],
[++Ws],
[--Ws],
Operands:
Operation:
Ws<7:0> Wnd<7:0>
0 Wnd<15:8>
Status Affected:
N, Z, C
Encoding:
1111
Description:
1011
1000
Words:
Cycles:
Example 1:
ZE
W3, W4
; zero-extend W3
; Store result to W4
Before
Instruction
W3
7839
W4
1005
SR
0000
Example 2:
ZE
[W2++], W12
; Zero-extend [W2]
; Store to W12
; Post-increment W2
Instruction
Descriptions
Before
Instruction
W2
0900
W12
1002
Data 0900
268F
SR
0000
After
Instruction
W3
7839
W4
0039
SR
0001 (C = 1)
After
Instruction
W2
0901
W12
008F
Data 0900
268F
SR
0001 (C = 1)
DS70157E-page 439
DS70157E-page 440
6
Reference
Section 6. Reference
HIGHLIGHTS
This section of the manual contains the following major topics:
6.1
6.2
6.3
DS70157E-page 441
DS70157E-page 442
The complete opcode for each instruction may be determined by the instruction
descriptions in Section 5. Instruction Descriptions, using Table 5-1 through
Table 5-12.
Instruction Encoding
Opcode<19:16>
0000
0000
NOP
0001
BRA
CALL
GOTO
RCALL
0010
0011
CALL
0001
0100
GOTO
0101
RETLW
0110
RETFIE
RETURN
0111
RCALL
Opcode<23:20>
DO
1001
1010
1011
REPEAT
1100
(1)
1101
1110
(1)
(1)
1111
BRA
(OA)
BRA
(OB)
BRA
(SA)
BRA(1)
(SB)
BRA
(GT)
BRA
(GE)
BRA
(GTU)
SUBBR
MOV
BRA
(OV)
BRA
(C)
BRA
(Z)
BRA
(N)
BRA
(LE)
BRA
(LT)
BRA
(LEU)
BRA
BRA (NOV)
BRA
(NC)
BRA
(NZ)
BRA
(NN)
0100
ADD
ADDC
0101
SUB
SUBB
0110
AND
XOR
0111
IOR
MOV
1000
MOV
1001
MOV
1010
BSET
BCLR
BTG
BTST
BTSTS
BTST
BTSS
BTSC
BSET
BCLR
BTG
BTST
BTSTS
BSW
BTSS
BTSC
1011
ADD
ADDC
SUB
SUBB
AND
XOR
IOR
MOV
ADD
ADDC
SUB
SUBB
AND
XOR
IOR
MOV
MUL.US
MUL.UU
MUL.SS
MUL.SU
TBLRDH
TBLRDL
TBLWTH
TBLWTL
MUL
SUB
SUBB
MOV.D
MOV
MOVSAC(1)
SFTAC(1)
ADD(1)
LAC(1)
ADD(1)
NEG(1)
SUB(1)
SAC(1)
SAC.R(1)
FF1L
FF1R
1100
MAC(1)
MPY(1)
MPY.N(1)
MSC(1)
CLRAC(1)
MAC(1)
MPY(1)
MPY.N(1)
MSC(1)
SL
ASR
LSR
RLC
RLNC
RRC
RRNC
SL
ASR
LSR
RLC
RLNC
RRC
RRNC
DIV.S
DIV.U
DIVF(1)
SL
ASR
LSR
FBCL
1110
CP0
CP
CPB
CP0
CP
CPB
CPBGT(2)
CPBLT(2)
CPSGT
CPSLT
CPBEQ(2)
CPBNE(2)
CPSEQ
CPSNE
INC
INC2
DEC
DEC2
COM
NEG
CLR
SETM
INC
INC2
DEC
DEC2
COM
NEG
CLR
SETM
PUSH
POP
LNK
ULNK
SE
ZE
DISI
DAW
EXCH
SWAP
CLRWDT
MOVPAG(2)
PWRSAV
POP.S
PUSH.S
RESET
NOPR
DS70157E-page 443
1:
2:
ED(1)
EDAC(1)
MAC(1)
MPY(1)
This instruction is only available in dsPIC30F, dsPIC33F, and dsPIC33E family devices.
This instruction is only available in PIC24E and dsPIC33E family devices.
Section 6. Reference
1101
1111
Note
(1)
SUBR
0010
0011
1000
Reference
Table 6-1:
Table 6-2:
The instruction cycle counts listed here are for PIC24F, PIC24H, dsPIC30F and dsPIC33F devices. Some instructions require
additional cycles in PIC24E and dsPIC33E devices. Refer to Section 3.3 and Section 5.4 for details.
Description
DC
OV
Page
Number
ADD
f {,WREG}
Destination = f + WREG
5-100
ADD
#lit10,Wn
Wn = lit10 + Wn
5-101
ADD
Wb,#lit5,Wd
Wd = Wb + lit5
5-102
ADD
Wb,Ws,Wd
Wd = Wb + Ws
5-104
ADD
Acc(2)
Add accumulators
5-106
ADD
Ws,#Slit4,Acc
5-107
ADDC
f {,WREG}
5-109
ADDC
#lit10,Wn
Wn = lit10 + Wn + (C)
5-110
ADDC
Wb,#lit5,Wd
Wd = Wb + lit5 + (C)
5-111
ADDC
Wb,Ws,Wd
Wd = Wb + Ws + (C)
5-113
AND
f {,WREG}
5-115
AND
#lit10,Wn
Wn = lit10 .AND. Wn
5-116
AND
Wb,#lit5,Wd
Wd = Wb .AND. lit5
5-117
AND
Wb,Ws,Wd
Wd = Wb .AND. Ws
5-118
ASR
f {,WREG}
5-120
ASR
Ws,Wd
5-122
ASR
Wb,#lit4,Wnd
5-124
ASR
Wb,Wns,Wnd
5-125
BCLR
f,#bit4
Bit clear f
5-127
Legend:
Note 1:
2:
3:
4:
5:
6:
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157E-page 444
6.2
Description
DC
OV
Page
Number
Ws,#bit4
Bit clear Ws
5-128
BRA
Expr
Branch unconditionally
5-130
BRA
Wn
Computed branch
5-132
BRA
C,Expr
Branch if Carry
1 (2)
5-134
BRA
GE,Expr
1 (2)
5-136
BRA
GEU,Expr
Branch if Carry
1 (2)
5-138
BRA
GT,Expr
1 (2)
5-139
BRA
GTU,Expr
1 (2)
5-140
BRA
LE,Expr
1 (2)
5-141
BRA
LEU,Expr
1 (2)
5-142
BRA
LT,Expr
1 (2)
5-143
BRA
LTU,Expr
1 (2)
5-144
BRA
N,Expr
Branch if Negative
1 (2)
5-145
BRA
NC,Expr
1 (2)
5-146
BRA
NN,Expr
1 (2)
5-147
BRA
NOV,Expr
1 (2)
5-148
BRA
NZ,Expr
1 (2)
5-149
BRA
OA,Expr(2)
1 (2)
5-150
BRA
OB,Expr(2)
1 (2)
5-151
BRA
OV,Expr
Branch if Overflow
1 (2)
5-152
BRA
SA,Expr(2)
1 (2)
5-153
BRA
SB,Expr(2)
1 (2)
5-154
BRA
Z,Expr
Branch if Zero
1 (2)
5-155
BSET
f,#bit4
Bit set f
5-156
BSET
Ws,#bit4
Bit set Ws
5-157
BSW.C
Ws,Wb
5-159
BSW.Z
Ws,Wb
5-159
BTG
f,#bit4
Bit toggle f
5-161
BTG
Ws,#bit4
Bit toggle Ws
5-162
Legend:
Note 1:
2:
3:
4:
5:
6:
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
Section 6. Reference
DS70157E-page 445
BCLR
Reference
Table 6-2:
Description
DC
OV
Page
Number
BTSC
f,#bit4
1
(2 or 3)
5-164
BTSC
Ws,#bit4
1
(2 or 3)
5-166
BTSS
f,#bit4
1
(2 or 3)
5-168
BTSS
Ws,#bit4
1
(2 or 3)
5-169
BTST
f,#bit4
Bit test f
5-171
BTST.C
Ws,#bit4
Bit test Ws to C
5-172
BTST.Z
Ws,#bit4
Bit test Ws to Z
5-172
BTST.C
Ws,Wb
5-174
BTST.Z
Ws,Wb
5-174
BTSTS
f,#bit4
5-176
BTSTS.C Ws,#bit4
5-177
BTSTS.Z Ws,#bit4
5-177
CALL
Expr
Call subroutine
5-179
CALL
Wn
5-183
CALL.L
Wn(3)
5-187
CLR
f = 0x0000
5-188
CLR
WREG
WREG = 0x0000
5-188
CLR
Wd
Wd = 0
5-189
CLR
Acc,Wx,Wxd,Wy,Wyd,AWB(2)
Clear accumulator
5-190
5-192
CLRWDT
COM
f {,WREG}
Destination = f
5-193
COM
Ws,Wd
Wd = Ws
5-194
CP
Compare (f WREG)
5-196
CP
Wb,#lit5
5-197
CP
Wb,#lit8
5-198
Legend:
Note 1:
2:
3:
4:
5:
6:
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157E-page 446
Table 6-2:
Description
DC
OV
Page
Number
CP
Wb,Ws
5-199
CP0
Compare (f 0x0000)
5-200
CP0
Ws
5-201
CPB
5-202
CPB
Wb,#lit5
5-203
CPB
Wb,#lit8
5-205
CPB
Wb,Ws
5-207
5-209
Wb, Wn,
1
(5)
CPBGT
1
(5)
5-210
CPBLT
1
(5)
5-211
CPBNE
1
(5)
5-212
CPSEQ
Wb, Wn
1
(2 or 3)
5-213
CPSGT
Wb, Wn
1
(2 or 3)
5-217
CPSLT
Wb, Wn
1
(2 or 3)
5-218
CPSNE
Wb, Wn
1
(2 or 3)
5-220
DAW.B
Wn
Wn = decimal adjust Wn
5-222
DEC
f {,WREG}
Destination = f 1
5-223
DEC
Ws,Wd
Wd = Ws 1
5-224
DEC2
f {,WREG}
Destination = f 2
5-226
DEC2
Ws,Wd
Wd = Ws 2
5-227
DISI
#lit14
5-228
DIV.S
Wm, Wn
18
5-229
DIV.SD
Wm, Wn
18
5-229
Legend:
Note 1:
2:
3:
4:
5:
6:
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
Section 6. Reference
DS70157E-page 447
CPBEQ
Expr(3)
Reference
Table 6-2:
Description
DC
OV
Page
Number
DIV.U
Wm, Wn
18
5-231
DIV.UD
Wm, Wn
18
5-231
DIVF
Wm, Wn(2)
18
5-233
DO
#lit14,
Expr(6)
5-235
DO
#lit15, Expr(4)
5-237
DO
Wn, Expr(2)
5-239
ED
Wm*Wm,Acc,Wx,Wy,Wxd(2)
5-243
EDAC
Wm*Wm,Acc,Wx,Wy,Wxd(2)
Euclidean distance
5-245
EXCH
Wns,Wnd
5-247
FBCL
Ws,Wnd
5-248
FF1L
Ws,Wnd
5-250
FF1R
Ws,Wnd
5-252
GOTO
Expr
Go to address
5-254
GOTO
Wn
Go to address indirectly
5-255
GOTO.L
Wn(3)
5-257
INC
f {,WREG}
Destination = f + 1
5-258
INC
Ws,Wd
Wd = Ws + 1
5-259
INC2
f {,WREG}
Destination = f + 2
5-260
INC2
Ws,Wd
Wd = Ws + 2
5-261
IOR
f {,WREG}
5-262
IOR
#lit10,Wn
Wn = lit10 .IOR. Wn
5-263
IOR
Wb,#lit5,Wd
Wd = Wb .IOR. lit5
5-264
IOR
Wb,Ws,Wd
Wd = Wb .IOR. Ws
5-266
LAC
Ws,#Slit4, Acc
Load accumulator
5-268
LNK
#lit14
5-270
LSR
f {,WREG}
5-272
LSR
Ws,Wd
5-274
Legend:
Note 1:
2:
3:
4:
5:
6:
(2)
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157E-page 448
Table 6-2:
Description
DC
OV
Page
Number
5-276
LSR
Wb,#lit4,Wnd
LSR
Wb,Wns,Wnd
5-277
MAC
5-278
MAC
(2)
Wm*Wm,Acc,Wx,Wxd,Wy,Wyd
5-280
MOV
f {,WREG}
Move f to destination
5-282
MOV
WREG,f
Move WREG to f
5-283
MOV
f,Wnd
Move f to Wnd
5-284
MOV
Wns,f
Move Wns to f
5-285
MOV.B
#lit8,Wnd
5-286
MOV
#lit16,Wnd
5-287
MOV
[Ws+Slit10],Wnd
5-288
MOV
Wns,[Wd+Slit10]
5-289
MOV
Ws,Wd
Move Ws to Wd
5-290
MOV.D
Wns,Wnd
5-292
MOV.D
Wns,Wnd
5-292
MOVPAG
#lit10,DSRPAG(3)
5-294
MOVPAG
#lit9,DSWPAG(3)
5-294
MOVPAG
#lit8,TBLPAG(3)
5-294
(2)
MOVSAC
Acc,Wx,Wxd,Wy,Wyd,AWB
5-296
MPY
Wm*Wn,Acc,Wx,Wxd,Wy,Wyd(2)
Multiply Wn by Wm to accumulator
5-298
MPY
Wm*Wm,Acc,Wx,Wxd,Wy,Wyd(2)
Square to accumulator
5-300
DS70157E-page 449
MPY.N
Wm*Wn,Acc,Wx,Wxd,Wy,Wyd
5-302
MSC
5-304
MUL
W3:W2 = f * WREG
5-306
MUL.SS
Wb,Ws,Wnd
5-307
MUL.SS
Wb,Ws,Acc(4)
5-309
MUL.SU
Wb,#lit5,Wnd
5-310
MUL.SU
Wb,Ws,Wnd
5-312
Legend:
Note 1:
2:
3:
4:
5:
6:
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
Section 6. Reference
(2)
Reference
Table 6-2:
MUL.SU
Wb,Ws,Acc(4)
(4)
Description
DC
OV
Page
Number
5-314
5-315
MUL.SU
Wb,#lit5,Acc
MUL.US
Wb,Ws,Wnd
5-316
MUL.US
Wb,Ws,Acc(4)
5-318
MUL.UU
Wb,#lit5,Wnd
5-319
MUL.UU
Wb,Ws,Wnd
5-320
5-322
(4)
MUL.UU
Wb,Ws,Acc
MUL.UU
Wb,#lit5,Acc(4)
5-323
MULW.SS Wb,Ws,Wnd(3)
5-324
MULW.SU Wb,Ws,Wnd(3)
5-326
MULW.SU Wb,#lit5,Wnd(3)
5-328
MULW.US Wb,Ws,Wnd(3)
5-329
MULW.UU Wb,Ws,Wnd
5-331
MULW.UU Wb,#lit5,Wnd(3)
5-332
NEG
f {,WREG}
Destination = f + 1
5-333
NEG
Ws,Wd
Wd = Ws + 1
5-334
(3)
Negate accumulator
5-335
NOP
No operation
5-336
NOPR
No operation
5-337
POP TOS to f
5-338
POP
Wd
POP TOS to Wd
5-339
POP.D
Wnd
5-340
NEG
POP
(2)
Acc
5-341
PUSH f to TOS
5-342
PUSH
Ws
PUSH Ws to TOS
5-343
PUSH.D
Wns
5-345
5-346
5-347
POP.S
PUSH
2010 Microchip Technology Inc.
PUSH.S
PWRSAV
Legend:
Note 1:
2:
3:
4:
5:
6:
#lit1
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157E-page 450
Table 6-2:
Description
DC
OV
Page
Number
RCALL
Expr
Relative call
5-348
RCALL
Wn
Computed call
5-352
REPEAT
(5)
#lit14
5-356
REPEAT
#lit15(3)
5-358
REPEAT
Wn
5-360
RESET
5-364
RETFIE
3 (2)
5-366
RETLW
#lit10,Wn
3 (2)
5-368
3 (2)
5-372
f {,WREG}
5-374
RLC
Ws,Wd
5-376
RLNC
f {,WREG}
5-378
RLNC
Ws,Wd
5-379
RRC
f {,WREG}
5-381
RRC
Ws,Wd
5-382
RRNC
f {,WREG}
5-384
RRNC
Ws,Wd
5-385
SAC
Acc,#Slit4,Wd(2)
Store accumulator
5-387
SAC.R
Acc,#Slit4,Wd(2)
5-389
SE
Ws,Wd
Wd = sign-extended Ws
5-391
SETM
f = 0xFFFF
5-392
SETM
WREG
WREG = 0xFFFF
5-392
SETM
Ws
Ws = 0xFFFF
5-393
SFTAC
Acc,#Slit6(2)
5-394
SFTAC
Acc,Wb(2)
5-395
SL
f {,WREG}
5-396
SL
Ws,Wd
5-397
RLC
DS70157E-page 451
Legend:
Note 1:
2:
3:
4:
5:
6:
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
Section 6. Reference
RETURN
Reference
Table 6-2:
Description
DC
OV
Page
Number
5-399
SL
Wb,#lit4,Wnd
SL
Wb,Wns,Wnd
5-400
SUB
f {,WREG}
Destination = f WREG
5-401
SUB
#lit10,Wn
Wn = Wn lit10
5-402
SUB
Wb,#lit5,Wd
Wd = Wb lit5
5-403
SUB
Wb,Ws,Wd
Wd = Wb Ws
5-404
SUB
Acc(2)
Subtract accumulators
5-406
SUBB
f {,WREG}
5-407
SUBB
#lit10,Wn
Wn = Wn lit10 (C)
5-408
SUBB
Wb,#lit5,Wd
Wd = Wb lit5 (C)
5-409
SUBB
Wb,Ws,Wd
Wd = Wb Ws (C)
5-411
SUBBR
f {,WREG}
5-413
SUBBR
Wb,#lit5,Wd
Wd = lit5 Wb (C)
5-414
SUBBR
Wb,Ws,Wd
Wd = Ws Wb (C)
5-416
SUBR
f {,WREG}
Destination = WREG f
5-418
SUBR
Wb,#lit5,Wd
Wd = lit5 Wb
5-419
SUBR
Wb,Ws,Wd
Wd = Ws Wb
5-420
SWAP
Wn
5-422
TBLRDH
Ws,Wd
5-423
TBLRDL
Ws,Wd
5-425
TBLWTH
Ws,Wd
5-427
TBLWTL
Ws,Wd
5-429
5-431
5-433
ULNK
2010 Microchip Technology Inc.
XOR
Legend:
Note 1:
2:
3:
4:
5:
6:
f {,WREG}
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157E-page 452
Table 6-2:
Table 6-2:
Description
DC
OV
Page
Number
XOR
#lit10,Wn
Wn = lit10 .XOR. Wn
5-434
XOR
Wb,#lit5,Wd
Wd = Wb .XOR. lit5
5-435
XOR
Wb,Ws,Wd
Wd = Wb .XOR. Ws
5-437
ZE
Ws,Wnd
Wnd = zero-extended Ws
5-439
Legend:
Note 1:
2:
3:
4:
5:
6:
set or cleared; may be cleared, but never set; may be set, but never cleared; 1 always set; 0 always cleared; unchanged
SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
This instruction/operand is only available in PIC24E and dsPIC33E devices.
This instruction/operand is only available in dsPIC33E devices.
This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
Section 6. Reference
DS70157E-page 453
Reference
REVISION HISTORY
Revision A
This is the initial release of this document.
Revision B
This revision incorporates all known errata at the time of this document update.
DS70157E-page 454
Section 6. Reference
NOTES:
Reference
DS70157E-page 455
B
Byte Operations .................................................................. 64
C
Code Examples
Z Status bit Operation for 32-bit Addition .................. 77
Base MAC Syntax ....................................................... 86
File Register Addressing ............................................. 53
File Register Addressing and WREG.......................... 53
Frame Pointer Usage .................................................. 73
Illegal Word Move Operations..................................... 68
Immediate Addressing ................................................ 59
Indirect Addressing with Effective Address Update .... 55
Indirect Addressing with Register Offset ..................... 56
Legal Word Move Operations ..................................... 67
MAC Accumulator WB Syntax .................................... 88
MAC Prefetch Syntax.................................................. 87
Move with Literal Offset Instructions ........................... 56
MSC Instruction with Two Prefetches and Accumulator
Write Back........................................................... 88
Normalizing with FBCL ............................................... 92
Register Direct Addressing ......................................... 54
Sample Byte Math Operations .................................... 65
Sample Byte Move Operations ................................... 64
Scaling with FBCL....................................................... 91
Stack Pointer Usage ................................................... 71
Unsigned f and WREG Multiply (Legacy MULWF Instruction) ..................................................................... 80
Using 10-bit Literals for Byte Operands ...................... 69
Using the Default Working Register WREG................ 79
Conditional Branch Instructions .......................................... 76
Core Control Register ......................................................... 22
D
Data Addressing Mode Tree ............................................... 59
Data Addressing Modes...................................................... 52
DCOUNT Register .............................................................. 19
Default Working Register (WREG)................................ 17, 79
Development Support ........................................................... 6
DOEND Register................................................................. 20
DOSTART Register............................................................. 19
DSP Accumulator Instructions ............................................ 89
DSP Data Formats .............................................................. 81
DSP MAC Indirect Addressing Modes ................................ 57
DSP MAC Instructions ........................................................ 85
dsPIC30F/33F Overview ..................................................... 10
F
File Register Addressing ..................................................... 52
I
Immediate Addressing ........................................................ 58
Operands in the Instruction Set .................................. 58
DS70157E-page 456
Index
DS70157E-page 457
Index
DS70157E-page 458
(text).............................................................................. 8
[text] .............................................................................. 8
{ } .................................................................................. 8
{label:}........................................................................... 8
#text .............................................................................. 8
<n:m>............................................................................ 8
Acc................................................................................ 8
AWB.............................................................................. 8
bit4 ................................................................................ 8
Expr .............................................................................. 8
f..................................................................................... 8
lit1 ................................................................................. 8
lit10 ............................................................................... 8
lit14 ............................................................................... 8
lit16 ............................................................................... 8
lit23 ............................................................................... 8
lit4 ................................................................................. 8
lit5 ................................................................................. 8
lit8 ................................................................................. 8
Slit10............................................................................. 8
Slit16............................................................................. 8
Slit4............................................................................... 8
Slit5............................................................................... 8
TOS .............................................................................. 8
Wb ................................................................................ 8
Wd ................................................................................ 8
Wm, Wn ........................................................................ 8
Wm*Wm........................................................................ 8
Wm*Wn......................................................................... 8
Wn ................................................................................ 8
Wnd .............................................................................. 8
Wns............................................................................... 8
WREG........................................................................... 8
Ws................................................................................. 8
Wx................................................................................. 8
Wxd............................................................................... 8
Wy................................................................................. 8
Wyd............................................................................... 8
Instruction Stalls ................................................................. 62
DO/REPEAT Loops .................................................... 63
Exceptions .................................................................. 63
Instructions that Change Program Flow ..................... 63
PSV............................................................................. 63
RAW Dependency Detection ...................................... 62
Instruction Symbols ............................................................ 94
Integer 16x16-bit Signed-Unsigned Short Literal Multiply. 328
Integer 16x16-bit Unsigned Short Literal Multiply with 16-bit Result ............................................................................ 332
Integer and Fractional Data ................................................ 81
Representation ........................................................... 82
Interrupt Priority Level......................................................... 21
Introduction ........................................................................... 6
M
MAC
Operations .................................................................. 86
Prefetch Register Updates.......................................... 85
Prefetches................................................................... 85
Syntax......................................................................... 86
Write Back .................................................................. 86
MAC Accumulator Write Back Selection............................. 97
MAC or MPY Source Operands (Different Working Register)97
MAC or MPY Source Operands (Same Working Register) 97
Manual Objective .................................................................. 6
Modulo and Bit-Reversed Addressing Modes .................... 57
MOPAG Destination Selection............................................ 97
Multi-Cycle Instructions....................................................... 39
Index
Multi-Word Instructions ....................................................... 39
O
Offset Addressing Modes for Wd Destination Register (with Register Offset) ................................................................. 95
Offset Addressing Modes for Ws Source Register (with Register
Offset) ......................................................................... 95
Y
Y Data Space Prefetch Destination .................................... 97
Y Data Space Prefetch Operation ...................................... 96
Z
Z Status Bit ......................................................................... 77
Index
R
RCOUNT Register .............................................................. 19
Register Direct Addressing ................................................. 53
Register Indirect Addressing ............................................... 54
Modes ......................................................................... 54
Register Indirect Addressing and the Instruction Set .......... 57
Registers
CORCON (Core Control) ...................................... 31, 34
CORCON (Core Control) Register........................ 30, 32
SR (CPU Status)................................................... 25, 28
SR (Status) Register ................................................... 26
S
Scaling Data with the FBCL Instruction .............................. 90
Scaling Examples ....................................................... 90
Shadow Registers ............................................................... 23
Automatic Usage......................................................... 23
Software Stack Frame Pointer ...................................... 18, 72
Example ...................................................................... 73
Overflow...................................................................... 74
Underflow.................................................................... 74
Software Stack Pointer ................................................. 18, 70
Example ...................................................................... 71
Stack Pointer Limit Register (SPLIM) ................................. 18
Status Register ................................................................... 20
DSP ALU Status Bits .................................................. 21
Loop Status Bits.......................................................... 20
MCU ALU Status Bits.................................................. 20
Style and Symbol Conventions ............................................. 7
Document Conventions................................................. 7
T
TBLPAG Register ............................................................... 18
U
Using 10-bit Literal Operands ............................................. 69
10-bit Literal Coding.................................................... 69
W
Word Move Operations ....................................................... 66
Data Alignment in Memory.......................................... 66
Working Register Array ....................................................... 17
DS70157E-page 459
ASIA/PACIFIC
ASIA/PACIFIC
EUROPE
Corporate Office
2355 West Chandler Blvd.
Chandler, AZ 85224-6199
Tel: 480-792-7200
Fax: 480-792-7277
Technical Support:
http://support.microchip.com
Web Address:
www.microchip.com
India - Bangalore
Tel: 91-80-3090-4444
Fax: 91-80-3090-4123
India - New Delhi
Tel: 91-11-4160-8631
Fax: 91-11-4160-8632
Austria - Wels
Tel: 43-7242-2244-39
Fax: 43-7242-2244-393
Denmark - Copenhagen
Tel: 45-4450-2828
Fax: 45-4485-2829
India - Pune
Tel: 91-20-2566-1512
Fax: 91-20-2566-1513
France - Paris
Tel: 33-1-69-53-63-20
Fax: 33-1-69-30-90-79
Japan - Yokohama
Tel: 81-45-471- 6166
Fax: 81-45-471-6122
Germany - Munich
Tel: 49-89-627-144-0
Fax: 49-89-627-144-44
Atlanta
Duluth, GA
Tel: 678-957-9614
Fax: 678-957-1455
Boston
Westborough, MA
Tel: 774-760-0087
Fax: 774-760-0088
Chicago
Itasca, IL
Tel: 630-285-0071
Fax: 630-285-0075
Cleveland
Independence, OH
Tel: 216-447-0464
Fax: 216-447-0643
Dallas
Addison, TX
Tel: 972-818-7423
Fax: 972-818-2924
Detroit
Farmington Hills, MI
Tel: 248-538-2250
Fax: 248-538-2260
Kokomo
Kokomo, IN
Tel: 765-864-8360
Fax: 765-864-8387
Los Angeles
Mission Viejo, CA
Tel: 949-462-9523
Fax: 949-462-9608
Santa Clara
Santa Clara, CA
Tel: 408-961-6444
Fax: 408-961-6445
Toronto
Mississauga, Ontario,
Canada
Tel: 905-673-0699
Fax: 905-673-6509
Australia - Sydney
Tel: 61-2-9868-6733
Fax: 61-2-9868-6755
China - Beijing
Tel: 86-10-8528-2100
Fax: 86-10-8528-2104
China - Chengdu
Tel: 86-28-8665-5511
Fax: 86-28-8665-7889
Korea - Daegu
Tel: 82-53-744-4301
Fax: 82-53-744-4302
China - Chongqing
Tel: 86-23-8980-9588
Fax: 86-23-8980-9500
Korea - Seoul
Tel: 82-2-554-7200
Fax: 82-2-558-5932 or
82-2-558-5934
China - Nanjing
Tel: 86-25-8473-2460
Fax: 86-25-8473-2470
Malaysia - Penang
Tel: 60-4-227-8870
Fax: 60-4-227-4068
China - Qingdao
Tel: 86-532-8502-7355
Fax: 86-532-8502-7205
Philippines - Manila
Tel: 63-2-634-9065
Fax: 63-2-634-9069
China - Shanghai
Tel: 86-21-5407-5533
Fax: 86-21-5407-5066
Singapore
Tel: 65-6334-8870
Fax: 65-6334-8850
China - Shenyang
Tel: 86-24-2334-2829
Fax: 86-24-2334-2393
China - Shenzhen
Tel: 86-755-8203-2660
Fax: 86-755-8203-1760
Taiwan - Kaohsiung
Tel: 886-7-536-4818
Fax: 886-7-536-4803
China - Wuhan
Tel: 86-27-5980-5300
Fax: 86-27-5980-5118
Taiwan - Taipei
Tel: 886-2-2500-6610
Fax: 886-2-2508-0102
China - Xian
Tel: 86-29-8833-7252
Fax: 86-29-8833-7256
Thailand - Bangkok
Tel: 66-2-694-1351
Fax: 66-2-694-1350
Italy - Milan
Tel: 39-0331-742611
Fax: 39-0331-466781
Netherlands - Drunen
Tel: 31-416-690399
Fax: 31-416-690340
Spain - Madrid
Tel: 34-91-708-08-90
Fax: 34-91-708-08-91
UK - Wokingham
Tel: 44-118-921-5869
Fax: 44-118-921-5820
China - Xiamen
Tel: 86-592-2388138
Fax: 86-592-2388130
China - Zhuhai
Tel: 86-756-3210040
Fax: 86-756-3210049
01/05/10
DS70157E-page 460