16-Bit MCU and DSC Programmer's Reference Manual
16-Bit MCU and DSC Programmer's Reference Manual
• 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 Microchip’s 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 Microchip’s 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.
ISBN: 978-1-61341-357-9
Introduction
Section 1. Introduction
HIGHLIGHTS
This section of the manual contains the following major topics:
1.1 INTRODUCTION
Microchip Technology focuses on products for the embedded control market. Microchip is a
leading supplier of the following devices and products:
• 8-bit General Purpose Microcontrollers (PIC® MCUs)
• 16-bit Digital Signal Controllers (dsPIC® DSCs)
• 16-bit and 32-bit Microcontrollers (MCUs)
• Speciality and Standard Nonvolatile Memory Devices
• Security Devices (KEELOQ® Security ICs)
• Application-specific Standard Products
Information about these devices and products, with corresponding technical documentation, is
available on the Microchip web site (www.microchip.com).
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.
HIGHLIGHTS
This section of the manual contains the following major topics:
2
2.1 16-bit MCU and DSC Core Architecture Overview ......................................................... 10
Programmer’s
2.2 Programmer’s Model....................................................................................................... 14
2.3 Working Register Array................................................................................................... 18
Model
2.4 Default Working Register (WREG) ................................................................................. 18
2.5 Software Stack Frame Pointer ........................................................................................ 18
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.
Programmer’s
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.
Model
2.1.2 PIC24E and dsPIC33E Features
In addition to the information provided in Section 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.
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.
Programmer’s
Model
15 0 PUSH.S
Shadow
W0/WREG Register
DIV and MUL W1
Result Registers Legend
W2
W3
W4
W5
W6
W7
Working Registers
W8
W9
W10
W11
W12
W13
W14/Frame Pointer
W15/Stack Pointer
22 0
0 Program Counter
7 0
TABPAG Data Table Page Address
TBLPAG
7 0
PSVPAG Program Space Visibility Page Address
PSVPAG
13 0
REPEAT Loop Counter
RCOUNT
15 0
CPU Core Control Register
CORCON
15 0 PUSH.S and
POP.S Shadow
W0/WREG Registers
DIV and MUL W1
Legend
Result Registers
W2
W3
W4
W5
W6
W7
2
Working Registers
W8
Programmer’s
W9
W10
Model
W11
W12
W13
W14/Frame Pointer
W15/Stack Pointer
22 0
Program Counter
0
7 0
TABPAG Data Table Page Address
TBLPAG
9 0
PSVPAG Data Space Read Page Address
DSRPAG
8 0
PSVPAG Data Space Write Page Address
DSWPAG
15 0
REPEAT Loop Counter
RCOUNT
15 0
CPU Core Control Register
CORCON
15 0 PUSH.S
Shadow
W0/WREG Register
DIV and MUL W1 DO Shadow
Result Registers Register
W2
W3
Legend
W4
MAC Operand W5
Registers
W6
W7
Working Registers
W8
MAC Address W9
Registers W10
W11
W12
W13
W14/Frame Pointer
W15/Stack Pointer
39 31 15 0
ACCA DSP
ACCB Accumulators
22 0
Program Counter
0
7 0
TABPAG Data Table Page Address
TBLPAG
7 0
PSVPAG Program Space Visibility Page Address
PSVPAG
13 0
REPEAT Loop Counter
RCOUNT
13 0
DO Loop Counter
DCOUNT
24 0
0 DOSTART 0 DO Loop Start Address
24 0
0 DOEND 0 DO Loop End Address
15 0
CORCON CPU Core Control Register
15 0 PUSH.S and
POP.S Shadow
W0/WREG Registers
DIV and MUL W1 Nested DO
Result Registers Stack
W2
W3
Legend
W4
MAC Operand W5
Registers
W6
W7
Working Registers
2
W8
Programmer’s
MAC Address W9
Registers W10
Model
W11
W12
W13
W14/Frame Pointer
W15/Stack Pointer
39 31 15 0
ACCA DSP
ACCB Accumulators
22 0
Program Counter
0
7 0
TABPAG Data Table Page Address
TBLPAG
9 0
PSVPAG X Data Space Read Page Address
DSRPAG
8 0
PSVPAG X Data Space Write Page Address
DSWPAG
15 0
REPEAT Loop Counter
RCOUNT
15 0
DO Loop Counter
DCOUNT
24 0
0 DOSTART 0 DO Loop Start Address
24 0
0 DOEND 0 DO Loop End Address
15 0
CORCON CPU Core Control Register
All registers in the programmer’s model are memory mapped and can be manipulated directly by
the instruction set. A description of each register is provided in Table 2-1.
Note: Unless otherwise specified, the Programmer’s Model Register Descriptions in
Table 2-1 apply to all MCU and DSC device families.
Programmer’s
2.8 ACCUMULATOR A AND ACCUMULATOR B (dsPIC30F, dsPIC33F AND
Model
dsPIC33E DEVICES)
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)
In dsPIC33E devices, Accumulator A and Accumulator B can also be used as destination
registers in MCU MUL.xx instructions. This helps reduce the execution time of
extended-precision arithmetic operations.
Refer to Section 4.12 “Accumulator Usage (dsPIC30F, dsPIC33F and dsPIC33E Devices)”
for details on using ACCA and ACCB.
Programmer’s
2.16 STATUS REGISTER
Model
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
Programmer’s
accumulator. The OA and OB bits are writable in dsPIC33E devices.
The SA and SB bits are used to indicate when an operation has generated an overflow out of the
Model
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.
DCOUNT(1) Yes —
DOSTART(1) Yes —
DOEND(1) Yes —
STATUS Register – DC, N, OV, Z and C bits — Yes
W0-W3 — Yes
Note 1: The DO shadow registers are only available in dsPIC30F and dsPIC33F devices.
For dsPIC30F and dsPIC33F devices, since the DCOUNT, DOSTART and DOEND registers are
shadowed, the 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: All shadow registers are one register deep and not directly accessible. Additional
shadowing may be performed in software using the software stack.
Programmer’s
Model
DL<2:0> DOSTART DOEND DCOUNT
000 Empty
100
Note 1: 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: If DL<2:0> = 0, no DO loops are active (DA = 0).
Register 2-1: SR: CPU STATUS Register (PIC24H, PIC24F and PIC24E Devices)
U-0 U-0 U-0 U-0 U-0 U-0 U-0 R/W-0
— — — — — — — DC
bit 15 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
IPL<3> = 1.
2: The IPL<2:0> Status bits are read only when the NSTDIS bit (INTCON1<15>) = 1. Refer to the family
reference manual of the specific device family to see the associated interrupt register.
Register 2-2: SR: CPU STATUS Register (dsPIC30F and dsPIC33F Devices)
R-0 R-0 R/C-0 R/C-0 R-0 R/C-0 R-0 R/W-0
OA OB SA(1,2) SB(1,2)
OAB SAB (1,2,3)
DA (4)
DC
bit 15 bit 8
Legend: 2
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
Programmer’s
Model
bit 15 OA: Accumulator A Overflow bit
1 = Accumulator A overflowed
0 = Accumulator A has not overflowed
bit 14 OB: Accumulator B Overflow bit
1 = Accumulator B overflowed
0 = Accumulator B has not overflowed
bit 13 SA: Accumulator A Saturation bit(1, 2)
1 = Accumulator A is saturated or has been saturated since this bit was last cleared
0 = Accumulator A is not saturated
bit 12 SB: Accumulator B Saturation bit(1, 2)
1 = Accumulator B is saturated or has been saturated at since this bit was last cleared
0 = Accumulator B is not saturated
bit 11 OAB: OA || OB Combined Accumulator Overflow bit
1 = Accumulator A or B has overflowed
0 = Neither Accumulator A nor B has overflowed
bit 10 SAB: SA || SB Combined Accumulator bit(1, 2, 3)
1 = Accumulator A or B is saturated or has been saturated since this bit was last cleared
0 = Neither Accumulator A nor B is saturated
bit 9 DA: DO Loop Active bit(4)
1 = DO loop in progress
0 = DO loop not in progress
bit 8 DC: MCU ALU Half Carry bit
1 = A carry-out from the MSb of the lower nibble occurred
0 = No carry-out from the MSb of the lower nibble occurred
bit 7-5 IPL<2:0>: Interrupt Priority Level bits(5)
111 = CPU Interrupt Priority Level is 7 (15). User interrupts disabled
110 = CPU Interrupt Priority Level is 6 (14)
101 = CPU Interrupt Priority Level is 5 (13)
100 = CPU Interrupt Priority Level is 4 (12)
011 = CPU Interrupt Priority Level is 3 (11)
010 = CPU Interrupt Priority Level is 2 (10)
001 = CPU Interrupt Priority Level is 1 (9)
000 = CPU Interrupt Priority Level is 0 (8)
Register 2-2: SR: CPU STATUS Register (dsPIC30F and dsPIC33F Devices) (Continued)
bit 4 RA: REPEAT Loop Active bit
1 = REPEAT loop in progress
0 = REPEAT loop not in progress
bit 3 N: MCU ALU Negative bit
1 = The result of the operation was negative
0 = The result of the operation was not negative
bit 2 OV: MCU ALU Overflow bit
1 = Overflow occurred
0 = No overflow occurred
bit 1 Z: MCU ALU Zero bit
1 = The result of the operation was zero
0 = The result of the operation was not zero
bit 0 C: MCU ALU Carry/Borrow bit
1 = A carry-out from the MSb occurred
0 = No carry-out from the MSb occurred
Programmer’s
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Model
bit 15 OA: Accumulator A Overflow Status bit
1 = Accumulator A has overflowed
0 = Accumulator A has not overflowed
bit 14 OB: Accumulator B Overflow Status bit
1 = Accumulator B has overflowed
0 = Accumulator B has not overflowed
bit 13 SA: Accumulator A Saturation Status bit
1 = Accumulator A is saturated or has been saturated since this bit was last cleared
0 = Accumulator A is not saturated
bit 12 SB: Accumulator B Saturation Status bit
1 = Accumulator B is saturated or has been saturated since this bit was last cleared
0 = Accumulator B is not saturated
bit 11 OAB: OA || OB Combined Accumulator Overflow Status bit
1 = Accumulator A or B has overflowed
0 = Neither Accumulator A nor B has overflowed
bit 10 SAB: SA || SB Combined Accumulator Status bit
1 = Accumulator A or B is saturated or has been saturated since this bit was last cleared
0 = Neither Accumulator A nor B is saturated
bit 9 DA: DO Loop Active bit
1 = DO loop in progress
0 = DO loop not in progress
bit 8 DC: MCU ALU Half Carry/Borrow bit
1 = A carry-out from the 4th low order bit (for byte-sized data) or 8th low order bit (for word-sized data
of the result occurred
0 = No carry-out from the 4th low order bit (for byte-sized data) or 8th low order bit (for word-sized data
of the result occurred
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 bit (INTCON1<15>) = 1. 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.
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 bit (INTCON1<15>) = 1. 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.
Register 2-4: CORCON: Core Control Register (PIC24F and PIC24H Devices)
U-0 U-0 U-0 U-0 U-0 U-0 U-0 U-0
— — — — — — — —
bit 15 bit 8
Programmer’s
U = Unimplemented bit, read as ‘0’
Model
bit 15-4 Unimplemented: Read as ‘0’
bit 3 IPL3: Interrupt Priority Level 3 Status bit(1,2)
1 = CPU Interrupt Priority Level is 8 or greater (trap exception activated)
0 = CPU Interrupt Priority Level is 7 or less (no trap exception activated)
bit 2 PSV: Program Space Visibility in Data Space Enable bit
1 = Program space visible in data space
0 = Program space not visible in data space
bit 1-0 Unimplemented: Read as ‘0’
Legend:
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Register 2-6: CORCON: Core Control Register (dsPIC30F and dsPIC33F Devices)
U-0 U-0 U-0 R/W-0 R(0)/W-0 R-0 R-0 R-0
(1) (2,3)
— — — US EDT DL<2:0>
bit 15 bit 8
Programmer’s
U = Unimplemented bit, read as ‘0’
Model
bit 15-13 Unimplemented: Read as ‘0’
bit 12 US: Unsigned or Signed Multiplier Mode Select bit
1 = Unsigned mode enabled for DSP multiply operations
0 = Signed mode enabled for DSP multiply operations
bit 11 EDT: Early DO Loop Termination Control bit(1)
1 = Terminate executing DO loop at end of current iteration
0 = No effect
bit 10-8 DL<2:0>: DO Loop Nesting Level Status bits(2, 3)
111 = DO looping is nested at 7 levels
110 = DO looping is nested at 6 levels
110 = DO looping is nested at 5 levels
110 = DO looping is nested at 4 levels
011 = DO looping is nested at 3 levels
010 = DO looping is nested at 2 levels
001 = DO looping is active, but not nested (just 1 level)
000 = DO looping is not active
bit 7 SATA: ACCA Saturation Enable bit
1 = Accumulator A saturation enabled
0 = Accumulator A saturation disabled
bit 6 SATB: ACCB Saturation Enable bit
1 = Accumulator B saturation enabled
0 = Accumulator B saturation disabled
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 ACCSAT: Accumulator Saturation Mode Select bit
1 = 9.31 saturation (Super Saturation)
0 = 1.31 saturation (Normal Saturation)
bit 3 IPL3: Interrupt Priority Level 3 Status bit(4, 5)
1 = CPU Interrupt Priority Level is 8 or greater (trap exception activated)
0 = CPU Interrupt Priority Level is 7 or less (no trap exception activated)
bit 2 PSV: Program Space Visibility in Data Space Enable bit
1 = Program space visible in data space
0 = Program space not visible in data space
Register 2-6: CORCON: Core Control Register (dsPIC30F and dsPIC33F Devices) (Continued)
bit 1 RND: Rounding Mode Select bit
1 = Biased (conventional) rounding enabled
0 = Unbiased (convergent) rounding enabled
bit 0 IF: Integer or Fractional Multiplier Mode Select bit
1 = Integer mode enabled for DSP multiply operations
0 = Fractional mode enabled for DSP multiply operations
Legend: 2
R = Readable bit W = Writable bit U = Unimplemented bit, read as ‘0’
Programmer’s
-n = Value at POR ‘1’ = Bit is set ‘0’ = Bit is cleared x = Bit is unknown
Model
bit 15 VAR: Variable Exception Processing Latency Control bit
1 = Variable (bounded deterministic) exception processing latency
0 = Fixed (fully deterministic) exception processing latency
bit 14 Unimplemented: Read as '0’
bit 13-12 US<1:0>: DSP Multiply Unsigned/Signed Control bits
11 = Reserved
10 = DSP engine multiplies are mixed-sign
01 = DSP engine multiplies are unsigned
00 = DSP engine multiplies are signed
bit 11 EDT: Early DO Loop Termination Control bit(1)
1 = Terminate executing DO loop at end of current loop iteration
0 = No effect
bit 10-8 DL<2:0>: DO Loop Nesting Level Status bits
111 = 7 DO loops active
•
•
•
001 = 1 DO loop active
000 = 0 DO loops active
bit 7 SATA: ACCA Saturation Enable bit
1 = Accumulator A saturation enabled
0 = Accumulator A saturation disabled
bit 6 SATB: ACCB Saturation Enable bit
1 = Accumulator B saturation enabled
0 = Accumulator B saturation disabled
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 ACCSAT: Accumulator Saturation Mode Select bit
1 = 9.31 saturation (super saturation)
0 = 1.31 saturation (normal saturation)
bit 3 IPL3: CPU Interrupt Priority Level Status bit 3(2)
1 = CPU interrupt priority level is greater than 7
0 = CPU interrupt priority level is 7 or less
HIGHLIGHTS
This section of the manual contains the following major topics:
Instruction Set
Overview
3.1 INTRODUCTION
The 16-bit MCU and DSC instruction set provides a broad suite of instructions that support
traditional microcontroller applications, and a class of instructions that support 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.
Instruction Set
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
Overview
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. However, all write operations on both CPU and non-CPU Special
Function Registers, and all read and read-modify-write operations on CPU Special
Function Registers require 1 instruction cycle.
Instruction Set
INC f {,WREG}(1) Destination = f + 1 1 1(5) 254
1(5)
Overview
INC Ws,Wd Wd = Ws + 1 1 255
INC2 f {,WREG}(1) Destination = f + 2 1 1(5) 257
INC2 Ws,Wd Wd = Ws + 2 1 1(5) 258
MUL f W3:W2 = f * WREG 1 1(5) 303
MUL.SS Wb,Ws,Wnd {Wnd + 1,Wnd} = signed(Wb) * signed(Ws) 1 1(5) 305
MUL.SS Wb,Ws,Acc(4) Accumulator = signed(Wb) * signed(Ws) 1 1(5) 307
MUL.SU Wb,#lit5,Wnd {Wnd + 1, Wnd} = signed(Wb) * unsigned(lit5) 1 1 308
MUL.SU Wb,Ws,Wnd {Wnd + 1,Wnd} = signed(Wb) * unsigned(Ws) 1 1(5) 310
MUL.SU Wb,Ws,Acc(4) Accumulator = signed(Wb) * unsigned(Ws) 1 1(5) 312
MUL.SU Wb,#lit5,Acc(4) Accumulator = signed(Wb) * unsigned(lit5) 1 1 314
MUL.US Wb,Ws,Wnd {Wnd + 1,Wnd} = unsigned(Wb) * signed(Ws) 1 1(5) 315
MUL.US Wb,Ws,Acc(4) Accumulator = unsigned(Wb) * signed(Ws) 1 1(5) 317
MUL.UU Wb,#lit5,Wnd {Wnd + 1, Wnd} = unsigned(Wb) * unsigned(lit5) 1 1 319
MUL.UU Wb,Ws,Wnd {Wnd + 1,Wnd} = unsigned(Wb) * unsigned(Ws) 1 1(5) 320
MUL.UU Wb,Ws,Acc(4) Accumulator = unsigned(Wb) * unsigned(Ws) 1 1 (5)
322
MUL.UU Wb,#lit5,Acc(4) Accumulator = unsigned(Wb) * unsigned(lit5) 1 1 323
MULW.SS Wb,Ws,Wnd(3) Wnd = signed(Wb) * signed(Ws) 1 1(5) 324
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.
2: The divide instructions must be preceded with a “REPEAT #17” instruction, such that they are executed
18 consecutive times.
3: These instructions are only available in dsPIC33E and PIC24E devices.
4: These instructions are only available in dsPIC33E devices.
5: In dsPIC33E and PIC24E devices, read and read-modify-write operations on non-CPU Special Function
Registers require an additional cycle when compared to dsPIC30F, dsPIC33F, PIC24F and PIC24H
devices.
Instruction Set
XOR #lit10,Wn Wn = lit10 .XOR. Wn 1 1 438
Overview
XOR Wb,#lit5,Wd Wd = Wb .XOR. lit5 1 1 439
XOR Wb,Ws,Wd Wd = Wb .XOR. Ws 1 1(2) 440
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.
2: In dsPIC33E and PIC24E devices, read and read-modify-write operations on non-CPU Special Function
Registers require an additional cycle when compared to dsPIC30F, dsPIC33F, PIC24F and PIC24H
devices.
Instruction Set
Note 1: In dsPIC33E and PIC24E devices, read and read-modify-write operations on non-CPU Special Function
Overview
Registers require an additional cycle when compared to dsPIC30F, dsPIC33F, PIC24F and PIC24H
devices.
Instruction Set
BRA OV,Expr
BRA SA,Expr Branch if Accumulator A Saturate 1 1 (2)(1,8) 149
Overview
BRA SB,Expr Branch if Accumulator B Saturate 1 1 (2)(1,8) 150
BRA Z,Expr Branch if Zero 1 1 (2)(1,8) 151
CALL Expr Call subroutine 2 2(8) 177
CALL Wn Call indirect subroutine 1 2(8) 180
CALL.L Wn(4) Call indirect subroutine (long address) 1 4 183
DO #lit14,Expr(6) Do code through PC + Expr, (lit14 + 1) times 2 2 230
DO #lit15,Expr(7) Do code through PC + Expr, (lit15 + 1) times 2 2 233
DO Wn,Expr(3) Do code through PC + Expr, (Wn + 1) times 2 2 235
GOTO Expr Go to address 2 2(8) 250
GOTO Wn Go to address indirectly 1 2(8) 251
GOTO.L Wn(4) Go to indirect (long address) 1 4 253
RCALL Expr Relative call 1 2(8) 347
RCALL Wn Computed call 1 2(8) 351
REPEAT #lit14(5) Repeat next instruction (lit14 + 1) times 1 1 355
Note 1: Conditional branch instructions execute in 1 cycle if the branch is not taken, or 2 cycles if the branch is
taken.
2: RETURN instructions execute in 3 cycles, but if an exception is pending, they execute in 2 cycles.
3: This instruction is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
4: This instruction is only available in dsPIC33E and PIC24E devices.
5: This instruction is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
6: This instruction is only available in dsPIC30F and dsPIC33F devices.
7: This instruction is only available in dsPIC33E devices.
8: In dsPIC33E and PIC24E devices, these instructions require 2 additional cycles (4 cycles overall) when
the branch is taken.
9: In dsPIC33E and PIC24E devices, these instructions require 3 additional cycles.
Instruction Set
NOP No operation 1 1 336
Overview
NOPR No operation 1 1 336
PWRSAV #lit1 Enter Power-saving mode lit1 1 1 346
RESET Software device Reset 1 1 363
HIGHLIGHTS
This section of the manual contains the following major topics:
Instruction Set
Details
Note: Instructions which support file register addressing use ‘f’ as an operand in the
instruction summary tables of Section 3. “Instruction Set Overview”.
4
4.1.2 Register Direct Addressing
Register direct addressing is used to access the contents of the 16 working registers (W0:W15).
Instruction Set
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
Details
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.
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”.
Table 4-2 shows that four Addressing modes modify the EA used in the instruction, and this
allows the following updates to be made to the working register: post-increment, post-decrement,
pre-increment and pre-decrement. Since all EAs must be given as byte addresses, support is
provided for Word mode instructions by scaling the EA update by 2. Namely, in Word mode,
pre/post-decrements subtract 2 from the EA stored in the working register, and
pre/post-increments add 2 to the EA. This feature ensures that after an EA modification is made,
the EA will point to the next adjacent word in memory. Example 4-4 shows how indirect
addressing may be used to update the EA.
Table 4-2 also shows that the Register Offset mode addresses data which is offset from a base
EA stored in a working register. This mode uses the contents of a second working register to form
the EA by adding the two specified working registers. This mode does not scale for Word mode
instructions, but offers the complete offset range of 64 Kbytes. Note that neither of the working
registers used to form the EA are modified. Example 4-5 shows how register offset indirect
addressing may be used to access data memory.
Note: The MOV with offset instructions (see pages 285 and 286) 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.
Instruction Set
W1 = 0x0800
W5 = 0x2200
Details
W8 = 0x2400
Data Memory 0x21FE = 0x7783
Data Memory 0x2402 = 0xAACC
After Instruction:
W1 = 0x0800
W5 = 0x21FE
W8 = 0x2402
Data Memory 0x21FE = 0x7783
Data Memory 0x2402 = 0x7F83
Note: Instructions which use register indirect addressing use the operand symbols Wd
and Ws in the summary tables of Section 3. “Instruction Set Overview”.
Instruction Set
dsPIC33E Devices)”, only W8 and W9 may be used to access X Memory, and only
W10 and W11 may be used to access Y Memory.
Details
4.1.3.3 MODULO AND BIT-REVERSED ADDRESSING MODES (dsPIC30F,
dsPIC33F, AND dsPIC33E DEVICES)
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.
Before Instruction:
W0 = 0x12A9
After Instruction:
W0 = 0x12B9
Figure 4-1: Data Addressing Mode Tree (PIC24F, PIC24H, and PIC24E)
Immediate
Instruction Set
Post-Decrement
Details
Literal Offset
Register Offset
The Data Addressing modes of the dsPIC30F, dsPIC33F, and dsPIC33E are summarized in
Figure 4-2.
Figure 4-2: Data Addressing Mode Tree (dsPIC30F, dsPIC33F, and dsPIC33E)
Immediate
Post-Decrement
Register Offset
Direct
Register Offset
Instruction Set
(Unconditional Indirect Long Jump)
RCALL Expr(1) PC = PC + 2 * Slit16 PC + 2 is PUSHed on the stack(2)
Details
(Relative Call)
RCALL Wn PC = PC + 2 * Wn PC + 2 is PUSHed on the stack(2)
(Computed Relative Call)
Exception Handling PC = address of the exception handler PC + 2 is PUSHed on the stack(3)
(read from vector table)
PC = Target REPEAT instruction PC not modified (if REPEAT active) None
(REPEAT Looping)
PC = DOEND address(4) PC = DOSTART (if DO active) None
(DO Looping)
Note 1: 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.
2: After CALL or RCALL is executed, RETURN or RETLW will POP the Top-of-Stack (TOS) back into the PC.
3: After an exception is processed, RETFIE will POP the Top-of-Stack (TOS) back into the PC.
4: This condition/instruction is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
5: This condition instruction is only available in dsPIC33E and PIC24E devices.
Note: Refer to the specific device family reference manual for more detailed information
about RAW instruction stalls.
Instruction Set
Details
Note: Instructions that operate in Byte mode must use the “.b” or “.B” instruction
extension to specify a byte instruction. For example, the following two instructions
are valid forms of a byte clear operation:
• CLR.b W0
• CLR.B W0
ADD.B W0, W1, [W2++] ; byte add W0 and W1, store to [W2]
; and post-inc W2
Before Instruction:
W0 = 0x1234
W1 = 0x5678
W2 = 0x1000
Data Memory 0x1000 = 0x5555
After Instruction:
W0 = 0x1234
W1 = 0x5678
W2 = 0x1001
Data Memory 0x1000 = 0x55AC
Instruction Set
Details
0x1001 b0 0x1000
0x1003 b1 0x1002
0x1005 b3 b2 0x1004
0x1007 b5 b4 0x1006
0x1009 b7 b6 0x1008
0x100B b8 0x100A
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 W0
• CLR.w W0
• CLR.W W0
Instruction Set
Details
Note: Using a literal value greater than 127 in Byte mode is functionally identical to using
the equivalent negative two’s 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
0x0000
15 0
Stack Grows Towards
Higher Address
0xFFFE
Note: For exceptions, the upper nine bits of the second PUSHed word contains
the SRL and IPL<3>.
0x0000
0xFFFE
W0 = 0x5A5A
W1 = 0x3636
W15 = 0x0800
0x0000
0x0800
4
5A5A
0x0802 <TOS> W15 (SP)
Instruction Set
Details
0xFFFE
W0 = 0x5A5A
W1 = 0x3636
W15 = 0x0802
0x0000
0x0800 5A5A
0x0802 3636
0x0804 <TOS> W15 (SP)
0xFFFE
W0 = 0x5A5A
W1 = 0x3636
W15 = 0x0804
0x0000
0x0800 5A5A
0x0802 <TOS> W15 (SP)
0x0804
0xFFFE
W0 = 0x5A5A
W1 = 0x3636
W3 = 0x3636
W15 = 0x0802
Note: The contents of 0x802, the new TOS, remain unchanged (0x3636).
COMPUTE:
LNK #4 ; Stack FP, allocate 4 bytes for local variables 4
...
ULNK ; Free allocated memory, restore original FP
Instruction Set
RETURN ; Return to TASKA
Details
Figure 4-9: Stack at the Beginning of Example 4-14
0x0000
0x0800
Frame W14 (FP)
of
TASKA
<TOS> W15 (SP)
0xFFFE
0x0000
0x0800
Frame W14 (FP)
of
TASKA
Parameter 1
Parameter 2
Parameter 3
PC<15:0>(1)
0:PC<22:16>
<TOS> W15 (SP)
0xFFFE
0x0000
0x0800
Frame
of
TASKA
Parameter 1
Parameter 2
Parameter 3
PC<15:0>(1)
0:PC<22:16>
FP of TASKA
Temp Word 1 W14 (FP)
Temp Word 2
<TOS> W15 (SP)
0xFFFE
Instruction Set
Details
Before 32-bit Addition (zero result for the most significant word):
W0 = 0x2342
W1 = 0xFFF0
W2 = 0x39AA
W3 = 0x0010
W4 = 0x0000
W5 = 0x0000
SR = 0x0000
After 32-bit Addition:
W0 = 0x2342
W1 = 0xFFF0
W2 = 0x39AA
W3
W4
=
=
0x0010
0x5CEC
4
W5 = 0x0000
Instruction Set
SR = 0x0201 (DC,C=1)
Before 32-bit Addition (zero result for the least significant word and most significant word):
Details
W0 = 0xB76E
W1 = 0xFB7B
W2 = 0x4892
W3 = 0x0484
W4 = 0x0000
W5 = 0x0000
SR = 0x0000
After 32-bit Addition:
W0 = 0xB76E
W1 = 0xFB7B
W2 = 0x4892
W3 = 0x0485
W4 = 0x0000
W5 = 0x0000
SR = 0x0103 (DC,Z,C=1)
Instruction Set
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
Details
working registers (starting with an even register), or an accumulator.
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 303).
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.
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.
Instruction Set
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
Details
has no other effect on the computation (e.g., 0.5 x 0.5 = 0.25).
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1.15 Fractional:
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Integer:
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0
1.15 Fractional:
1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0
B)
4
C)
Instruction Set
Details
D)
Note 1: 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).
2: The OA, OB, SA or SB bit cannot be set by writing overflowed values to the memory
mapped accumulators using MOV instructions, as these status bits are only affected
by DSP operations.
Instruction Set
(see Table 4-11).
Details
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.
If a prefetch is used in the instruction, the assembler is capable of discriminating between the X
or Y data prefetch based on the register used for the effective address. [W8] or [W9] specifies
the X prefetch and [W10] or [W11] specifies the Y prefetch. Brackets around the working register
are required in the syntax, and they designate that indirect addressing is used to perform the
prefetch. When address modification is used, it must be specified using a minus-equals or
plus-equals “C”-like syntax (i.e., “[W8] – = 2” or “[W8] + = 6”). When Register Offset Addressing
is used for the prefetch, W12 is placed inside the brackets ([W9 + W12] for X prefetches and [W11
+ W12] for Y prefetches). Each prefetch operation must also specify a prefetch destination
register (W4-W7). In the instruction syntax, the destination register appears before the prefetch
register. Legal forms of prefetch are shown in Example 4-20.
ACCA=ACCA+W5*W6
X([W8]+=2)→W5
ACCB=ACCB+W5*W5
Y([W11+W12])→W5
ACCB=ACCB+W6*W7
X([W9])→W6
Y([W10]+=4)→W7
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.
0 →ACCA
ACCB →W13
ACCA=ACCA+W4*W5
ACCB →[W13]+=2
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: MSC Instruction with Two Prefetches and Accumulator Write Back
ACCB=ACCB-W6*W7
X([W8]+=2)→W6
4
Y([W10]-=6)→W7
Instruction Set
ACCA→[W13]+=2
Details
4.16 SCALING DATA WITH THE FBCL INSTRUCTION (dsPIC30F, dsPIC33F AND
dsPIC33E DEVICES)
To minimize quantization errors that are associated with data processing using DSP instructions,
it is important to utilize the complete numerical result of the operations. This may require scaling
data up to avoid underflow (i.e., when processing data from a 12-bit ADC), or scaling data down
to avoid overflow (i.e., when sending data to a 10-bit DAC). The scaling, which must be
performed to minimize quantization error, depends on the dynamic range of the input data which
is operated on, and the required dynamic range of the output data. At times, these conditions
may be known beforehand and fixed scaling may be employed. In other cases, scaling conditions
may not be fixed or known, and then dynamic scaling must be used to process data.
The FBCL instruction (Find First Bit Change Left) can efficiently be used to perform dynamic
scaling, because it determines the exponent of a value. A fixed point or integer value’s exponent
represents the amount which the value may be shifted before overflowing. This information is
valuable, because it may be used to bring the data value to “full scale”, meaning that its numeric
representation utilizes all the bits of the register it is stored in.
The FBCL instruction determines the exponent of a word by detecting the first bit change starting
from the value’s sign bit and working towards the LSB. Since the dsPIC DSC device’s barrel
shifter uses negative values to specify a left shift, the FBCL instruction returns the negated
exponent of a value. If the value is being scaled up, this allows the ensuing shift to be performed
immediately with the value returned by FBCL. Additionally, since the FBCL instruction only
operates on signed quantities, FBCL produces results in the range of -15:0. When the FBCL
instruction returns ‘0’, it indicates that the value is already at full scale. When the instruction
returns -15, it indicates that the value cannot be scaled (as is the case with 0x0 and 0xFFFF).
Table 4-13 shows word data with various dynamic ranges, their exponents, and the value after
scaling each data to maximize the dynamic range. Example 4-23 shows how the FBCL
instruction may be used for block processing.
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.
Instruction Set
SFTAC A, W2 ; shift ACCA by W2 bits
SCALE:
Details
SAC A, [W4++] ; store scaled input (overwrite original)
Instruction Set
Besides DSP instructions, MCU multiplication (MUL) instructions can also utilize Accumulator A
Details
or Accumulator B as a result destination, which enables faster extended-precision arithmetic
even when not using DSP multiplication instructions such as MPY or MAC.
HIGHLIGHTS
This section of the manual contains the following major topics:
5
Descriptions
Instruction
Table 5-4: Offset Addressing Modes for Ws Source Register (with Register Offset)
ggg Addressing Mode Source Operand
000 Register Direct Ws
001 Indirect [Ws]
010 Indirect with Post-Decrement [Ws--]
011 Indirect with Post-Increment [Ws++]
100 Indirect with Pre-Decrement [--Ws]
101 Indirect with Pre-Increment [++Ws]
11x Indirect with Register Offset [Ws+Wb]
Table 5-6: X Data Space Prefetch Operation (dsPIC30F, dsPIC33F and dsPIC33E)
iiii Operation
0000 Wxd = [W8]
0001 Wxd = [W8], W8 = W8 + 2
0010 Wxd = [W8], W8 = W8 + 4
0011 Wxd = [W8], W8 = W8 + 6
0100 No Prefetch for X Data Space
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 Wxd = [W9 + W12]
1101 Wxd = [W9], W9 = W9 – 6
1110 Wxd = [W9], W9 = W9 – 4
1111 Wxd = [W9], W9 = W9 – 2
Table 5-7: X Data Space Prefetch Destination (dsPIC30F, dsPIC33F and dsPIC33E)
xx Wxd
00 W4
01 W5
10 W6
11 W7
Table 5-8: Y Data Space Prefetch Operation (dsPIC30F, dsPIC33F and dsPIC33E)
jjjj Operation
0000 Wyd = [W10]
0001 Wyd = [W10], W10 = W10 + 2
0010 Wyd = [W10], W10 = W10 + 4
0011 Wyd = [W10], W10 = W10 + 6
0100 No Prefetch for Y Data Space
0101 Wyd = [W10], W10 = W10 – 6
0110 Wyd = [W10], W10 = W10 – 4
0111 Wyd = [W10], W10 = W10 – 2
1000 Wyd = [W11]
1001 Wyd = [W11], W11 = W11 + 2
1010 Wyd = [W11], W11 = W11 + 4
1011 Wyd = [W11], W11 = W11 + 6
1100 Wyd = [W11 + W12]
1101 Wyd = [W11], W11 = W11 – 6
1110 Wyd = [W11], W11 = W11 – 4
1111 Wyd = [W11], W11 = W11 – 2
Table 5-9: Y Data Space Prefetch Destination (dsPIC30F, dsPIC33F and dsPIC33E)
yy Wyd
00 W4
01 W5
10 W6
11 W7
Table 5-10: MAC or MPY Source Operands (Same Working Register) (dsPIC30F,
dsPIC33F and dsPIC33E)
mm Multiplicands
00 W4 * W4
01 W5 * W5
10 W6 * W6
11 W7 * W7
Table 5-11: MAC or MPY Source Operands (Different Working Register) (dsPIC30F,
dsPIC33F and dsPIC33E)
mmm Multiplicands
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: MAC Accumulator Write Back Selection (dsPIC30F, dsPIC33F and
dsPIC33E)
aa Write Back Selection
00 W13 = Other Accumulator (Direct Addressing)
01 [W13] + = 2 = Other Accumulator (Indirect Addressing with Post-Increment)
10 No Write Back
11 Invalid
0 Accumulator A
1 Accumulator B
Syntax: 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 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: The Operation field summarizes the operation performed by the instruction.
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: The Description field describes in detail the operation performed by the
instruction. A key for the encoding bits is also provided.
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.
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG CC80 WREG CC80
RAM100 FFC0 RAM100 FF40
SR 0000 SR 0005 (OV, C = 1)
Before After
Instruction Instruction 5
WREG CC80 WREG CC40
RAM200 FFC0 RAM200 FFC0
Descriptions
Instruction
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
W7 12C0 W7 12BF
SR 0000 SR 0009 (N, C = 1)
Before After
Instruction Instruction
W1 12C0 W1 13BF
SR 0000 SR 0000
Before After
Instruction Instruction
W0 2290 W0 2290
W7 12C0 W7 12AF
SR 0000 SR 0008 (N = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
W3 6006 W3 6006
W4 1000 W4 0FFE
Data 0FFE DDEE Data 0FFE 600C
Data 1000 DDEE Data 1000 DDEE
SR 0000 SR 0000
ADD Add Wb to Ws
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W5 AB00 W5 AB00
W6 0030 W6 0030
W7 FFFF W7 FF30
SR 0000 SR 0000
Before After
Instruction Instruction
W5 AB00 W5 AB00
W6 0030 W6 0030
W7 FFFF W7 AB30
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
ACCA 00 E111 2222 ACCA 00 E111 2222
ACCB 00 7654 3210 ACCB 01 5765 5432
SR 0000 SR 4800 (OB, OAB = 1)
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W0 8000 W0 8000
ACCA 00 7000 0000 ACCA 00 5000 0000
SR 0000 SR 0000
Before After
Instruction Instruction
W5 2000 W5 2002
ACCA 00 0067 2345 ACCA 00 5067 2345
Data 2000 5000 Data 2000 5000
SR 0000 SR 0000
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG CC60 WREG CC60
RAM100 8006 RAM100 8067
SR 0001 (C=1) SR 0000
Example 2: ADDC RAM200, WREG ; Add RAM200 and C bit to the WREG
; (Word mode)
Before After
Instruction Instruction
WREG 5600 WREG 8A01
RAM200 3400 RAM200 3400
SR 0001 (C=1) SR 000C (N, OV = 1)
Before After
Instruction Instruction
W7 12C0 W7 12BF
SR 0000 (C = 0) SR 0009 (N,C = 1)
Before After
Instruction Instruction
W1 12C0 W1 13C0 5
SR 0001 (C = 1) SR 0000
Descriptions
Instruction
Example 1: ADDC.B W0, #0x1F, [W7] ; Add W0, 31 and C bit (Byte mode)
; Store the result in [W7]
Before After
Instruction Instruction
W0 CC80 W0 CC80
W7 12C0 W7 12C0
Data 12C0 B000 Data 12C0 B09F
SR 0000 (C = 0) SR 0008 (N = 1)
Example 2: ADDC W3, #0x6, [--W4] ; Add W3, 6 and C bit (Word mode)
; Store the result in [--W4]
Before After
Instruction Instruction
W3 6006 W3 6006
W4 1000 W4 0FFE
Data 0FFE DDEE Data 0FFE 600D
Data 1000 DDEE Data 1000 DDEE
SR 0001 (C = 1) SR 0000
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: ADDC.B W0,[W1++],[W2++] ; Add W0, [W1] and C bit (Byte mode)
; Store the result in [W2]
; Post-increment 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
Example 2: ADDC W3,[W2++],[W1++] ; Add W3, [W2] and C bit (Word mode)
; Store the result in [W1]
; Post-increment W1, W2
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
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG CC80 WREG CC80
RAM100 FFC0 RAM100 FF80
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
WREG CC80 WREG 0080
RAM200 12C0 RAM200 12C0
SR 0000 SR 0000
Before After
Instruction Instruction
W7 12C0 W7 1280
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
W1 12D0 W1 0210
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 23A5 W0 23A5
W1 2211 W1 2212
Data 2210 9999 Data 2210 0199
SR 0000 SR 0000
Example 2: AND W0,#0x1F,W1 ; AND W0 and 0x1F (Word mode)
; Store to W1
Before After
Instruction Instruction
W0 6723 W0 6723
W1 7878 W1 0003
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Status Affected: N, Z, C
Encoding: 1101 0101 1BDf ffff ffff ffff
Description: 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: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
WREG 0600 WREG 0611
RAM400 0823 RAM400 0823
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
RAM200 8009 RAM200 C004
SR 0000 SR 0009 (N, C = 1)
Status Affected: N, Z, C
Encoding: 1101 0001 1Bqq qddd dppp ssss
Description: 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: 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.
Words:
Cycles:
1
5
1(1)
Descriptions
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
Instruction
Before After
Instruction Instruction
W0 0600 W0 0601
W1 0801 W1 0802
Data 600 2366 Data 600 2366
Data 800 FFC0 Data 800 33C0
SR 0000 SR 0000
Before After
Instruction Instruction
W12 AB01 W12 AB01
W13 0322 W13 D580
SR 0000 SR 0009 (N, C = 1)
Before After
Instruction Instruction
W0 060F W0 060F
W1 1234 W1 0060
SR 0000 SR 0000
Before After
Instruction Instruction
W0 80FF W0 80FF
W1 0060 W1 FE03
SR 0000 SR 0008 (N = 1)
W0 70FF W0 70FF
W1 CC26 W1 0000
SR 0000 SR 0002 (Z = 1)
Before After
Instruction Instruction
W0 80FF W0 80FF
W5 0004 W5 0004
W6 2633 W6 F80F
SR 0000 SR 0000
Before After
Instruction Instruction
W0 6688 W0 6688
W5 000A W5 000A
W6 FF00 W6 0019
SR 0000 SR 0000
Example 3: ASR W11, W12, W13 ; ASR W11 by W12 and store to W13
Before After
Instruction Instruction
W11 8765 W11 8765
W12 88E4 W12 88E4
W13 A5A5 W13 F876
SR 0000 SR 0008 (N = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
Data 0800 66EF Data 0800 666F
SR 0000 SR 0000
Before After
Instruction Instruction 5
Data 0400 AA55 Data 0400 A855
SR 0000 SR 0000
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W2 F234 W2 F230
SR 0000 SR 0000
Before After
Instruction Instruction
W0 2300 W0 2302
Data 2300 5607 Data 2300 5606
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 200A
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 2000 PC 00 1366
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 210A
W7 0084 W7 0084
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 2000 PC 00 210A
W7 0084 W7 0084
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 2008
SR 0001 (C = 1) SR 0001 (C = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 6230 PC 00 6238
SR 0001 (C = 1) SR 0001 (C = 1)
Before After
Instruction Instruction
PC 00 623C PC 00 6234
SR 0001 (C = 1) SR 0001 (C = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 7608 PC 00 7600
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 7608 PC 00 760A
SR 0008 (N = 1) SR 0008 (N = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 0001 (C = 1) SR 0001 (C = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 0001 (C = 1) SR 0001 (C = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 0001 (C = 1) SR 0001 (C = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
SR 0001 (C = 1) SR 0001 (C = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 0001 (C = 1) SR 0001 (C = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
SR 0001 (C = 1) SR 0001 (C = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
SR 0001 (C = 1) SR 0001 (C = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 0008 (N = 1) SR 0008 (N = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
SR 0001 (C = 1) SR 0001 (C = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 0008 (N = 1) SR 0008 (N = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
SR 0002 (Z = 1) SR 0002 (Z = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 8800 (OA, OAB = 1) SR 8800 (OA, OAB = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
SR 8800 (OA, OAB = 1) SR 8800 (OA, OAB = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
SR 0002 (Z = 1) SR 0002 (Z = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 2400 (SA, SAB = 1) SR 2400 (SA, SAB = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 2000 PC 00 200C
SR 0002 (Z = 1) SR 0002 (Z = 1)
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
Data 0600 F234 Data 0600 FA34
SR 0000 SR 0000
Before After
Instruction Instruction
Data 0444 5604 Data 0444 D604
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
W3 0026 W3 00A6
SR 0000 SR 0000
Before After
Instruction Instruction
W4 6700 W4 6702
Data 6700 1734 Data 6700 1735
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After 5
Instruction Instruction
W2 F234 W2 7234
Descriptions
W3 111F W3 111F
Instruction
SR 0002 (Z = 1, C = 0) SR 0002 (Z = 1, C = 0)
Before After
Instruction Instruction
W2 E235 W2 E234
W3 0550 W3 0550
SR 0002 (Z = 1, C = 0) SR 0002 (Z = 1, C = 0)
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)
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)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
Data 1000 F234 Data 1000 E234
SR 0000 SR 0000
Before After 5
Instruction Instruction
Data 1660 5606 Data 1660 5706
Descriptions
Instruction
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W2 F234 W2 F235
SR 0000 SR 0000
Before After
Instruction Instruction
W0 2300 W0 2302
Data 2300 5606 Data 2300 5607
SR 0000 SR 0000
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
Data 1200 264F Data 1200 264F
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 2000 PC 00 2006
Data 0804 2647 Data 0804 2647
SR 0000 SR 0000
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
W0 264F W0 264F
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 2000 PC 00 2006
W6 264F W6 264F
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 3400 PC 00 3402
W6 1800 W6 1802
Data 1800 1000 Data 1800 1000
SR 0000 SR 0000
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
PC 00 7100 PC 00 7104
Data 1400 0280 Data 1400 0280
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 7100 PC 00 7102
Data 0890 00FE Data 0890 00FE
SR 0000 SR 0000
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
PC 00 2000 PC 00 2006
W0 264F W0 264F
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
W6 264F W6 264F
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 3400 PC 00 3406
W6 1800 W6 1802
Data 1800 1000 Data 1800 1000
SR 0000 SR 0000
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
Data 1200 F7FF Data 1200 F7FF
SR 0000 SR 0002 (Z = 1)
Before After
Instruction Instruction
Data 1302 F7FF Data 1302 F7FF
SR 0002 (Z = 1) SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 1200 W0 1202
Data 1200 FFF7 Data 1200 FFF7
SR 0001 (C = 1) SR 0000
Before After
Instruction Instruction
W0 F234 W0 F234
SR 0000 SR 0002 (Z = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
W2 F234 W2 F234
W3 2368 W3 2368
SR 0001 (C = 1) SR 0000
Before After
Instruction Instruction
W0 1200 W0 1202
W1 CCC0 W1 CCC0
Data 1200 6243 Data 1200 6243
SR 0002 (Z = 1) SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
Data 1200 F7FF Data 1200 FFFF
SR 0000 SR 0002 (Z = 1)
Before After
Instruction Instruction
RAM300 8050 RAM300 8050
SR 0002 (Z = 1) SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 1200 W0 1202
Data 1200 FFF7 Data 1200 FFFF
SR 0001 (C = 1) SR 0000
Before After
Instruction Instruction
W0 F234 W0 F2BC
SR 0000 SR 0002 (Z = 1)
Before After
Instruction Instruction
PC 02 6000 PC 02 6844
W15 A268 W15 A26C
Data A268 FFFF Data A268 6004
Data A26A FFFF Data A26A 0002
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 07 2000 PC 07 7A28
W15 9004 W15 9008
Data 9004 FFFF Data 9004 2004
Data 9006 FFFF Data 9006 0007
SR 0000 SR 0000
Before After
Instruction Instruction
PC 02 6000 PC 02 6844
W15 A268 W15 A26C
Data A268 FFFF Data A268 6004
Data A26A FFFF Data A26A 0002
SR 0000 SR 0000
Before After
Instruction Instruction
PC 07 2000 PC 07 7A28
W15 9004 W15 9008
Data 9004 FFFF Data 9004 2004
Data 9006 FFFF Data 9006 0007
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 1002 PC 00 1600
W0 1600 W0 1600
W15 6F00 W15 6F04
Data 6F00 FFFF Data 6F00 1004
Data 6F02 FFFF Data 6F02 0000
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 4200 PC 00 5500
W7 5500 W7 5500
W15 6F00 W15 6F04
Data 6F00 FFFF Data 6F00 4202
Data 6F02 FFFF Data 6F02 0000
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 1002 PC 00 1600
W0 1600 W0 1600
W15 6F00 W15 6F04
Data 6F00 FFFF Data 6F00 1004
Data 6F02 FFFF Data 6F02 0000
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 4200 PC 00 5500
W7 5500 W7 5500
W15 6F00 W15 6F04
Data 6F00 FFFF Data 6F00 4202
Data 6F02 FFFF Data 6F02 0000
SR 0000 SR 0000
Words: 1
Cycles: 4
Before After
Instruction Instruction
PC 02 6000 PC 02 6844
W4 6844 W4 6844
W5 0002 W5 0002
W15 A268 W15 A26C
Data A268 FFFF Data A268 6004
Data A26A FFFF Data A26A 0002
SR 0000 SR 0000 5
Descriptions
Instruction
Before After
Instruction Instruction
RAM200 8009 RAM200 8000
SR 0000 SR 0000
Before After
Instruction Instruction
WREG 0600 WREG 0000
SR 0000 SR 0000
CLR Clear Wd
Before After
Instruction Instruction
W2 3333 W2 3300
SR 0000 SR 0000
Before After
Instruction Instruction
W0 2300 W0 2302
Data 2300 5607 Data 2300 0000
SR 0000 SR 0000 5
Descriptions
Instruction
Before After
Instruction Instruction
W4 F001 W4 1221
W8 2000 W8 2002
W13 C623 W13 5420
ACCA 00 0067 2345 ACCA 00 0000 0000
ACCB 00 5420 3BDD ACCB 00 5420 3BDD
Data 2000 1221 Data 2000 1221
SR 0000 SR 0000
Before After
Instruction Instruction
W6 F001 W6 1221
W7 C783 W7 FF80
W8 2000 W8 2002
W10 3000 W10 3002
W13 4000 W13 4002
ACCA 00 0067 2345 ACCA 00 0067 2345
ACCB 00 5420 ABDD ACCB 00 0000 0000
Data 2000 1221 Data 2000 1221
Data 3000 FF80 Data 3000 FF80
Data 4000 FFC3 Data 4000 0067
SR 0000 SR 0000
5
Descriptions
Instruction
Operands: None
Operation: 0 →WDT count register
0 →WDT prescaler A count
0 →WDT prescaler B count
Status Affected: None
Encoding: 1111 1110 0110 0000 0000 0000
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: 1
Cycles: 1
Before After
Instruction Instruction
SR 0000 SR 0000
COM Complement f
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
RAM200 80FF RAM200 8000
SR 0000 SR 0002 (Z)
Before After
Instruction Instruction
WREG 1211 WREG F7DC
RAM400 0823 RAM400 0823 5
SR 0000 SR 0008 (N = 1)
Descriptions
Instruction
COM Complement Ws
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: COM.B [W0++], [W1++] ; COM [W0] and store to [W1] (Byte mode)
; Post-increment W0, W1
Before After
Instruction Instruction
W0 2301 W0 2302
W1 2400 W1 2401
Data 2300 5607 Data 2300 5607
Data 2400 ABCD Data 2400 ABA9
SR 0000 SR 0008 (N = 1)
Example 2: COM W0, [W1++] ; COM W0 and store to [W1] (Word mode)
; Post-increment W1
Before After
Instruction Instruction
W0 D004 W0 D004
W1 1000 W1 1002
Data 1000 ABA9 Data 1000 2FFB
SR 0000 SR 0000
Operands: f ∈ [0 ...8191]
Operation: (f) – (WREG)
Status Affected: DC, N, OV, Z, C
Encoding: 1110 0011 0B0f ffff ffff ffff
Description: 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: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG 8823 WREG 8823
RAM400 0823 RAM400 0823 5
SR 0000 SR 0003 (C = 1)
Example 2: CP 0x1200 ; Compare (0x1200) with WREG (Word mode)
Descriptions
Instruction
Before After
Instruction Instruction
WREG 2377 WREG 2377
Data 1200 2277 Data 1200 2277
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
W4 7711 W4 7711
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
W4 7713 W4 7713
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
W4 7711 W4 7711
SR 0000 SR 0009 (N, C = 1)
Before After
Instruction Instruction
W4 7713 W4 7713
SR 0000 SR 0001 (C = 1)
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W0 ABA9 W0 ABA9
W1 2000 W1 2001
Data 2000 D004 Data 2000 D004
SR 0000 SR 0009 (N, C = 1)
Before After
Instruction Instruction
W5 2334 W5 2334
W6 8001 W6 8001
SR 0000 SR 000C (N, OV = 1)
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
RAM100 44C3 RAM100 44C3
SR 0000 SR 0009 (N, C = 1)
Before After
Instruction Instruction
Data 1FFE 0001 Data 1FFE 0001
SR 0000 SR 0001 (C = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W4 1001 W4 1000
Data 1000 0034 Data 1000 0034
SR 0000 SR 0001 (C = 1)
W5 2400 W5 23FE
Data 23FE 9000 Data 23FE 9000
SR 0000 SR 0009 (N, C = 1)
Operands: f ∈ [0 ...8191]
Operation: (f) – (WREG) – (C)
Status Affected: DC, N, OV, Z, C
Encoding: 1110 0011 1B0f ffff ffff ffff
Description: 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.
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: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: CPB.B RAM400 ; Compare RAM400 with WREG using C (Byte mode)
Before After
Instruction Instruction
WREG 8823 WREG 8823
RAM400 0823 RAM400 0823
SR 0000 SR 0008 (N = 1)
Example 2: CPB 0x1200 ; 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)
Example 1: CPB.B W4, #0x12 ; Compare W4 with 0x12 using C (Byte mode)
Before After
Instruction Instruction
W4 7711 W4 7711
SR 0001 (C = 1) SR 0008 (N = 1)
Example 2: CPB.B W4, #0x12 ; Compare W4 with 0x12 using C (Byte mode)
Before After
Instruction Instruction
W4 7711 W4 7711
SR 0000 SR 0008 (N = 1)
Example 3: CPB W12, #0x1F ; Compare W12 with 0x1F using C (Word mode)
Before After
Instruction Instruction
W12 0020 W12 0020 5
SR 0002 (Z = 1) SR 0003 (Z, C = 1)
Descriptions
Instruction
Example 4: CPB W12, #0x1F ; Compare W12 with 0x1F using C (Word mode)
Before After
Instruction Instruction
W12 0020 W12 0020
SR 0003 (Z, C = 1) SR 0001 (C = 1)
Example 1: CPB.B W4, #0x12 ; Compare W4 with 0x12 using C (Byte mode)
Before After
Instruction Instruction
W4 7711 W4 7711
SR 0001 (C = 1) SR 0008 (N = 1)
Example 2: CPB.B W4, #0x12 ; Compare W4 with 0x12 using C (Byte mode)
Before After
Instruction Instruction
W4 7711 W4 7711
SR 0000 SR 0008 (N = 1)
Example 3: CPB W12, #0x1F ; Compare W12 with 0x1F using C (Word mode)
Before After
Instruction Instruction
W12 0020 W12 0020
SR 0002 (Z = 1) SR 0003 (Z, C = 1)
Example 4: CPB W12, #0x1F ; Compare W12 with 0x1F using C (Word mode)
Before After
Instruction Instruction
W12 0020 W12 0020
SR 0003 (Z, C = 1) SR 0001 (C = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: CPB.B W0, [W1++] ; Compare [W1] with W0 using C (Byte mode)
; Post-increment W1
Before After
Instruction Instruction
W0 ABA9 W0 ABA9
5
W1 1000 W1 1001
Data 1000 D0A9 Data 1000 D0A9
Descriptions
Instruction
SR 0002 (Z = 1) SR 0008 (N = 1)
Example 2: CPB.B W0, [W1++] ; Compare [W1] with W0 using C (Byte mode)
; Post-increment 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 ; Compare W5 with W4 using C (Word mode)
Before After
Instruction Instruction
W4 4000 W4 4000
W5 3000 W5 3000
SR 0001 (C = 1) SR 0001 (C = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2008
W0 1000 W0 1000
W1 1000 W1 1000
SR 0000 SR 0002 (z = 1)
5
Descriptions
Instruction
CPBGT Signed Compare Wb with Wn, Branch if Greater Than (Wb > Wn)
Example 1: 002000 HERE: CPBGT.B W0, W1, BYPASS ; If W0 > W1 (Byte mode),
002002 ADD W2, W3, W4 ; Perform branch to BYPASS
002004 . . .
002006 . . .
002008 BYPASS . . .
00200A . . .
Before After
Instruction Instruction
PC 00 2000 PC 00 2008
W0 30FF W0 00FF
W1 26FE W1 26FE
SR 0000 SR 0000 (N, C = 0)
CPBLT Signed Compare Wb with Wn, Branch if Less Than (Wb < Wn)
Example 1: 002000 HERE: CPBLT.B W8, W9, BYPASS; If W8 < W9 (Byte mode),
002002 ADD W2, W3, W4; Perform branch to BYPASS
002004 . . .
002006 . . .
002008 BYPASS: . . .
00200A . . .
Before After
Instruction Instruction
PC 00 2000 PC 00 2008
W8 00FF W8 00FF
W9 26FE W9 26FE
SR 0000 SR 0008 (N = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 200A
W2 00FF W2 00FF
W3 26FE W3 26FE
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
W0 1001 W0 1001
W1 1000 W1 1000
SR 0000 SR 0000
PC 01 8000 PC 01 8006
W4 3344 W4 3344
W8 3344 W8 3344
SR 0002 (Z = 1) SR 0002 (Z = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
W0 1001 W0 1001
W1 1000 W1 1000
SR 0000 SR 0000
Before After
Instruction Instruction
PC 01 8000 PC 01 8006
W4 3344 W4 3344
W8 3344 W8 3344
SR 0002 (Z = 1) SR 0002 (Z = 1)
5
Descriptions
Instruction
CPSGT Signed Compare Wb with Wn, Skip if Greater Than (Wb > Wn)
Before After
Instruction Instruction
PC 00 2000 PC 00 2006
W0 00FF W0 00FF
W1 26FE W1 26FE
SR 0009 (N, C = 1) SR 0009 (N, C = 1)
Before After
Instruction Instruction
PC 01 8000 PC 01 8002
W4 2600 W4 2600
W5 2600 W5 2600
SR 0004 (OV = 1) SR 0004 (OV = 1)
CPSGT Signed Compare Wb with Wn, Skip if Greater Than (Wb > Wn)
Before After
Instruction Instruction
PC 00 2000 PC 00 2006
W0 00FF W0 00FF
W1 26FE W1 26FE
SR 0009 (N, C = 1) SR 0009 (N, C = 1)
PC 01 8000 PC 01 8002
W4 2600 W4 2600
W5 2600 W5 2600
SR 0004 (OV = 1) SR 0004 (OV = 1)
CPSLT Signed Compare Wb with Wn, Skip if Less Than (Wb < Wn)
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
W8 00FF W8 00FF
W9 26FE W9 26FE
SR 0008 (N = 1) SR 0008 (N = 1)
Before After
Instruction Instruction
PC 01 8000 PC 01 8006
W3 2600 W3 2600
W6 3000 W6 3000
SR 0000 SR 0000
CPSLT Signed Compare Wb with Wn, Skip if Less Than (Wb < Wn)
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
W8 00FF W8 00FF
W9 26FE W9 26FE
SR 0008 (N = 1) SR 0008 (N = 1)
PC 01 8000 PC 01 8006
W3 2600 W3 2600
W6 3000 W6 3000
SR 0000 SR 0000
CPSNE Signed Compare Wb with Wn, Skip if Not Equal (Wb ≠ Wn)
Before After
Instruction Instruction
PC 00 2000 PC 00 2006
W2 00FF W2 00FF
W3 26FE W3 26FE
SR 0001 (C = 1) SR 0001 (C = 1)
Before After
Instruction Instruction
PC 01 8000 PC 01 8002
W0 3000 W0 3000
W8 3000 W8 3000
SR 0000 SR 0000
CPSNE Signed Compare Wb with Wn, Skip if Not Equal (Wb ≠ Wn)
Before After
Instruction Instruction
PC 00 2000 PC 00 2006
W2 00FF W2 00FF
W3 26FE W3 26FE
SR 0001 (C = 1) SR 0001 (C = 1)
PC 01 8000 PC 01 8002
W0 3000 W0 3000
W8 3000 W8 3000
SR 0000 SR 0000
If (Wn<7:4> > 9) or (C = 1)
(Wn<7:4>) + 6 →Wn<7:4>
Else
(Wn<7:4>) →Wn<7:4>
Status Affected: C
Encoding: 1111 1101 0100 0000 0000 ssss
Description: Adjust the Least Significant Byte in Wn to produce a binary coded decimal
(BCD) result. The Most Significant Byte of Wn is not changed, and the
Carry flag is used to indicate any decimal rollover. Register direct
addressing must be used for Wn.
The ‘s’ bits select the source/destination register.
Note 1: This instruction is used to correct the data format after two
packed BCD bytes have been added.
2: This instruction operates in Byte mode only and the .B
extension must be included with the opcode.
Words: 1
Cycles: 1
Before After
Instruction Instruction
W0 771A W0 7720
SR 0002 (DC = 1) SR 0002 (DC = 1)
Before After
Instruction Instruction
W3 77AA W3 7710
SR 0000 SR 0001 (C = 1)
DEC Decrement f
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
Data 200 80FF Data 200 80FE
SR 0000 SR 0009 (N, C = 1)
Before After
Instruction Instruction
WREG 1211 WREG 0822
RAM400
SR
0823
0000
RAM400
SR
0823
0000
5
Descriptions
Instruction
DEC Decrement Ws
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: DEC.B [W7++], [W8++] ; DEC [W7] and store to [W8] (Byte mode)
; Post-increment W7, W8
Before After
Instruction Instruction
W7 2301 W7 2302
W8 2400 W8 2401
Data 2300 5607 Data 2300 5607
Data 2400 ABCD Data 2400 AB55
SR 0000 SR 0000
Example 2: DEC W5, [W6++] ; Decrement W5 and store to [W6] (Word mode)
; Post-increment W6
Before After
Instruction Instruction
W5 D004 W5 D004
W6 2000 W6 2002
Data 2000 ABA9 Data 2000 D003
SR 0000 SR 0009 (N, C = 1)
5
Descriptions
Instruction
DEC2 Decrement f by 2
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
Data 200 80FF Data 200 80FD
SR 0000 SR 0009 (N, C = 1)
Before After
Instruction Instruction
WREG 1211 WREG 0821
RAM400 0823 RAM400 0823
SR 0000 SR 0000
DEC2 Decrement Ws by 2
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: DEC2.B [W7--], [W8--]; DEC [W7] by 2, store to [W8] (Byte mode)
; Post-decrement W7, W8
Before After
Instruction Instruction
W7 2301 W7 2300
W8 2400 W8 23FF
Data 2300 0107 Data 2300 0107
Data 2400 ABCD Data 2400 ABFF 5
SR 0000 SR 0008 (N = 1)
Descriptions
Instruction
Before After
Instruction Instruction
W5 D004 W5 D004
W6 1000 W6 1002
Data 1000 ABA9 Data 1000 D002
SR 0000 SR 0009 (N, C = 1)
Example 1: 002000 HERE: DISI #100 ; Disable interrupts for 101 cycles
002002 ; next 100 cycles protected by DISI
002004 . . .
Before After
Instruction Instruction
PC 00 2000 PC 00 2002
DISICNT 0000 DISICNT 0100
INTCON2 0000 INTCON2 4000 (DISI = 1)
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 5555 W0 013B
W1 1234 W1 0003
W3 3000 W3 3000
W4 0027 W4 0027
SR 0000 SR 0000
Before After
Instruction Instruction
W0 2500 W0 FA6B
W1 FF42 W1 EF00
W12 2200 W12 2200
SR 0000 SR 0008 (N = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 5555 W0 0040
W1 1234 W1 0000
W2 8000 W2 8000
W4 0200 W4 0200
SR 0000 SR 0002 (Z = 1)
Before After
Instruction Instruction
W0 5555 W0 01F2
W1 1234 W1 0100
W10 2500 W10 2500
W11 0042 W11 0042
W12 2200 W12 2200
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 8000 W0 2000
W1 1234 W1 0000
W8 1000 W8 1000
W9 4000 W9 4000
SR 0000 SR 0002 (Z = 1)
Before After
Instruction Instruction
W0 8000 W0 F000
W1 1234 W1 0000
W8 1000 W8 1000
W9 8000 W9 8000
SR 0000 SR 0002 (Z = 1)
Before After
Instruction Instruction
W0 8002 W0 7FFE
W1 8001 W1 8002
SR 0000 SR 0008 (N = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 2000 PC 00 2004 5
DCOUNT 0000 DCOUNT 0005
DOSTART FF FFFF DOSTART 00 2004
Descriptions
Before After
Instruction Instruction
PC 01 C000 PC 01 C004
DCOUNT 0000 DCOUNT 0160
DOSTART FF FFFF DOSTART 01 C004
DOEND FF FFFF DOEND 01 C014
CORCON 0000 CORCON 0100 (DL = 1)
SR 0008 (N = 1) SR 0208 (DA, N = 1)
Words: 2
Cycles: 2
Before After
Instruction Instruction
PC 00 2000 PC 00 2004
DCOUNT 0000 DCOUNT 0005
DOSTART FF FFFF DOSTART 00 2004
DOEND FF FFFF DOEND 00 200A
CORCON 0000 CORCON 0100 (DL = 1)
SR 0001 (C = 1) SR 0201 (DA, C = 1)
Before After
Instruction Instruction
PC 01 C000 PC 01 C004
DCOUNT 0000 DCOUNT 0160
DOSTART FF FFFF DOSTART 01 C004
DOEND FF FFFF DOEND 01 C014
CORCON 0000 CORCON 0100 (DL = 1)
SR 0008 (N = 1) SR 0208 (DA, N = 1)
2: The linker will convert the specified expression into the offset to
be used.
Words: 2
Cycles: 2
Before After
Instruction Instruction
PC 00 2000 PC 00 2004
W0 0012 W0 0012
DCOUNT 0000 DCOUNT 0012
DOSTART FF FFFF DOSTART 00 2004
DOEND FF FFFF DOEND 00 2010
CORCON 0000 CORCON 0100 (DL = 1)
SR 0000 SR 0080 (DA = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2004
W7 E00F W7 E00F
DCOUNT 0000 DCOUNT 200F
DOSTART FF FFFF DOSTART 00 2004
DOEND FF FFFF DOEND 00 2010
CORCON 0000 CORCON 0100 (DL = 1)
SR 0000 SR 0080 (DA = 1)
by the user. See the specific device family reference manual for
Instruction
details.
2: The linker will convert the specified expression into the offset to
be used.
Words: 2
Cycles: 2
Before After
Instruction Instruction
PC 00 2000 PC 00 2004
W0 0012 W0 0012
DCOUNT 0000 DCOUNT 0012
DOSTART FF FFFF DOSTART 00 2004
DOEND FF FFFF DOEND 00 2010
CORCON 0000 CORCON 0100 (DL = 1)
SR 0000 SR 0080 (DA = 1)
Before After
Instruction Instruction
PC 00 2000 PC 00 2004
W7 E00F W7 E00F
DCOUNT 0000 DCOUNT 200F
DOSTART FF FFFF DOSTART 00 2004
DOEND FF FFFF DOEND 00 2010
CORCON 0000 CORCON 0100 (DL = 1)
SR 0000 SR 0080 (DA = 1)
Before After
Instruction Instruction
W4
W8
009A
1100
W4
W8
0057
1102
5
W10 2300 W10 22FE
Descriptions
Before After
Instruction Instruction
W5 43C2 W5 3F3F
W9 1200 W9 1202
W11 2500 W11 2500
W12 0008 W12 0008
ACCB 00 28E3 F14C ACCB 00 11EF 1F04
Data 1200 6A7C Data 1200 6A7C
Data 2508 2B3D Data 2508 2B3D
SR 0000 SR 0000
Before After
Instruction Instruction 5
W4 009A W4 0057
W8 1100 W8 1102
Descriptions
Instruction
Before After
Instruction Instruction
W5 43C2 W5 3F3F
W9 1200 W9 1202
W11 2500 W11 2500
W12 0008 W12 0008
ACCB 00 28E3 F14C ACCB 00 3AD3 1050
Data 1200 6A7C Data 1200 6A7C
Data 2508 2B3D Data 2508 2B3D
SR 0000 SR 0000
Before After
Instruction Instruction
W1 55FF W1 A3A3
W9 A3A3 W9 55FF
SR 0000 SR 0000
Before After
Instruction Instruction
W4 ABCD W4 4321
W5 4321 W5 ABCD
SR 0000 SR 0000
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W1 55FF W1 55FF
W9 FFFF W9 0000
SR 0000 SR 0000
Before After
Instruction Instruction
W1 FFFF W1 FFFF
W9 BBBB W9 FFF1
SR 0000 SR 0001 (C = 1)
Example 3: FBCL [W1++], W9 ; Find 1st bit change from left in [W1]
; and store result to W9
; Post-increment W1
Before After
Instruction Instruction
W1 2000 W1 2002
W9 BBBB W9 FFF9
Data 2000 FF0A Data 2000 FF0A
SR 0000 SR 0000
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: FF1L W2, W5 ; Find the 1st one from the left in W2
; and store result to W5
Before After
Instruction Instruction
W2 000A W2 000A
W5 BBBB W5 000D
SR 0000 SR 0000
Example 2: FF1L [W2++], W5 ; Find the 1st one from the left in [W2]
; and store the result to W5
; Post-increment W2
Before After
Instruction Instruction
W2 2000 W2 2002
W5 BBBB W5 0000
Data 2000 0000 Data 2000 0000
SR 0000 SR 0001 (C = 1)
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: FF1R W1, W9 ; Find the 1st one from the right in W1
; and store the result to W9
Before After
Instruction Instruction
W1 000A W1 000A
W9 BBBB W9 0002
SR 0000 SR 0000
Example 2: FF1R [W1++], W9 ; Find the 1st one from the right in [W1]
; and store the result to W9
; Post-increment W1
Before After
Instruction Instruction
W1 2000 W1 2002
W9 BBBB W9 0010
Data 2000 8000 Data 2000 8000
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 02 6000 PC 02 7844
SR 0000 SR 0000
Before After
Instruction Instruction
PC 02 6000 PC 00 0102
SR 0000 SR 0000
Before After
Instruction Instruction
W4 7844 W4 7844
PC 00 6000 PC 00 7844
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W4 7844 W4 7844
PC 00 6000 PC 00 7844
SR 0000 SR 0000
Before After
Instruction Instruction
PC 02 6000 PC 02 6844
W4 6844 W4 6844
W5 0002 W5 0002
W15 A268 W15 A26C
Data A268 FFFF Data A268 6004
Data A26A FFFF Data A26A 0002
SR 0000 SR 0000
5
Descriptions
Instruction
INC Increment f
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
Data 1000 8FFF Data 1000 8F00
SR 0000 SR 0101 (DC, C = 1)
Before After
Instruction Instruction
WREG ABCD WREG 9000
Data 1000 8FFF Data 1000 8FFF
SR 0000 SR 0108 (DC, N = 1)
INC Increment Ws
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W1 FF7F W1 FF7F
W2 2000 W2 2001 5
Data 2000 ABCD Data 2000 80CD
SR 0000 SR 010C (DC, N, OV = 1)
Descriptions
Instruction
Before After
Instruction Instruction
W1 FF7F W1 FF7F
W2 2000 W2 FF80
SR 0000 SR 0108 (DC, N = 1)
INC2 Increment f by 2
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
Data 1000 8FFF Data 1000 8F01
SR 0000 SR 0101 (DC, C = 1)
Before After
Instruction Instruction
WREG ABCD WREG 9001
Data 1000 8FFF Data 1000 8FFF
SR 0000 SR 0108 (DC, N = 1) 5
Descriptions
Instruction
INC2 Increment Ws by 2
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W1 FF7F W1 FF7F
W2 2000 W2 2001
Data 2000 ABCD Data 2000 81CD
SR 0000 SR 010C (DC, N, OV = 1)
Before After
Instruction Instruction
W1 FF7F W1 FF7F
W2 2000 W2 FF81
SR 0000 SR 0108 (DC, N = 1)
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG 1234 WREG 1234
Data 1000 FF00 Data 1000 FF34
SR 0000 SR 0000
Before After
Instruction Instruction
WREG 1234 WREG 1FBF
Data 1000 0FAB Data 1000 0FAB
SR 0008 (N = 1) SR 0000
Before After
Instruction Instruction
W9 1234 W9 12BE
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
W4 A34D W4 A3EF
SR 0000 SR 0008 (N = 1) 5
Descriptions
Instruction
Example 1: IOR.B W1, #0x5, [W9++] ; IOR W1 and 0x5 (Byte mode)
; Store to [W9]
; Post-increment W9
Before After
Instruction Instruction
W1 AAAA W1 AAAA
W9 2000 W9 2001
Data 2000 0000 Data 2000 00AF
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
W1 0000 W1 0000
W9 A34D W9 0000
SR 0000 SR 0002 (Z = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: IOR.B W1, [W5++], [W9++] ; IOR W1 and [W5] (Byte mode)
; Store result to [W9]
; Post-increment W5 and W9
Before
Instruction
After
Instruction
5
W1 AAAA W1 AAAA
Descriptions
W5 2000 W5 2001
Instruction
W9 2400 W9 2401
Data 2000 1155 Data 2000 1155
Data 2400 0000 Data 2400 00FF
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
W1 AAAA W1 AAAA
W5 5555 W5 5555
W9 A34D W9 FFFF
SR 0000 SR 0008 (N = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
W4 2000 W4 2002
ACCB 00 5125 ABCD ACCB FF 9108 0000
Data 2000 1221 Data 2000 1221
SR 0000 SR 4800 (OB, OAB = 1)
Before After
Instruction Instruction
W2 4002 W2 4000
ACCA 00 5125 ABCD ACCA FF FF22 1000
Data 4000 9108 Data 4000 9108
Data 4002 1221 Data 4002 1221
SR 0000 SR 0000
Before After
Instruction Instruction
W14 2000 W14 2002
W15 2000 W15 20A2
Data 2000 0000 Data 2000 2000
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W14 2000 W14 2002
W15 2000 W15 20A2
Data 2000 0000 Data 2000 2000
SR 0000 SR 0000
CORCON 0000 CORCON 0004
0 C
Status Affected: N, Z, C
Encoding: 1101 0101 0BDf ffff ffff ffff
Description: 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: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before
Instruction
After
Instruction 5
Data 600 55FF Data 600 557F
SR 0000 SR 0001 (C = 1)
Descriptions
Instruction
Before After
Instruction Instruction
Data 600 55FF Data 600 55FF
WREG 0000 WREG 2AFF
SR 0000 SR 0001 (C = 1)
0 C
Status Affected: N, Z, C
Encoding: 1101 0001 0Bqq qddd dppp ssss
Description: 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: 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.
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
5
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Descriptions
Instruction
Before After
Instruction Instruction
W0 FF03 W0 FF03
W1 2378 W1 2301
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
W0 8000 W0 8000
W1 2378 W1 4000
SR 0000 SR 0000
Before After
Instruction Instruction
W4 C800 W4 C800
W5 1200 W5 0003
SR 0000 SR 0000
Before After
Instruction Instruction
W4 0505 W4 0505
W5 F000 W5 0282
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 C00C W0 C00C
W1 0001 W1 0001
W2 2390 W2 6006
SR 0000 SR 0000
Before After
Instruction Instruction
W3 DD43 W3 0000
W4 000C W4 000C
W5 0800 W5 0800
SR 0000 SR 0002 (Z = 1)
Syntax: {label:} MAC Wm*Wn, Acc {,[Wx], Wxd} {,[Wy], Wyd} {,AWB}
{,[Wx] + = kx, Wxd} {,[Wy] + = ky, Wyd}
{,[Wx] – = kx, Wxd} {,[Wy] – = ky, Wyd}
{,[W9 + W12], Wxd} {,[W11 + W12], Wyd}
Before After
Instruction Instruction
W4 A022 W4 2567
W5 B900 W5 909C
W8 0A00 W8 0A06
W10 1800 W10 1802
ACCA 00 1200 0000 ACCA 00 472D 2400
Data 0A00 2567 Data 0A00 2567
Data 1800 909C Data 1800 909C
CORCON 00C0 CORCON 00C0
SR 0000 SR 0000
Before After
Instruction Instruction
W4 1000 W4 5BBE
W5 3000 W5 C967
W8 0A00 W8 09FE
W10 1800 W10 1802
W13 2000 W13 0001
ACCA 23 5000 2000 ACCA 23 5600 2000
ACCB 00 0000 8F4C ACCB 00 0000 1F4C
Data 0A00 5BBE Data 0A00 5BBE
Data 1800 C967 Data 1800 C967
CORCON 00D0 CORCON 00D0
SR 0000 SR 8800 (OA, OAB = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
W4 A022 W4 A230
W5 B200 W5 650B
W9 0C00 W9 0C00
W10 1900 W10 18FE
W12 0020 W12 0020
ACCB 00 2000 0000 ACCB 00 67CD 0908
Data 0C20 A230 Data 0C20 A230
Data 1900 650B Data 1900 650B
CORCON 00C0 CORCON 00C0
SR 0000 SR 0000
Before After
Instruction Instruction
W7 76AE W7 23FF
W11 2000 W11 1FFE
ACCA FE 9834 4500 ACCA FF 063E 0188
Data 2000 23FF Data 2000 23FF
CORCON 00D0 CORCON 00D0
SR 0000 SR 8800 (OA, OAB = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG (W0) 9080 WREG (W0) 9055
TMR0 2355 TMR0 2355
SR 0000 SR 0000
Before After
5
Instruction Instruction
Data 0800 B29F Data 0800 B29F
Descriptions
Instruction
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
WREG (W0) 98F3 WREG (W0) 98F3
Data 0800 4509 Data 0800 F309
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
WREG (W0) 00A0 WREG (W0) 00A0
DISICNT 0000 DISICNT 00A0
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W12 78FA W12 00F0
CORCON 00F0 CORCON 00F0
SR 0000 SR 0000
Before After
Instruction Instruction
W3 0035 W3 ABCD 5
Data 27FE ABCD Data 27FE ABCD
SR 0000 SR 0000
Descriptions
Instruction
Before After
Instruction Instruction
W4 1200 W4 1200
XMODSRT 1340 XMODSRT 1200
SR 0000 SR 0000
Before After
Instruction Instruction
W8 F200 W8 F200
Data 1222 FD88 Data 1222 F200
SR 0000 SR 0000
Before After
Instruction Instruction
W5 7899 W5 7817
SR 0000 SR 0000
Before After
Instruction Instruction
W9 AB23 W9 ABFE
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W13 091B W13 4231
SR 0000 SR 0000
Before After
Instruction Instruction
W2 B004 W2 0004
SR 0000 SR 0000
Before After
Instruction Instruction
W8 23FF W8 FC18
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W8 1008 W8 1008
W10 4009 W10 4033
Data 101A 3312 Data 101A 3312
SR 0000 SR 0000 5
Descriptions
Instruction
Before After
Instruction Instruction
W2 9088 W2 5634
W4 0800 W4 0800
Data 0BE8 5634 Data 0BE8 5634
SR 0000 SR 0000
Before After
Instruction Instruction
W0 9015 W0 9015
W1 1800 W1 1800
Data 1806 2345 Data 1806 1545
SR 0000 SR 0000
Before After
Instruction Instruction
W1 1000 W1 1000
W11 8813 W11 8813
Data 0C00 FFEA Data 0C00 8813
SR 0000 SR 0000
MOV Move Ws to Wd
MOV Move Ws to Wd
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W0 0A01 W0 0A00
W4 2976 W4 2989
Data 0A00 8988 Data 0A00 8988
SR 0000 SR 0000
Before After
Instruction Instruction
W2 0800 W2 0800
W3 0040 W3 0040
W6 1228 W6 122A
Data 0840 9870 Data 0840 0690
Data 1228 0690 Data 1228 0690
SR 0000 SR 0000
Before After
Instruction Instruction
W2 12FB W2 12FB
W3 9877 W3 9877
W6 9833 W6 12FB
W7 FCC6 W7 9877
SR 0000 SR 0000
Before After
Instruction Instruction
W4 B012 W4 A319
W5 FD89 W5 9927
W7 0900 W7 08FC
Data 0900 A319 Data 0900 A319
Data 0902 9927 Data 0902 9927
SR 0000 SR 0000
Operands: lit10 ∈ [0 ... 1023], lit9 ∈ [0 ... 511], lit8 ∈ [0 ... 255]
Operation: lit10 →DSRPAG or lit9 →DSWPAG or lit8 →TBLPAG
Status Affected: None
Encoding: 1111 1110 1100 PPkk kkkk kkkk
Description: 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: This instruction operates in word mode only.
Words: 1
Cycles: 1
Before After
Instruction Instruction
DSRPAG 0000 DSRPAG 0002
5
Descriptions
Instruction
Before After
Instruction Instruction
DSRPAG 0000 DSRPAG 0002
W2 0002 W2 0002
5
Descriptions
Instruction
Before After
Instruction Instruction
W6 A022 W6 7811
W7 B200 W7 B2AF
W9 0800 W9 0800
W11 1900 W11 1904
W13 0020 W13 3290
ACCA 00 3290 5968 ACCA 00 3290 5968
Data 0800 7811 Data 0800 7811
Data 1900 B2AF Data 1900 B2AF
SR 0000 SR 0000
Before After
Instruction Instruction
W4 76AE W4 BB00
W6 2000 W6 52CE
W9 1200 W9 11FE
W11 2000 W11 2000
W12 0024 W12 0024
W13 2300 W13 2302
ACCB 00 9834 4500 ACCB 00 9834 4500
Data 1200 BB00 Data 1200 BB00
Data 2024 52CE Data 2024 52CE
Data 2300 23FF Data 2300 9834
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W4 C000 W4 C000
W5 9000 W5 9000
W6 0800 W6 671F
W7 B200 W7 E3DC
W8 1780 W8 1782
W10 2400 W10 23FE
ACCA FF F780 2087 ACCA 00 3800 0000
Data 1780 671F Data 1780 671F
Data 2400 E3DC Data 2400 E3DC
CORCON 0000 CORCON 0000
SR 0000 SR 0000
Before After
Instruction Instruction
W4 C000 W4 8FDC
W5 9000 W5 0078
W6 671F W6 671F
W7 E3DC W7 E3DC
W8 1782 W8 1784
W10 23FE W10 23FC
ACCB 00 9834 4500 ACCB FF E954 3748
Data 1782 8FDC Data 1782 8FDC
Data 23FE 0078 Data 23FE 0078
CORCON 0000 CORCON 0000
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W6 6500 W6 B865
W9 0900 W9 0902
ACCA 00 7C80 0908 ACCA 00 4FB2 0000
Data 0900 B865 Data 0900 B865
CORCON 0000 CORCON 0000
SR 0000 SR 0000
Before After
Instruction Instruction
W4 E228 W4 8911
W5 9000 W5 F678
W9 1700 W9 1700
W10 1B00 W10 1B02
W12 FF00 W12 FF00
ACCB 00 9834 4500 ACCB 00 06F5 4C80
Data 1600 8911 Data 1600 8911
Data 1B00 F678 Data 1B00 F678
CORCON 0000 CORCON 0000
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W4 3023 W4 0054
W5 1290 W5 660A
W8 0B00 W8 0B02
W10 2000 W10 2002
ACCA 00 0000 2387 ACCA FF FC82 7650
Data 0B00 0054 Data 0B00 0054
Data 2000 660A Data 2000 660A
CORCON 0001 CORCON 0001
SR 0000 SR 0000
Before After
Instruction Instruction
W4 3023 W4 0054
W5 1290 W5 660A
W8 0B00 W8 0B02
W10 2000 W10 2002
ACCA 00 0000 2387 ACCA FF F904 ECA0
Data 0B00 0054 Data 0B00 0054
Data 2000 660A Data 2000 660A
CORCON 0000 CORCON 0000
SR 0000 SR 0000
Syntax: {label:} MSC Wm * Wn, Acc {,[Wx], Wxd} {,[Wy], Wyd} {,AWB}
{,[Wx] + = kx, Wxd} {,[Wy] + = ky, Wyd}
{,[Wx] – = kx, Wxd} {,[Wy] – = ky, Wyd}
{,[W9 + W12], Wxd} {,[W11 + W12], Wyd}
5
Descriptions
Instruction
Before After
Instruction Instruction
W6 9051 W6 D309
W7 7230 W7 100B
W8 0C00 W8 0BFC
W10 1C00 W10 1BFC
ACCA 00 0567 8000 ACCA 00 3738 5ED0
Data 0C00 D309 Data 0C00 D309
Data 1C00 100B Data 1C00 100B
CORCON 0001 CORCON 0001
SR 0000 SR 0000
Before After
Instruction Instruction
W4 0500 W4 0500
W5 2000 W5 3579
W11 1800 W11 1800
W12 0800 W12 0800
W13 6233 W13 3738
ACCA 00 3738 5ED0 ACCA 00 3738 5ED0
ACCB 00 1000 0000 ACCB 00 0EC0 0000
Data 2000 3579 Data 2000 3579
CORCON 0000 CORCON 0000
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG (W0) 9823 WREG (W0) 9823
W2 FFFF W2 13B0
W3
Data 0800
FFFF
2690
W3
Data 0800
FFFF
2690
5
SR 0000 SR 0000
Descriptions
Instruction
Before After
Instruction Instruction
WREG (W0) F001 WREG (W0) F001
W2 0000 W2 C287
W3 0000 W3 2F5E
TMR1 3287 TMR1 3287
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”. 5
Descriptions
Instruction
Before After
Instruction Instruction
W0 9823 W0 9823
W1 67DC W1 67DC
W12 FFFF W12 D314
W13 FFFF W13 D5DC
SR 0000 SR 0000
Before After
Instruction Instruction
W0 FFFF W0 28F8
W1 FFFF W1 0000
W2 0045 W2 0045
W4 27FE W4 27FC
Data 27FC 0098 Data 27FC 0098
SR 0000 SR 0000
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Instruction Instruction
W0 9823 W0 9823
W1 67DC W1 67DC
Acc A 00 0000 0000 Acc A FF D5DC D314
SR 0000 SR 0000
Before After
Instruction Instruction
W0 C000 W0 C000
W2 1234 W2 4000
W3 C9BA W3 FFF8
SR 0000 SR 0000
Before After
Instruction Instruction
W0 ABCD W0 2400
W1 89B3 W1 000F
W2 F240 W2 F240
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 68DC W0 0000
W1 AA40 W1 F100
W8 F000 W8 F000
W9 178C W9 178C
Data 178C F000 Data 178C F000
SR 0000 SR 0000
Before After
Instruction Instruction
W2 0040 W2 0040
W3 0280 W3 0282
W4 1819 W4 1A00
W5 2021 W5 0000
Data 0282 0068 Data 0282 0068
SR 0000 SR 0000
5
Descriptions
Instruction
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W8 F000 W8 F000
W9 F000 W9 F000
Acc A 00 0000 0000 Acc A FF F100 0000
SR 0000 SR 0000
5
Descriptions
Instruction
Words: 1
Cycles: 1
Before After
Instruction Instruction
W8 0042 W8 0042
Acc A 00 0000 0000 Acc A 00 0000 0084
SR 0000 SR 0000
Before After
Instruction Instruction
W0 C000 W0 C000
W1 2300 W1 2300
W2 00DA W2 0000
W3 CC25 W3 F400
Data 2300 F000 Data 2300 F000
SR 0000 SR 0000
Before After
Instruction Instruction
W5 0C00 W5 0C02
W6 FFFF W6 FFFF
W10 0908 W10 8001
W11 6EEB W11 7FFE
Data 0C00 7FFF Data 0C00 7FFF
SR 0000 SR 0000
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 C000 W0 0000
W1 F000 W1 F000
Acc B 00 0000 0000 Acc B FF F400 0000
SR 0000 SR 0000
Before After
Instruction Instruction
W0 2323 W0 2323
W12 4512 W12 0F0D
W13 7821 W13 0002
SR 0000 SR 0000
Example 2:
5
MUL.UU W7, #0x1F, W0 ; Multiply W7 by literal 0x1F
; Store the result to W0:W1
Before After
Descriptions
Instruction Instruction
Instruction
W0 780B W0 55C0
W1 3805 W1 001D
W7 F240 W7 F240
SR 0000 SR 0000
Before After
Instruction Instruction
W0 FFFF W0 FFFF
W2 2300 W2 0001
W3 00DA W3 FFFE
W4 FFFF W4 FFFF
SR 0000 SR 0000
Before After
Instruction Instruction
W0 1024 W0 1024
W1 2300 W1 2302
W4 9654 W4 6D34
W5 BDBC W5 0D80
Data 2300 D625 Data 2300 D625
SR 0000 SR 0000
5
Descriptions
Instruction
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: MUL.UU W4, W0, B
Before After
Instruction Instruction
W0 FFFFF W0 FFFFF
W4 FFFFF W4 FFFFF
Acc B 00 0000 0000 Acc B FF FFFE 0001
SR 0000 SR 0000
Words: 1
Cycles: 1
Before After
Instruction Instruction
W8 0042 W8 0042 5
Acc A 00 0000 0000 Acc A 00 0000 0084
SR 0000 SR 0000
Descriptions
Instruction
Before After
Instruction Instruction
W0 9823 W0 9823
W1 67DC W1 67DC
W12 FFFF W12 D314
SR 0000 SR 0000
Before After
Instruction Instruction
W0 FFFF W0 28F8
W2 0045 W2 0045
W4 27FE W4 27FC
Data 27FC 0098 Data 27FC 0098
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 68DC W0 0000
W8 F000 W8 F000
W9 178C W9 178C
Data 178C F000 Data 178C F000
SR 0000 SR 0000
Before After
Instruction Instruction
W2 0040 W2 0040
W3 0280 W3 0282
W4 1819 W4 1A00
Data 0282 0068 Data 0282 0068
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 68DC W0 4000
W8 1000 W8 1000
SR 0000 SR 0000
Before After
5
Instruction Instruction
W0 C000 W0 C000
Descriptions
Instruction
W1 2300 W1 2300
W2 00DA W2 0000
Data 2300 F000 Data 2300 F000
SR 0000 SR 0000
Before After
Instruction Instruction
W5 0C00 W5 0C02
W6 FFFF W6 FFFF
W10 0908 W10 8001
Data 0C00 7FFF Data 0C00 7FFF
SR 0000 SR 0000
Before After
Instruction Instruction
W0 FFFF W0 FFFF
W2 2300 W2 0001 5
W4 FFFF W4 FFFF
SR 0000 SR 0000
Descriptions
Instruction
Before After
Instruction Instruction
W2 2300 W2 4000
W4 1000 W4 1000
SR 0000 SR 0000
NEG Negate f
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG (W0) 9080 WREG (W0) 90AB
Data 0880 2355 Data 0880 2355
SR 0000 SR 0008 (N = 1)
Example 2: NEG 0x1200 ; Negate (0x1200) (Word mode)
Before After
Instruction Instruction
Data 1200
SR
8923
0000
Data 1200 76DD
SR 0000
5
NEG Negate Ws
Descriptions
Instruction
NEG Negate Ws
[Ws++], [Wd++]
[Ws--], [Wd--]
[++Ws], [++Wd]
[--Ws], [--Wd]
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: NEG.B W3, [W4++] ; Negate W3 and store to [W4] (Byte mode)
; Post-increment W4
Before After
Instruction Instruction
W3 7839 W3 7839
W4 1005 W4 1006
Data 1004 2355 Data 1004 C755
SR 0000 SR 0008 (N = 1)
Example 2: NEG [W2++], [--W4] ; Pre-decrement W4 (Word mode)
; Negate [W2] and store to [W4]
; Post-increment W2
Before After
Instruction Instruction
W2 0900 W2 0902
W4 1002 W4 1000
Data 0900 870F Data 0900 870F
Data 1000 5105 Data 1000 78F1
SR 0000 SR 0000
Before After
Instruction Instruction
ACCA 00 3290 59C8 ACCA FF CD6F A638
CORCON 0000 CORCON 0000
SR 0000 SR 0000
Example 2: NEG B ; Negate ACCB
; Store result to ACCB
; CORCON = 0x00C0 (normal saturation)
Before After
Instruction Instruction
ACCB FF F230 10DC ACCB 00 0DCF EF24
CORCON 00C0 CORCON 00C0
SR 0000 SR 0000
5
Descriptions
Instruction
NOP No Operation
Operands: None
Operation: No Operation
Status Affected: None
Encoding: 0000 0000 xxxx xxxx xxxx xxxx
Description: No Operation is performed.
The ‘x’ bits can take any value.
Words: 1
Cycles: 1
Before After
Instruction Instruction
PC 00 1092 PC 00 1094
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 08AE PC 00 08B0
SR 0000 SR 0000
NOPR No Operation
Operands: None
Operation: No Operation
Status Affected: None
Encoding: 1111 1111 xxxx xxxx xxxx xxxx
Description: No Operation is performed.
The ‘x’ bits can take any value.
Words: 1
Cycles: 1
Before After
Instruction Instruction
PC 00 2430 PC 00 2432
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 1466 PC 00 1468
SR 0000 SR 0000
Before After
Instruction Instruction
W15 1006 W15 1004
Data 1004 A401 Data 1004 A401
Data 1230 2355 Data 1230 A401
SR 0000 SR 0000 5
Descriptions
Instruction
Before After
Instruction Instruction
W15 2000 W15 1FFE
Data 0880 E3E1 Data 0880 A090
Data 1FFE A090 Data 1FFE A090
SR 0000 SR 0000
Before After
Instruction Instruction
W4 EDA8 W4 C45A
W15 1008 W15 1006
Data 1006 C45A Data 1006 C45A
SR 0000 SR 0000
Before After
Instruction Instruction
W10 0E02 W10 0E04
W15 1766 W15 1764
Data 0E04 E3E1 Data 0E04 C7B5
Data 1764 C7B5 Data 1764 C7B5
SR 0000 SR 0000
Before After
Instruction Instruction 5
W6 07BB W6 3210
W7 89AE W7 7654
Descriptions
Instruction
Before After
Instruction Instruction
W0 673E W0 791C
W1 DD23 W1 D400
W15 0BBC W15 0BB8
Data 0BB8 791C Data 0BB8 791C
Data 0BBA D400 Data 0BBA D400
SR 0000 SR 0000
Operands: None
Operation: POP shadow registers
Status Affected: DC, N, OV, Z, C
Encoding: 1111 1110 1000 0000 0000 0000
Description: 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: 1
Cycles: 1
Before After
Instruction Instruction
W0 07BB W0 0000
W1 03FD W1 1000
W2 9610 W2 2000
W3 7249 W3 3000
SR 00E0 (IPL = 7) SR 00E1 (IPL = 7, C = 1)
Note: After instruction execution, contents of shadow registers are NOT modified.
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W15 0B00 W15 0B02
Data 0B00 791C Data 0B00 D400
Data 2004 D400 Data 2004 D400
SR 0000 SR 0000
Before After
Instruction Instruction
W15 0920 W15 0922
Data 0920 0000 Data 0920 67AA
Data 0C0E 67AA Data 2004 67AA
SR 0000 SR 0000 5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W2 6889 W2 6889
W15 1566 W15 1568
Data 1566 0000 Data 1566 6889
SR 0000 SR 0000
Before After
Instruction Instruction
W5 1200 W5 1200
W10 0044 W10 0044
W15 0806 W15 0808
Data 0806 216F Data 0806 B20A
Data 1244 B20A Data 1244 B20A
SR 0000 SR 0000
Before
Instruction
After
Instruction 5
W6 C451 W6 C451
W7 3380 W7 3380
Descriptions
Instruction
Before After
Instruction Instruction
W10 80D3 W10 80D3
W11 4550 W11 4550
W15 0C08 W15 0C0C
Data 0C08 79B5 Data 0C08 80D3
Data 0C0A 008E Data 0C0A 4550
SR 0000 SR 0000
Operands: None
Operation: PUSH shadow registers
Status Affected: None
Encoding: 1111 1110 1010 0000 0000 0000
Description: 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: 1
Cycles: 1
Before After
Instruction Instruction
W0 0000 W0 0000
W1 1000 W1 1000
W2 2000 W2 2000
W3 3000 W3 3000
SR 0001 (C = 1) SR 0001 (C = 1)
Note: After an instruction execution, contents of the shadow registers are updated.
5
Descriptions
Instruction
Before After
Instruction Instruction
SR 0040 (IPL = 2) SR 0040 (IPL = 2)
Before After
Instruction Instruction
SR 0020 (IPL = 1) SR 0020 (IPL = 1)
Before After
Instruction Instruction
PC 01 2004 PC 01 2458
W15 0810 W15 0814
Data 0810 FFFF Data 0810 2006
Data 0812 FFFF Data 0812 0001
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 620E PC 00 7000
W15 0C50 W15 0C54
Data 0C50 FFFF Data 0C50 6210
Data 0C52 FFFF Data 0C52 0000
SR 0000 SR 0000
Before After
Instruction Instruction
PC 01 2004 PC 01 2458
W15 0810 W15 0814
Data 0810 FFFF Data 0810 2006
Data 0812 FFFF Data 0812 0001
SR 0000 SR 0000 5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 620E PC 00 7000
W15 0C50 W15 0C54
Data 0C50 FFFF Data 0C50 6210
Data 0C52 FFFF Data 0C52 0000
SR 0000 SR 0000
Before After
Instruction Instruction
PC 01 000A PC 00 FF8C
W6 FFC0 W6 FFC0
W15 1004 W15 1008
Data 1004 98FF Data 1004 000C
Data 1006 2310 Data 1006 0001
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 0302 PC 00 0450
W2 00A6 W2 00A6
W15 1004 W15 1008
Data 1004 32BB Data 1004 0304
Data 1006 901A Data 1006 0000
SR 0000 SR 0000
Before After
Instruction Instruction
PC 01 000A PC 00 FF8C
W6 FFC0 W6 FFC0
W15 1004 W15 1008
Data 1004 98FF Data 1004 000C
Data 1006 2310 Data 1006 0001
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 0302 PC 00 0450
W2 00A6 W2 00A6
W15 1004 W15 1008
Data 1004 32BB Data 1004 0304
Data 1006 901A Data 1006 0000
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 0452 PC 00 0454
RCOUNT 0000 RCOUNT 0009
SR 0000 SR 0010 (RA = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 089E PC 00 08A0
RCOUNT 0000 RCOUNT 03FF
SR 0000 SR 0010 (RA = 1)
Before After
Instruction Instruction
PC 00 0452 PC 00 0454
RCOUNT 0000 RCOUNT 0009
SR 0000 SR 0010 (RA = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 089E PC 00 08A0
RCOUNT 0000 RCOUNT 03FF
SR 0000 SR 0010 (RA = 1)
Before After
Instruction Instruction
PC 00 0A26 PC 00 0A28
W4 0023 W4 0023 5
RCOUNT 0000 RCOUNT 0023
SR 0000 SR 0010 (RA = 1)
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 089E PC 00 08A0
W10 00FF W10 00FF
RCOUNT 0000 RCOUNT 00FF
SR 0000 SR 0010 (RA = 1)
Before After
Instruction Instruction
PC 00 0A26 PC 00 0A28
W4 0023 W4 0023
RCOUNT 0000 RCOUNT 0023 5
SR 0000 SR 0010 (RA = 1)
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 089E PC 00 08A0
W10 00FF W10 00FF
RCOUNT 0000 RCOUNT 00FF
SR 0000 SR 0010 (RA = 1)
RESET Reset
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: 1111 1110 0000 0000 0000 0000
Description: 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: Refer to the specific device family reference manual for the
power-on value of all registers.
Words: 1
Cycles: 1
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 202A PC 00 0000
W0 8901 W0 0000
W1 08BB W1 0000
W2 B87A W2 0000
W3 872F W3 0000
W4 C98A W4 0000
W5 AAD4 W5 0000
W6 981E W6 0000
W7 1809 W7 0000
W8 C341 W8 0000
W9 90F4 W9 0000
W10 F409 W10 0000
W11 1700 W11 0000
W12 1008 W12 0000
W13 6556 W13 0000
W14 231D W14 0000
W15 1704 W15 0800
SPLIM 1800 SPLIM 0000
TBLPAG 007F TBLPAG 0000
PSVPAG 0001 PSVPAG 0000
CORCON 00F0 CORCON 0020 (SATDW = 1)
RCON 0000 RCON 0040 (SWR = 1)
SR 0021 (IPL, C = 1) SR 0000
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: IPL<3:0>, RA, N, OV, Z, C
Encoding: 0000 0110 0100 0000 0000 0000
Description: Return from Interrupt Service Routine. The stack is POPped, which
loads the low byte of the STATUS register, IPL<3> (CORCON<3>) and
the Most Significant Byte of the PC. The stack is POPped again, which
loads the lower 16 bits of the PC.
Note 1: Restoring IPL<3> and the low byte of the STATUS register
restores the Interrupt Priority Level to the level before the
execution was processed.
2: Before RETFIE is executed, the appropriate interrupt flag
must be cleared in software to avoid recursive interrupts.
Words: 1
Cycles: 3 (2 if exception pending)
Before After
Instruction Instruction
PC 00 0A26 PC 01 0230
W15 0834 W15 0830
Data 0830 0230 Data 0830 0230
Data 0832 8101 Data 0832 8101
CORCON 0001 CORCON 0001
SR 0000 SR 0081 (IPL = 4, C = 1)
Before After
Instruction Instruction 5
PC 00 8050 PC 00 7008
W15 0926 W15 0922
Descriptions
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: IPL<3:0>, RA, N, OV, Z, C, SFA
Encoding: 0000 0110 0100 0000 0000 0000
Description: Return from Interrupt Service Routine. The stack is POPped, which
loads the low byte of the STATUS register, IPL<3> (CORCON<3>) and
the Most Significant Byte of the PC. The stack is POPped again, which
loads the lower 16 bits of the PC.
Note 1: Restoring IPL<3> and the low byte of the STATUS register
restores the Interrupt Priority Level to the level before the
execution was processed.
2: Before RETFIE is executed, the appropriate interrupt flag
must be cleared in software to avoid recursive interrupts.
Words: 1
Cycles: 6 (5 if exception pending)
Before After
Instruction Instruction
PC 00 0A26 PC 01 0230
W15 0834 W15 0830
Data 0830 0230 Data 0830 0230
Data 0832 8101 Data 0832 8101
CORCON 0001 CORCON 0001
SR 0000 SR 0081 (IPL = 4, C = 1)
Before After
Instruction Instruction
PC 00 8050 PC 00 7008
W15 0926 W15 0922
Data 0922 7008 Data 0922 7008
Data 0924 0300 Data 0924 0300
CORCON 0000 CORCON 0000
SR 0000 SR 0003 (Z, C = 1)
Before After
Instruction Instruction
PC 00 0440 PC 00 7006
W0 9846 W0 980A
W15 1988 W15 1984
Data 1984 7006 Data 1984 7006
Data 1986 0000 Data 1986 0000
SR 0000 SR 0000 5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 050A PC 01 7008
W2 0993 W2 0230
W15 1200 W15 11FC
Data 11FC 7008 Data 11FC 7008
Data 11FE 0001 Data 11FE 0001
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 0440 PC 00 7006
W0 9846 W0 980A
W15 1988 W15 1984
Data 1984 7006 Data 1984 7006
Data 1986
SR
0000
0000
Data 1986
SR
0000
0000
5
Descriptions
Instruction
Before After
Instruction Instruction
PC 00 050A PC 01 7008
W2 0993 W2 0230
W15 1200 W15 11FC
Data 11FC 7008 Data 11FC 7008
Data 11FE 0001 Data 11FE 0001
SR 0000 SR 0000
RETURN Return
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 0110 0000 0000 0000 0000
Description: Return from subroutine. The software stack is POPped twice to restore
the PC. Since two POPs are made, the Stack Pointer (W15) is
decremented by 4.
Words: 1
Cycles: 3 (2 if exception pending)
Before After
Instruction Instruction
PC 00 1A06 PC 01 0004
W15 1248 W15 1244
Data 1244 0004 Data 1244 0004
Data 1246 0001 Data 1246 0001
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 5404 PC 00 0966
W15 090A W15 0906
Data 0906 0966 Data 0906 0966
Data 0908 0000 Data 0908 0000
SR 0000 SR 0000
5
Descriptions
Instruction
RETURN Return
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 0110 0000 0000 0000 0000
Description: Return from subroutine. The software stack is POPped twice to restore
the PC. Since two POPs are made, the Stack Pointer (W15) is
decremented by 4.
Words: 1
Cycles: 6 (5 if exception pending)
Before After
Instruction Instruction
PC 00 1A06 PC 01 0004
W15 1248 W15 1244
Data 1244 0004 Data 1244 0004
Data 1246 0001 Data 1246 0001
SR 0000 SR 0000
Before After
Instruction Instruction
PC 00 5404 PC 00 0966
W15 090A W15 0906
Data 0906 0966 Data 0906 0966
Data 0908 0000 Data 0908 0000
SR 0000 SR 0000
Status Affected: N, Z, C
Encoding: 1101 0110 1BDf ffff ffff ffff
Description: 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: 1
Cycles: 1
Before After
Instruction Instruction
Data 1232 E807 Data 1232 D007
SR 0000 SR 0009 (N, C = 1) 5
Descriptions
Instruction
Before After
Instruction Instruction
WREG (W0) 5601 WREG (W0) 42DD
Data 0820 216E Data 0820 216E
SR 0001 (C = 1) SR 0000 (C = 0)
Status Affected: N, Z, C
Encoding: 1101 0010 1Bqq qddd dppp ssss
Description: 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: 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.
Words: 1
Cycles: 1
Before After
Instruction
Instruction Instruction
W0 9976 W0 9976
W3 5879 W3 58ED
SR 0001 (C = 1) SR 0009 (N = 1)
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)
Status Affected: N, Z
Encoding: 1101 0110 0BDf ffff ffff ffff
Description: 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: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
Data 1232 E807 Data 1233 D107
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
WREG (W0) 5601 WREG (W0) 42DC
Data 0820 216E Data 0820 216E
SR 0001 (C = 1) SR 0000 (C = 0)
Status Affected: N, Z
Encoding: 1101 0010 0Bqq qddd dppp ssss
Description: 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: 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.
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more 5
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Descriptions
Instruction
Before After
Instruction Instruction
W0 9976 W0 9976
W3 5879 W3 58EC
SR 0001 (C = 1) SR 0009 (N, C = 1)
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)
Status Affected: N, Z, C
Encoding: 1101 0111 1BDf ffff ffff ffff
Description: 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: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
5
Instruction Instruction
Data 1232 E807 Data 1232 7407
Descriptions
Instruction
SR 0000 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)
Status Affected: N, Z, C
Encoding: 1101 0011 1Bqq qddd dppp ssss
Description: 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: 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.
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
5
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Descriptions
Instruction
Before After
Instruction Instruction
W0 9976 W0 9976
W3 5879 W3 58BB
SR 0001 (C = 1) SR 0008 (N = 1)
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)
Status Affected: N, Z
Encoding: 1101 0111 0BDf ffff ffff ffff
Description: 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: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
Data 1232 E807 Data 1232 7407
SR 0000 SR 0000
Before After
Instruction Instruction
WREG (W0) 5601 WREG (W0) 10B7
Data 0820 216E Data 0820 216E
SR 0001 (C = 1) SR 0001 (C = 1)
Status Affected: N, Z
Encoding: 1101 0011 0Bqq qddd dppp ssss
Description: 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: 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.
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 9976 W0 9976
W3 5879 W3 583B
SR 0001 (C = 1) SR 0001 (C = 1)
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 0000 SR 0008 (N = 1)
Instruction Instruction
W5 B900 W5 0120
ACCA 00 120F FF00 ACCA 00 120F FF00
CORCON 0010 CORCON 0010
SR 0000 SR 0000
Before After
Instruction Instruction
W5 2000 W5 2002
ACCB FF C891 8F4C ACCB FF C891 1F4C
Data 2000 5BBE Data 2000 8000
CORCON 0010 CORCON 0010
SR 0000 SR 0000
Before After
Instruction Instruction
W5 B900 W5 0121
ACCA 00 120F FF00 ACCA 00 120F FF00
CORCON 0010 CORCON 0010
SR 0000 SR 0000
Before After
Instruction Instruction
W5 2000 W5 2002
ACCB FF F891 8F4C ACCB FF F891 8F4C
Data 2000 5BBE Data 2000 8919
CORCON 0010 CORCON 0010
SR 0000 SR 0000
SE Sign-Extend Ws
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W3
W4
7839
1005
W3
W4
7839
0039
5
SR 0000 SR 0001 (C = 1)
Descriptions
Instruction
Before After
Instruction Instruction
W2 0900 W2 0901
W12 1002 W12 FF8F
Data 0900 008F Data 0900 008F
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
Data 0890 2739 Data 0890 FF39
SR 0000 SR 0000
Example 2: SETM WREG ; Set WREG (Word mode)
Before After
Instruction Instruction
WREG (W0) 0900 WREG (W0) FFFF
SR 0000 SR 0000
5
Descriptions
Instruction
SETM Set Ws
Before After
Instruction Instruction
W13 2739 W13 27FF
SR 0000 SR 0000
Example 2: SETM [--W6] ; Pre-decrement W6 (Word mode)
; Set [W6]
Before After
Instruction Instruction
W6 1250 W6 124E
Data 124E 3CD9 Data 124E FFFF
SR 0000 SR 0000
Before After
Instruction Instruction
ACCA 00 120F FF00 ACCA 00 0001 20FF
CORCON 0080 CORCON 0080
SR 0000 SR 0000
Before After 5
Instruction Instruction
ACCB FF FFF1 8F4C ACCB FF C63D 3000
Descriptions
SR 0000 SR 0000
Example 1: SFTAC A, W0
; Arithmetic shift ACCA by (W0)
; Store result to ACCA
; CORCON = 0x0000 (saturation disabled)
Before After
Instruction Instruction
W0 FFFC W0 FFFC
ACCA 00 320F AB09 ACCA 03 20FA B090
CORCON 0000 CORCON 0000
SR 0000 SR 8800 (OA, OAB = 1)
Before After
Instruction Instruction
W12 000F W12 000F
ACCB FF FFF1 8F4C ACCB FF FFFF FFE3
CORCON 0040 CORCON 0040
SR 0000 SR 0000
SL Shift Left f
Status Affected: N, Z, C
Encoding: 1101 0100 0BDf ffff ffff ffff
Description: 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: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before
Instruction
After
Instruction
5
Data 0908 9439 Data 0908 0839
Descriptions
SR 0000 SR 0001 (C = 1)
Instruction
Before After
Instruction Instruction
WREG (W0) 0900 WREG (W0) 80CA
Data 1650 4065 Data 1650 4065
SR 0000 SR 0008 (N = 1)
SL Shift Left Ws
C 0
Status Affected: N, Z, C
Encoding: 1101 0000 0Bqq qddd dppp ssss
Description: 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: 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.
Words: 1
Cycles: 1(1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and 5
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Descriptions
Instruction
Before After
Instruction Instruction
W3 78A9 W3 78A9
W4 1005 W4 1052
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
W2 0900 W2 0902
W12 1002 W12 1002
Data 0900 800F Data 0900 800F
Data 1002 6722 Data 1002 001E
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
W2 78A9 W2 8A90
SR 0000 SR 0008 (N = 1)
Example 2: SL W3, #12, W8 ; Shift left W3 by 12
; Store result to W8
Before After
Instruction Instruction
W3 0912 W3 0912
W8 1002 W8 2000
SR 0000 SR 0000
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 09A4 W0 09A4
W1 8903 W1 8903
W2 78A9 W2 4D20
SR 0000 SR 0000
Before After
Instruction Instruction
W4 A409 W4 A409
W5 FF01 W5 FF01
W6 0883 W6 4812
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG (W0) 7804 WREG (W0) 7804
Data 1FFE 9439 Data 1FFE 9039
SR 0000 SR 0001 (C = 1)
Example 2: SUB 0xA04, WREG ; Sub. WREG from (0xA04) (Word mode)
; Store result to WREG
Before After
Instruction Instruction
WREG (W0) 6234 WREG (W0) E2EF 5
Data 0A04 4523 Data 0A04 4523
SR 0000 SR 0008 (N = 1)
Descriptions
Instruction
Before After
Instruction Instruction
W0 7804 W0 78E1
SR 0000 SR 0008 (N = 1)
Example 2: SUB #0x108, W4 ; Sub. 0x108 from W4 (Word mode)
; Store result to W4
Before After
Instruction Instruction
W4 6234 W4 612C
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
W4 1782 W4 1782
W5 7804 W5 7872
SR 0000 SR 0005 (OV, C = 1)
Example 2: SUB W0, #0x8, [W2++] ; Sub. 0x8 from W0 (Word mode)
; Store result to [W2]
; Post-increment W2
5
Before After
Instruction Instruction
Descriptions
Instruction
W0 F230 W0 F230
W2 2004 W2 2006
Data 2004 A557 Data 2004 F228
SR 0000 SR 0009 (N, C = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W0 1732 W0 17EE
W1 7844 W1 7844
SR 0000 SR 0108 (DC, N = 1)
Example 2: SUB W7, [W8++], [W9++] ; Sub. [W8] from W7 (Word mode)
; Store result to [W9]
; Post-increment W8
; Post-increment W9
Before After
Instruction Instruction
W7 2450 W7 2450
W8 1808 W8 180A
W9 2020 W9 2022
Data 1808 92E4 Data 1808 92E4
Data 2020 A557 Data 2020 916C
SR 0000 SR 010C (DC, N, OV = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
ACCA 76 120F 098A ACCA 52 1EFC 4D73
ACCB 23 F312 BC17 ACCB 23 F312 BC17
CORCON 0000 CORCON 0000
SR 0000 SR 1100 (OA, OB = 1)
Before After
Instruction Instruction
ACCA FF 9022 2EE1 ACCA FF 9022 2EE1
ACCB 00 2456 8F4C ACCB 00 7FFF FFFF
CORCON 0040 CORCON 0040
SR 0000 SR 1400 (SB, SAB = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: SUBB.B 0x1FFF ; Sub. WREG and C from (0x1FFF) (Byte mode)
; Store result to 0x1FFF
Before After
Instruction Instruction
WREG (W0) 7804 WREG (W0) 7804
Data 1FFE 9439 Data 1FFE 8F39
SR 0000 SR 0011 (DC, C = 1)
Example 2: SUBB 0xA04, WREG ; Sub. WREG and C from (0xA04) (Word mode)
; Store result to WREG
5
Before After
Instruction Instruction
Descriptions
Before After
Instruction Instruction
W0 7804 W0 78E0
SR 0000 SR 0108 (DC, N = 1)
Example 2: SUBB #0x108, W4 ; Sub. 0x108 and C from W4 (Word mode)
; Store result to W4
Before After
Instruction Instruction
W4 6234 W4 612C
SR 0001 (C = 1) SR 0001 (C = 1)
Example 1: SUBB.B W4, #0x10, W5 ; Sub. 0x10 and C from W4 (Byte mode)
; Store result to W5
Before After
Instruction Instruction
W4 1782 W4 1782
W5
SR
7804
0000
W5
SR
7871
0005 (OV, C = 1)
5
Descriptions
Instruction
Example 2: SUBB W0, #0x8, [W2++] ; Sub. 0x8 and C from W0 (Word mode)
; Store result to [W2]
; Post-increment W2
Before After
Instruction Instruction
W0 0009 W0 0009
W2 2004 W2 2006
Data 2004 A557 Data 2004 0000
SR 0002 (Z = 1) SR 0103 (DC, Z, C = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
W0 1732 W0 17ED
W1 7844 W1 7844
SR 0000 SR 0108 (DC, N = 1)
Before After
Instruction Instruction
W7 2450 W7 2450
W8 1808 W8 180A
W9 2022 W9 2024
Data 1808 92E4 Data 1808 92E4
Data 2022 A557 Data 2022 916B
SR 0000 SR 010C (DC, N, OV = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: SUBBR.B 0x803 ; Sub. (0x803) and C from WREG (Byte mode)
; Store result to 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 After 5
Instruction Instruction
WREG (W0) 6234 WREG (W0) FFFE
Descriptions
SR 0000 SR 0008 (N = 1)
Example 1: SUBBR.B W0, #0x10, W1 ; Sub. W0 and C from 0x10 (Byte mode)
; Store result to W1
Before After
Instruction Instruction
W0 F310 W0 F310
W1 786A W1 7800
SR 0003 (Z, C = 1) SR 0103 (DC, Z, C = 1)
Example 2: SUBBR W0, #0x8, [W2++] ; Sub. W0 and C from 0x8 (Word mode)
; Store result to [W2]
; Post-increment W2
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
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W0 1732 W0 1711
W1 7844 W1 7844
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
W7 2450 W7 2450
W8 1808 W8 180A
W9 2022 W9 2024
Data 1808 92E4 Data 1808 92E4
Data 2022 A557 Data 2022 6E93
SR 0000 SR 0005 (OV, C = 1)
5
Descriptions
Instruction
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG (W0) 7804 WREG (W0) 7804
Data 1FFE 9439 Data 1FFE 7039
SR 0000 SR 0000
Example 2: SUBR 0xA04, WREG ; Sub. (0xA04) from WREG (Word mode)
; Store result to WREG
Before After
Instruction Instruction
WREG (W0) 6234 WREG (W0) FFFF
Data 0A04 6235 Data 0A04 6235
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
W0 F310 W0 F310
W1 786A W1 7800
SR 0000 SR 0103 (DC, Z, C = 1)
Example 2: SUBR W0, #0x8, [W2++] ; Sub. W0 from 0x8 (Word mode)
; Store result to [W2]
; Post-increment W2 5
Before After
Descriptions
Instruction Instruction
Instruction
W0 0009 W0 0009
W2 2004 W2 2006
Data 2004 A557 Data 2004 FFFF
SR 0000 SR 0108 (DC, N = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W0 1732 W0 1712
W1 7844 W1 7844
SR 0000 SR 0001 (C = 1)
Example 2: SUBR W7, [W8++], [W9++] ; Sub. W7 from [W8] (Word mode)
; Store result to [W9]
; Post-increment W8
; Post-increment W9
Before After
Instruction Instruction
W7 2450 W7 2450
W8 1808 W8 180A
W9 2022 W9 2024
Data 1808 92E4 Data 1808 92E4
Data 2022 A557 Data 2022 6E94
SR 0000 SR 0005 (OV, C = 1)
5
Descriptions
Instruction
Before After
Instruction Instruction
W0 AB87 W0 AB78
SR 0000 SR 0000
Before After
Instruction Instruction
W0 8095 W0 9580
SR 0000 SR 0000
Words: 1
Cycles: 2 (PIC24F, PIC24H, dsPIC30F, dsPIC33F)
5 (PIC24E, dsPIC33E)
Before After
Instruction Instruction
W0 0812 W0 0812
W1 0F71 W1 0F72
Data 0F70 0944 Data 0F70 EF44
Program 01 0812 EF 2042 Program 01 0812 EF 2042
TBLPAG 0001 TBLPAG 0001
SR 0000 SR 0000
Before After
Instruction Instruction
W6 3406 W6 3408
W8 65B1 W8 0029
Program 00 3406 29 2E40 Program 00 3406 29 2E40
TBLPAG 0000 TBLPAG 0000
SR 0000 SR 0000
Before After
Instruction Instruction
W0 0813 W0 0814
W1 0F71 W1 0F20
Data 0F70 0944 Data 0F70 EF44
Program 01 0812 EF 2042 Program 01 0812 EF 2042
TBLPAG 0001 TBLPAG 0001
SR 0000 SR 0000
Before After
Instruction Instruction
W6 3406 W6 3406
W8 1202 W8 1204
Data 1202 658B Data 1202 2E40
Program 00 3406 29 2E40 Program 00 3406 29 2E40
TBLPAG 0000 TBLPAG 0000
SR 0000 SR 0000
Before After
Instruction Instruction
W0 0812 W0 0814
W1 0F70 W1 0F70
Data 0812 0944 Data 0812 EF44
Program 01 0F70 EF 2042 Program 01 0F70 44 2042
TBLPAG 0001 TBLPAG 0001
SR 0000 SR 0000
Note: 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.
Before After
Instruction Instruction
W6 0026 W6 0026
W8 0870 W8 0872
Program 00 0870 22 3551 Program 00 0870 26 3551
TBLPAG 0000 TBLPAG 0000
SR 0000 SR 0000
Note: 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.
Before After
Instruction Instruction
W0 6628 W0 6628
W1 1225 W1 1226
Program 00 1224 78 0080 Program 01 1224 78 2880
TBLPAG 0000 TBLPAG 0000
SR 0000 SR 0000
Note: 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.
Before After
Instruction Instruction
W6 1600 W6 1600
W8 7208 W8 7208
Data 1600 0130 Data 1600 0130
Program 01 7208 09 0002 Program 01 7208 09 0130
TBLPAG 0001 TBLPAG 0001
SR 0000 SR 0000
Note: 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.
Operands: None
Operation: W14 →W15
(W15) – 2 →W15
(TOS) →W14
Status Affected: None
Encoding: 1111 1010 1000 0000 0000 0000
Description: This instruction de-allocates a Stack Frame for a subroutine calling
sequence. The Stack Frame is de-allocated by setting the Stack Pointer
(W15) equal to the Frame Pointer (W14), and then POPping the stack
to reset the Frame Pointer (W14).
Words: 1
Cycles: 1
Before After
Instruction Instruction
W14 2002 W14 2000
W15 20A2 W15 2000
Data 2000 2000 Data 2000 2000
SR 0000 SR 0000
Before After
Instruction Instruction
W14 0802 W14 0800
W15 0812 W15 0800
Data 0800 0800 Data 0800 0800
SR 0000 SR 0000
5
Descriptions
Instruction
Operands: None
Operation: W14 →W15
(W15) – 2 →W15
(TOS) →W14
0 →SFA bit
Status Affected: SFA
Encoding: 1111 1010 1000 0000 0000 0000
Description: This instruction de-allocates a Stack Frame for a subroutine calling
sequence. The Stack Frame is de-allocated by setting the Stack Pointer
(W15) equal to the Frame Pointer (W14), and then POPping the stack
to reset the Frame Pointer (W14).
Words: 1
Cycles: 1
Before After
Instruction Instruction
W14 2002 W14 2000
W15 20A2 W15 2000
Data 2000 2000 Data 2000 2000
SR 0000 SR 0000
Before After
Instruction Instruction
W14 0802 W14 0800
W15 0812 W15 0800
Data 0800 0800 Data 0800 0800
SR 0000 SR 0000
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
WREG (W0) 7804 WREG (W0) 7804
Data 1FFE 9439 Data 1FFE 9039
SR 0000 SR 0008 (N = 1)
Example 2: XOR 0xA04, WREG ; XOR (0xA04) and WREG (Word mode)
; Store result to WREG
Before
Instruction
After
Instruction
5
WREG (W0) 6234 WREG (W0) C267
Descriptions
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
W0 7804 W0 7827
SR 0000 SR 0000
Example 2: XOR #0x108, W4 ; XOR 0x108 and W4 (Word mode)
; Store result to W4
Before After
Instruction Instruction
W4 6134 W4 603C
SR 0000 SR 0000
Before After
Instruction Instruction
W4 C822 W4 C822
W5 1200 W5 1234
SR 0000 SR 0000
Example 2: XOR W2, #0x1F, [W8++] ; XOR W2 by 0x1F (Word mode)
; Store result to [W8]
; Post-increment W8
5
Before After
Descriptions
Instruction
Instruction Instruction
W2 8505 W2 8505
W8 1004 W8 1006
Data 1004 6628 Data 1004 851A
SR 0000 SR 0008 (N = 1)
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Example 1: XOR.B W1, [W5++], [W9++] ; XOR W1 and [W5] (Byte mode)
; Store result to [W9]
; Post-increment W5 and W9
Before After
Instruction Instruction
W1 AAAA W1 AAAA
W5 2000 W5 2001
W9 2600 W9 2601
Data 2000 115A Data 2000 115A
Data 2600 0000 Data 2600 00F0
SR 0000 SR 0008 (N = 1)
Before After
Instruction Instruction
W1 FEDC W1 FEDC
W5 1234 W5 1234
W9 A34D W9 ECE8
SR 0000 SR 0008 (N = 1)
5
Descriptions
Instruction
ZE Zero-Extend Ws
Note 1: In dsPIC33E and PIC24E devices, the listed cycle count does not apply to read and
read-modify-write operations on non-CPU Special Function Registers. For more
details, see Note 3 in Section 3.2.1 “Multi-Cycle Instructions”.
Before After
Instruction Instruction
W3 7839 W3 7839
W4 1005 W4 0039
SR 0000 SR 0001 (C = 1)
Before After
Instruction Instruction
W2 0900 W2 0901
W12 1002 W12 008F
Data 0900 268F Data 0900 268F
SR 0000 SR 0001 (C = 1)
5
Descriptions
Instruction
NOTES:
Built-in Functions
Section 6. Built-in Functions
HIGHLIGHTS
This section of the manual contains the following major topics:
6.1 INTRODUCTION
This section describes the built-in functions that are specific to the MPLAB C Compiler for PIC24
MCUs and dsPIC DSCs (formerly MPLAB C30).
Built-in functions give the C programmer access to assembler operators or machine instructions
that are currently only accessible using in-line assembly, but are sufficiently useful that they are
applicable to a broad range of applications. Built-in functions are coded in C source files
syntactically like function calls, but they are compiled to assembly code that directly implements
the function, and do not involve function calls or library routines.
There are a number of reasons why providing built-in functions is preferable to requiring
programmers to use in-line assembly. They include the following:
1. Providing built-in functions for specific purposes simplifies coding.
2. Certain optimizations are disabled when in-line assembly is used. This is not the case for
built-in functions.
3. For machine instructions that use dedicated registers, coding in-line assembly while
avoiding register allocation errors can require considerable care. The built-in functions
make this process simpler as you do not need to be concerned with the particular register
requirements for each individual machine instruction.
The built-in functions are listed below followed by their individual detailed descriptions.
• __builtin_addab • __builtin_mpyn
• __builtin_add • __builtin_msc
• __builtin_btg • __builtin_mulss
• __builtin_clr • __builtin_mulsu
• __builtin_clr_prefetch • __builtin_mulus
• __builtin_divf • __builtin_muluu
• __builtin_divmodsd • __builtin_nop
• __builtin_divmodud • __builtin_psvpage
• __builtin_divsd • __builtin_psvoffset
• __builtin_divud • __builtin_readsfr
• __builtin_dmaoffset • __builtin_return_address
• __builtin_ed • __builtin_sac
• __builtin_edac • __builtin_sacr
• __builtin_edsoffset • __builtin_sftac
• __builtin_edspage • __builtin_subab
• __builtin_fbcl • __builtin_tbladdress
• __builtin_lac • __builtin_tblpage
• __builtin_mac • __builtin_tbloffset
• __builtin_modsd • __builtin_tblrdh
• __builtin_modud • __builtin_tblrdl
• __builtin_movsac • __builtin_tblwth
• __builtin_mpy • __builtin_tblwtl
This section describes only the built-in functions related to the CPU operations. The compiler
provides additional built-in functions for operations such as writing to Flash program memory and
changing the oscillator settings. Refer to the “MPLAB® C Compiler for PIC24 MCUs and dsPIC®
DSCs User’s Guide” (DS51284) for a complete list of compiler built-in functions.
Built-in Functions
This section describes the programmer interface to the compiler built-in functions. Since the
functions are “built-in”, there are no header files associated with them. Similarly, there are no
command-line switches associated with the built-in functions – they are always available. The
built-in function names are chosen such that they belong to the compiler’s namespace (they all
have the prefix __builtin_), so they will not conflict with function or variable names in the
programmer’s namespace.
__builtin_addab
Description:
Add accumulators A and B with the result written back to the specified accumulator. For
example:
register int result asm("A");
register int B asm("A");
result = __builtin_addab(result,B);
will generate:
add A
Prototype:
int __builtin_addab(int Accum_a, int Accum_b);
Argument:
Accum_a First accumulator to add.
Accum_b Second accumulator to add.
Return Value:
Returns the addition result to an accumulator.
Assembler Operator / Machine Instruction:
add
Error Messages:
An error message appears if the result is not an accumulator register.
__builtin_add
Description:
Add value to the accumulator specified by result with a shift specified by literal shift. For
example:
register int result asm("A");
int value;
result = __builtin_add(result,value,0);
If value is held in w0, the following will be generated:
add w0, #0, A
Prototype:
int __builtin_add(int Accum,int value,
const int shift);
Argument:
Accum Accumulator to add.
value Integer number to add to accumulator value.
shift Amount to shift resultant accumulator value.
Return Value:
Returns the shifted addition result to an accumulator.
Assembler Operator / Machine Instruction:
add
Error Messages:
An error message appears if:
• the result is not an accumulator register
• argument 0 is not an accumulator
• the shift value is not a literal within range
Built-in Functions
__builtin_btg
Description:
This function will generate a btg machine instruction. Some examples include:
int i; /* near by default */
int l _ _attribute_ _((far));
struct foo {
int bit1:1;
} barbits;
int bar;
void some_bittoggles() {
register int j asm("w9");
int k;
k = i;
_ _builtin_btg(&i,1);
_ _builtin_btg(&j,3);
_ _builtin_btg(&k,4);
_ _builtin_btg(&l,11);
return j+k;
}
Note that taking the address of a variable in a register will produce warning by the compiler and
cause the register to be saved onto the stack (so that its address may be taken); this form is
not recommended. This caution only applies to variables explicitly placed in registers by the
programmer.
Prototype:
void _ _builtin_btg(unsigned int *, unsigned int 0xn);
Argument:
* A pointer to the data item for which a bit should be toggled.
0xn A literal value in the range of 0 to 15.
Return Value:
Returns a btg machine instruction.
Assembler Operator / Machine Instruction:
btg
Error Messages:
An error message appears if the parameter values are not within range.
__builtin_clr
Description:
Clear the specified accumulator. For example:
register int result asm("A");
result = _ _builtin_clr();
will generate:
clr A
Prototype:
int _ _builtin_clr(void);
Argument:
None
Return Value:
Returns the cleared value result to an accumulator.
Assembler Operator / Machine Instruction:
clr
Error Messages:
An error message appears if the result is not an accumulator register.
Built-in Functions
__builtin_clr_prefetch
Description:
Clear an accumulator and prefetch data ready for a future MAC operation.
xptr may be null to signify no X prefetch to be performed, in which case the values of xincr
and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which case the values of yincr
and yval are ignored, but required.
xval and yval nominate the address of a C variable where the prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an integer value.
If AWB is non null, the other accumulator will be written back into the referenced variable.
For example:
register int result asm("A");
register int B asm("B");
int x_memory_buffer[256]
_ _attribute_ _((space(xmemory)));
int y_memory_buffer[256]
_ _attribute_ _((space(ymemory)));
int *xmemory;
int *ymemory;
int awb;
int xVal, yVal;
xmemory = x_memory_buffer;
ymemory = y_memory_buffer;
result = _ _builtin_clr(&xmemory, &xVal, 2,
&ymemory, &yVal, 2, &awb, B);
May generate:
clr A, [w8]+=2, w4, [w10]+=2, w5, w13
The compiler may need to spill w13 to ensure that it is available for the write-back. It may be
recommended to users that the register be claimed for this purpose.
After this instruction:
• result will be cleared
• xVal will contain x_memory_buffer[0]
• yVal will contain y_memory_buffer[0]
• xmemory and ymemory will be incremented by 2, ready for the next mac operation
Prototype:
int _ _builtin_clr_prefetch(
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr, int *AWB,
int AWB_accum);
__builtin_clr_prefetch (Continued)
Argument:
xptr Integer pointer to x prefetch.
xval Integer value of x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to y prefetch.
yval Integer value of y prefetch.
yincr Integer increment value of y prefetch.
AWB Accumulator write back location.
AWB_accum Accumulator to write back.
Note: The arguments xptr and yptr must point to the arrays located in the x data
memory and y data memory, respectively.
Return Value:
Returns the cleared value result to an accumulator.
Assembler Operator / Machine Instruction:
clr
Error Messages:
An error message appears if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
• AWB_accum is not an accumulator and AWB is not null
Built-in Functions
__builtin_divf
Description:
Computes the quotient num / den. A math error exception occurs if den is zero. Function
arguments are unsigned, as is the function result.
Prototype:
unsigned int _ _builtin_divf(unsigned int num,
unsigned int den);
Argument:
num numerator
den denominator
Return Value:
Returns the unsigned integer value of the quotient num / den.
Assembler Operator / Machine Instruction:
div.f
__builtin_divmodsd
Description:
Issues the 16-bit architecture’s native signed divide support. Notably, if the quotient does not fit
into a 16-bit result, the results (including remainder) are unexpected. This form of the built-in
function will capture both the quotient and remainder.
Prototype:
signed int _ _builtin_divmodsd(
signed long dividend, signed int divisor,
signed int *remainder);
Argument:
dividend number to be divided
divisor number to divide by
remainder pointer to remainder
Return Value:
Quotient and remainder.
Assembler Operator / Machine Instruction:
divmodsd
Error Messages:
None.
__builtin_divmodud
Description:
Issues the 16-bit architecture’s native unsigned divide support. Notably, if the quotient does not
fit into a 16-bit result, the results (including remainder) are unexpected. This form of the built-in
function will capture both the quotient and remainder.
Prototype:
unsigned int _ _builtin_divmodud(
unsigned long dividend, unsigned int divisor,
unsigned int *remainder);
Argument:
dividend number to be divided
divisor number to divide by
remainder pointer to remainder
Return Value:
Quotient and remainder.
Assembler Operator / Machine Instruction:
divmodud
Error Messages:
None.
__builtin_divsd
Description:
Computes the quotient num / den. A math error exception occurs if den is zero. Function
arguments are signed, as is the function result. The command-line option -Wconversions
can be used to detect unexpected sign conversions.
Prototype:
int _ _builtin_divsd(const long num, const int den);
Argument:
num numerator
den denominator
Return Value:
Returns the signed integer value of the quotient num / den.
Assembler Operator / Machine Instruction:
div.sd
Built-in Functions
__builtin_divud
Description:
Computes the quotient num / den. A math error exception occurs if den is zero. Function
arguments are unsigned, as is the function result. The command-line option -Wconversions
can be used to detect unexpected sign conversions.
Prototype:
unsigned int _ _builtin_divud(const unsigned
long num, const unsigned int den);
Argument:
num numerator
den denominator
Return Value:
Returns the unsigned integer value of the quotient num / den.
Assembler Operator / Machine Instruction:
div.ud
__builtin_dmaoffset
Description:
Obtains the offset of a symbol within DMA memory.
For example:
unsigned int result;
char buffer[256] _ _attribute_ _((space(dma)));
result = _ _builtin_dmaoffset(&buffer);
May generate:
mov #dmaoffset(buffer), w0
Prototype:
unsigned int _ _builtin_dmaoffset(const void *p);
Argument:
*p pointer to DMA address value
Return Value:
Returns the offset to a variable located in DMA memory.
Assembler Operator / Machine Instruction:
dmaoffset
Error Messages:
An error message appears if the parameter is not the address of a global symbol.
__builtin_ed
Description:
Squares sqr, returning it as the result. Also prefetches data for future square operation by
computing **xptr - **yptr and storing the result in *distance.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an integer value.
For example:
register int result asm("A");
int *xmemory, *ymemory;
int distance;
result = _ _builtin_ed(distance,
&xmemory, 2,
&ymemory, 2,
&distance);
May generate:
ed w4*w4, A, [w8]+=2, [W10]+=2, w4
Prototype:
int _ _builtin_ed(int sqr, int **xptr, int xincr,
int **yptr, int yincr, int *distance);
Argument:
sqr Integer squared value.
xptr Integer pointer to pointer to x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yincr Integer increment value of y prefetch.
distance Integer pointer to distance.
Note: The arguments xptr and yptr must point to the arrays located in the x data
memory and y data memory, respectively.
Return Value:
Returns the squared result to an accumulator.
Assembler Operator / Machine Instruction:
ed
Error Messages:
An error message appears if:
• the result is not an accumulator register
• xptr is null
• yptr is null
• distance is null
Built-in Functions
__builtin_edac
Description:
Squares sqr and sums with the nominated accumulator register, returning it as the result. Also
prefetches data for future square operation by computing **xptr - **yptr and storing the
result in *distance.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an integer value.
For example:
register int result asm("A");
int *xmemory, *ymemory;
int distance;
May generate:
edac w4*w4, A, [w8]+=2, [W10]+=2, w4
Prototype:
int _ _builtin_edac(int Accum, int sqr,
int **xptr, int xincr, int **yptr, int yincr,
int *distance);
Argument:
Accum Accumulator to sum.
sqr Integer squared value.
xptr Integer pointer to pointer to x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yincr Integer increment value of y prefetch.
distance Integer pointer to distance.
Note: The arguments xptr and yptr must point to the arrays located in the x data
memory and y data memory, respectively.
Return Value:
Returns the squared result to specified accumulator.
Assembler Operator / Machine Instruction:
edac
Error Messages:
An error message appears if:
• the result is not an accumulator register
• Accum is not an accumulator register
• xptr is null
• yptr is null
• distance is null
__builtin_edsoffset
Description:
Returns the eds page offset of the object whose address is given as a parameter. The argument
p must be the address of an object in extended data space; otherwise an error message is
produced and the compilation fails. See the space attribute in Section 2.3.1 “Specifying
Attributes of Variables” of the “MPLAB® C Compiler for PIC24 MCUs and dsPIC® DSCs
User’s Guide” (DS51284).
Prototype:
unsigned int __builtin_edsoffset(int *p);
Argument:
p object address
Return Value:
Returns the eds page number of the object whose address is given as a parameter
Assembler Operator / Machine Instruction:
edsoffset
__builtin_edspage
Description:
Returns the eds page number of the object whose address is given as a parameter. The
argument p must be the address of an object in extended data space; otherwise an error
message is produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables” of the “MPLAB® C Compiler for PIC24
MCUs and dsPIC® DSCs User’s Guide” (DS51284).
Prototype:
unsigned int __builtin_edspage(int *p);
Argument:
p object address
Return Value:
Returns the eds page number of the object whose address is given as a parameter.
Assembler Operator / Machine Instruction:
edspage
Built-in Functions
__builtin_fbcl
Description:
Finds the first bit change from left in value. This is useful for dynamic scaling of fixed-point data.
For example:
int result, value;
result = _ _builtin_fbcl(value);
May generate:
fbcl w4, w5
Prototype:
int _ _builtin_fbcl(int value);
Argument:
value Integer number of first bit change.
Return Value:
Returns the shifted addition result to an accumulator.
Assembler Operator / Machine Instruction:
fbcl
Error Messages:
An error message appears if the result is not an accumulator register.
__builtin_lac
Description:
Shifts value by shift (a literal between -8 and 7) and returns the value to be stored into the
accumulator register. For example:
register int result asm("A");
int value;
result = _ _builtin_lac(value,3);
May generate:
lac w4, #3, A
Prototype:
int _ _builtin_lac(int value, int shift);
Argument:
value Integer number to be shifted.
shift Literal amount to shift.
Return Value:
Returns the shifted addition result to an accumulator.
Assembler Operator / Machine Instruction:
lac
Error Messages:
An error message appears if:
• the result is not an accumulator register
• the shift value is not a literal within range
__builtin_mac
Description:
Computes a x b and sums with accumulator; also prefetches data ready for a future MAC
operation.
xptr may be null to signify no X prefetch to be performed, in which case the values of xincr
and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which case the values of yincr
and yval are ignored, but required.
xval and yval nominate the address of a C variable where the prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an integer value.
If AWB is non null, the other accumulator will be written back into the referenced variable.
For example:
register int result asm("A");
register int B asm("B");
int *xmemory;
int *ymemory;
int xVal, yVal;
May generate:
mac w4*w5, A, [w8]+=2, w4, [w10]+=2, w5
Prototype:
int _ _builtin_mac(int Accum, int a, int b,
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr, int *AWB,
int AWB_accum);
Argument:
Accum Accumulator to sum.
a Integer multiplicand.
b Integer multiplier.
xptr Integer pointer to pointer to x prefetch.
xval Integer pointer to value of x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yval Integer pointer to value of y prefetch.
yincr Integer increment value of y prefetch.
AWB Accumulator write-back location.
AWB_accum Accumulator to write-back.
Note: The arguments xptr and yptr must point to the arrays located in the x data
memory and y data memory, respectively.
Return Value:
Returns the cleared value result to an accumulator.
Assembler Operator / Machine Instruction:
mac
Built-in Functions
__builtin_mac (Continued)
Error Messages:
An error message appears if:
• the result is not an accumulator register
• Accum is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
• AWB_accum is not an accumulator register and AWB is not null
__builtin_modsd
Description:
Issues the 16-bit architecture’s native signed divide support. Notably, if the quotient does not fit
into a 16-bit result, the results (including remainder) are unexpected. This form of the built-in
function will capture only the remainder.
Prototype:
signed int _ _builtin_modsd(signed long dividend,
signed int divisor);
Argument:
dividend number to be divided
divisor number to divide by
Return Value:
Remainder.
Assembler Operator / Machine Instruction:
modsd
Error Messages:
None.
__builtin_modud
Description:
Issues the 16-bit architecture’s native unsigned divide support. Notably, if the quotient does not
fit into a 16-bit result, the results (including remainder) are unexpected. This form of the built-in
function will capture only the remainder.
Prototype:
unsigned int _ _builtin_modud(unsigned long dividend,
unsigned int divisor);
Argument:
dividend number to be divided
divisor number to divide by
Return Value:
Remainder.
Assembler Operator / Machine Instruction:
modud
Error Messages:
None.
Built-in Functions
__builtin_movsac
Description:
Computes nothing, but prefetches data ready for a future MAC operation.
xptr may be null to signify no X prefetch to be performed, in which case the values of xincr
and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which case the values of yincr
and yval are ignored, but required.
xval and yval nominate the address of a C variable where the prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an integer value.
If AWB is not null, the other accumulator will be written back into the referenced variable.
For example:
register int result asm("A");
int *xmemory;
int *ymemory;
int xVal, yVal;
May generate:
movsac A, [w8]+=2, w4, [w10]+=2, w5
Prototype:
int _ _builtin_movsac(
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr, int *AWB
int AWB_accum);
Argument:
xptr Integer pointer to pointer to x prefetch.
xval Integer pointer to value of x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yval Integer pointer to value of y prefetch.
yincr Integer increment value of y prefetch.
AWB Accumulator write back location.
AWB_accum Accumulator to write back.
Note: The arguments xptr and yptr must point to the arrays located in the x data
memory and y data memory, respectively.
Return Value:
Returns prefetch data.
Assembler Operator / Machine Instruction:
movsac
Error Messages:
An error message appears if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
• AWB_accum is not an accumulator register and AWB is not null
__builtin_mpy
Description:
Computes a x b ; also prefetches data ready for a future MAC operation.
xptr may be null to signify no X prefetch to be performed, in which case the values of xincr
and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which case the values of yincr
and yval are ignored, but required.
xval and yval nominate the address of a C variable where the prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an integer value.
For example:
register int result asm("A");
int *xmemory;
int *ymemory;
int xVal, yVal;
May generate:
mac w4*w5, A, [w8]+=2, w4, [w10]+=2, w5
Prototype:
int _ _builtin_mpy(int a, int b,
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr);
Argument:
a Integer multiplicand.
b Integer multiplier.
xptr Integer pointer to pointer to x prefetch.
xval Integer pointer to value of x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yval Integer pointer to value of y prefetch.
yincr Integer increment value of y prefetch.
AWB Integer pointer to accumulator selection.
Note: The arguments xptr and yptr must point to the arrays located in the x data
memory and y data memory, respectively.
Return Value:
Returns the cleared value result to an accumulator.
Assembler Operator / Machine Instruction:
mpy
Error Messages:
An error message appears if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
Built-in Functions
__builtin_mpyn
Description:
Computes -a x b ; also prefetches data ready for a future MAC operation.
xptr may be null to signify no X prefetch to be performed, in which case the values of xincr
and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which case the values of yincr
and yval are ignored, but required.
xval and yval nominate the address of a C variable where the prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an integer value.
For example:
register int result asm("A");
int *xmemory;
int *ymemory;
int xVal, yVal;
May generate:
mac w4*w5, A, [w8]+=2, w4, [w10]+=2, w5
Prototype:
int _ _builtin_mpyn(int a, int b,
int **xptr, int *xval, int xincr,
int **yptr, int *yval, int yincr);
Argument:
a Integer multiplicand.
b Integer multiplier.
xptr Integer pointer to pointer to x prefetch.
xval Integer pointer to value of x prefetch.
xincr Integer increment value of x prefetch.
yptr Integer pointer to pointer to y prefetch.
yval Integer pointer to value of y prefetch.
yincr Integer increment value of y prefetch.
AWB Integer pointer to accumulator selection.
Note: The arguments xptr and yptr must point to the arrays located in the x data
memory and y data memory, respectively.
Return Value:
Returns the cleared value result to an accumulator.
Assembler Operator / Machine Instruction:
mpyn
Error Messages:
An error message appears if:
• the result is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
__builtin_msc
Description:
Computes a x b and subtracts from accumulator; also prefetches data ready for a future MAC
operation.
xptr may be null to signify no X prefetch to be performed, in which case the values of xincr
and xval are ignored, but required.
yptr may be null to signify no Y prefetch to be performed, in which case the values of yincr
and yval are ignored, but required.
xval and yval nominate the address of a C variable where the prefetched value will be stored.
xincr and yincr may be the literal values: -6, -4, -2, 0, 2, 4, 6 or an integer value.
If AWB is non null, the other accumulator will be written back into the referenced variable.
For example:
register int result asm("A");
int *xmemory;
int *ymemory;
int xVal, yVal;
Note: The arguments xptr and yptr must point to the arrays located in the x data
memory and y data memory, respectively.
Return Value:
Returns the cleared value result to an accumulator.
Assembler Operator / Machine Instruction:
msc
Built-in Functions
__builtin_msc (Continued)
Error Messages:
An error message appears if:
• the result is not an accumulator register
• Accum is not an accumulator register
• xval is a null value but xptr is not null
• yval is a null value but yptr is not null
• AWB_accum is not an accumulator register and AWB is not null
__builtin_mulss
Description:
Computes the product p0 x p1. Function arguments are signed integers, and the function result
is a signed long integer. The command-line option -Wconversions can be used to detect
unexpected sign conversions.
Prototype:
signed long __builtin_mulss(const signed int p0, const signed int p1);
Argument:
p0 multiplicand
p1 multiplier
Return Value:
Returns the signed long integer value of the product p0 x p1.
Assembler Operator / Machine Instruction:
mul.ss
__builtin_mulsu
Description:
Computes the product p0 x p1. Function arguments are integers with mixed signs, and the
function result is a signed long integer. The command-line option -Wconversions can be
used to detect unexpected sign conversions. This function supports the full range of addressing
modes of the instruction, including immediate mode for operand p1.
Prototype:
signed long __builtin_mulsu(const signed int p0, const unsigned int p1);
Argument:
p0 multiplicand
p1 multiplier
Return Value:
Returns the signed long integer value of the product p0 x p1.
Assembler Operator / Machine Instruction:
mul.su
Built-in Functions
__builtin_mulus
Description:
Computes the product p0 x p1. Function arguments are integers with mixed signs, and the
function result is a signed long integer. The command-line option -Wconversions can be
used to detect unexpected sign conversions. This function supports the full range of addressing
modes of the instruction.
Prototype:
signed long __builtin_mulus(const unsigned int p0, const signed int p1);
Argument:
p0 multiplicand
p1 multiplier
Return Value:
Returns the signed long integer value of the product p0 x p1.
Assembler Operator / Machine Instruction:
mul.us
__builtin_muluu
Description:
Computes the product p0 x p1. Function arguments are unsigned integers, and the function
result is an unsigned long integer. The command-line option -Wconversions can be used to
detect unexpected sign conversions. This function supports the full range of addressing modes
of the instruction, including immediate mode for operand p1.
Prototype:
unsigned long __builtin_muluu(const unsigned int p0, const unsigned int p1);
Argument:
p0 multiplicand
p1 multiplier
Return Value:
Returns the signed long integer value of the product p0 x p1.
Assembler Operator / Machine Instruction:
mul.uu
__builtin_nop
Description:
Generates a nop instruction.
Prototype:
void _ _builtin_nop(void);
Argument:
None.
Return Value:
Returns a no operation (nop).
Assembler Operator / Machine Instruction:
nop
__builtin_psvoffset
Description:
Returns the psv page offset of the object whose address is given as a parameter. The argument
p must be the address of an object in an EE data, PSV or executable memory space; otherwise
an error message is produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables” of the “MPLAB® C Compiler for PIC24
MCUs and dsPIC® DSCs User’s Guide” (DS51284).
Prototype:
unsigned int _ _builtin_psvoffset(const void *p);
Argument:
p object address
Return Value:
Returns the psv page number offset of the object whose address is given as a parameter.
Assembler Operator / Machine Instruction:
psvoffset
Error Messages:
The following error message is produced when this function is used incorrectly:
“Argument to _ _builtin_psvoffset() is not the address of an object in code, psv, or
eedata section”.
The argument must be an explicit object address.
For example, if obj is object in an executable or read-only section, the following syntax is valid:
unsigned page = _ _builtin_psvoffset(&obj);
Built-in Functions
__builtin_psvpage
Description:
Returns the psv page number of the object whose address is given as a parameter. The
argument p must be the address of an object in an EE data, PSV or executable memory space;
otherwise an error message is produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables” of the “MPLAB® C Compiler for PIC24
MCUs and dsPIC® DSCs User’s Guide” (DS51284).
Prototype:
unsigned int _ _builtin_psvpage(const void *p);
Argument:
p object address
Return Value:
Returns the psv page number of the object whose address is given as a parameter.
Assembler Operator / Machine Instruction:
psvpage
Error Messages:
The following error message is produced when this function is used incorrectly:
“Argument to _ _builtin_psvpage() is not the address of an object in code, psv, or eedata
section”.
The argument must be an explicit object address.
For example, if obj is object in an executable or read-only section, the following syntax is valid:
unsigned page = _ _builtin_psvpage(&obj);
__builtin_readsfr
Description:
Reads the SFR.
Prototype:
unsigned int _ _builtin_readsfr(const void *p);
Argument:
p object address
Return Value:
Returns the SFR.
Assembler Operator / Machine Instruction:
readsfr
Error Messages:
The following error message is produced when this function is used incorrectly:
__builtin_return_address
Description:
Returns the return address of the current function, or of one of its callers. For the level
argument, a value of 0 yields the return address of the current function, a value of 1 yields the
return address of the caller of the current function, and so forth. When level exceeds the current
stack depth, 0 will be returned. This function should only be used with a non-zero argument for
debugging purposes.
Prototype:
int _ _builtin_return_address (const int level);
Argument:
level Number of frames to scan up the call stack.
Return Value:
Returns the return address of the current function, or of one of its callers.
Assembler Operator / Machine Instruction:
return_address
__builtin_sac
Description:
Shifts value by shift (a literal between -8 and 7) and returns the value.
For example:
register int value asm("A");
int result;
result = _ _builtin_sac(value,3);
May generate:
sac A, #3, w0
Prototype:
int _ _builtin_sac(int value, int shift);
Argument:
value Integer number to be shifted.
shift Literal amount to shift.
Return Value:
Returns the shifted result to an accumulator.
Assembler Operator / Machine Instruction:
sac
Error Messages:
An error message appears if:
• the result is not an accumulator register
• the shift value is not a literal within range
Built-in Functions
__builtin_sacr
Description:
Shifts value by shift (a literal between -8 and 7) and returns the value which is rounded using
the rounding mode determined by the CORCONbits.RND control bit.
For example:
register int value asm("A");
int result;
result = _ _builtin_sac(value,3);
May generate:
sac.r A, #3, w0
Prototype:
int _ _builtin_sacr(int value, int shift);
Argument:
value Integer number to be shifted.
shift Literal amount to shift.
Return Value:
Returns the shifted result to the CORCON register.
Assembler Operator / Machine Instruction:
sacr
Error Messages:
An error message appears if:
• the result is not an accumulator register
• the shift value is not a literal within range
__builtin_sftac
Description:
Shifts accumulator by shift. The valid shift range is -16 to 16.
For example:
register int result asm("A");
int i;
result = _ _builtin_sftac(result,i);
May generate:
sftac A, w0
Prototype:
int _ _builtin_sftac(int Accum, int shift);
Argument:
Accum Accumulator to shift.
shift Amount to shift.
Return Value:
Returns the shifted result to an accumulator.
Assembler Operator / Machine Instruction:
sftac
Error Messages:
An error message appears if:
• the result is not an accumulator register
• Accum is not an accumulator register
• the shift value is not a literal within range
Built-in Functions
__builtin_subab
Description:
Subtracts accumulators A and B with the result written back to the specified accumulator. For
example:
register int result asm("A");
register int B asm("B");
result = _ _builtin_subab(result,B);
will generate:
sub A
Prototype:
int _ ___builtin_subab(int Accum_a, int Accum_b);
Argument:
Accum_a Accumulator from which to subtract.
Accum_b Accumulator to subtract.
Return Value:
Returns the subtraction result to an accumulator.
Assembler Operator / Machine Instruction:
sub
Error Messages:
An error message appears if the result is not an accumulator register.
__builtin_tbladdress
Description:
Returns a value that represents the address of an object in program memory. The argument p
must be the address of an object in an EE data, PSV or executable memory space; otherwise
an error message is produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables” of the “MPLAB® C Compiler for PIC24
MCUs and dsPIC® DSCs User’s Guide” (DS51284).
Prototype:
unsigned long _ _builtin_tblpage(const void *p);
Argument:
p object address
Return Value:
Returns an unsigned long value that represents the address of an object in program
memory.
Assembler Operator / Machine Instruction:
tbladdress
__builtin_tbladdress
Error Messages:
The following error message is produced when this function is used incorrectly:
“Argument to _ _builtin_tbladdress() is not the address of an object in code, psv, or
eedata section”.
The argument must be an explicit object address.
For example, if obj is object in an executable or read-only section, the following syntax is valid:
unsigned long page = _ _builtin_tbladdress(&obj);
__builtin_tbloffset
Description:
Returns the table page offset of the object whose address is given as a parameter. The
argument p must be the address of an object in an EE data, PSV or executable memory space;
otherwise an error message is produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables” of the “MPLAB® C Compiler for PIC24
MCUs and dsPIC® DSCs User’s Guide” (DS51284).
Prototype:
unsigned int _ _builtin_tbloffset(const void *p);
Argument:
p object address
Return Value:
Returns the table page number offset of the object whose address is given as a parameter.
Assembler Operator / Machine Instruction:
tbloffset
Error Messages:
The following error message is produced when this function is used incorrectly:
“Argument to _ _builtin_tbloffset() is not the address of an object in code, psv, or
eedata section”.
The argument must be an explicit object address.
For example, if obj is object in an executable or read-only section, the following syntax is valid:
unsigned page = _ _builtin_tbloffset(&obj);
Built-in Functions
__builtin_tblpage
Description:
Returns the table page number of the object whose address is given as a parameter. The
argument p must be the address of an object in an EE data, PSV or executable memory space;
otherwise an error message is produced and the compilation fails. See the space attribute in
Section 2.3.1 “Specifying Attributes of Variables” of the “MPLAB® C Compiler for PIC24
MCUs and dsPIC® DSCs User’s Guide” (DS51284).
Prototype:
unsigned int _ _builtin_tblpage(const void *p);
Argument:
p object address
Return Value:
Returns the table page number of the object whose address is given as a parameter.
Assembler Operator / Machine Instruction:
tblpage
Error Messages:
The following error message is produced when this function is used incorrectly:
“Argument to _ _builtin_tblpage() is not the address of an object in code, psv, or eedata
section”.
The argument must be an explicit object address.
For example, if obj is object in an executable or read-only section, the following syntax is valid:
unsigned page = _ _builtin_tblpage(&obj);
__builtin_tblrdh
Description:
Issues the tblrdh.w instruction to read a word from Flash or EEDATA memory. You must set
up the TBLPAG to point to the appropriate page. To do this, you may make use of
_ _builtin_tbloffset() and _ _builtin_tblpage().
Please refer to the specific device data sheet or the appropriate family reference manual for
complete details regarding reading and writing program Flash.
Prototype:
unsigned int _ _builtin_tblrdh(unsigned int offset);
Argument:
offset desired memory offset
Return Value:
None.
Assembler Operator / Machine Instruction:
tblrdh
Error Messages:
None.
__builtin_tblrdl
Description:
Issues the tblrdl.w instruction to read a word from Flash or EEDATA memory. You must set
up the TBLPAG to point to the appropriate page. To do this, you may make use of
_ _builtin_tbloffset() and_ _builtin_tblpage().
Please refer to the specific device data sheet or the appropriate family reference manual for
complete details regarding reading and writing program Flash.
Prototype:
unsigned int _ _builtin_tblrdl(unsigned int offset);
Argument:
offset desired memory offset
Return Value:
None.
Assembler Operator / Machine Instruction:
tblrdl
Error Messages:
None.
__builtin_tblwth
Description:
Issues the tblwth.w instruction to write a word to Flash or EEDATA memory. You must set up
the TBLPAG to point to the appropriate page. To do this, you may make use of
_ _builtin_tbloffset() and _ _builtin_tblpage().
Please refer to the specific device data sheet or the appropriate family reference manual for
complete details regarding reading and writing program Flash.
Prototype:
void _ _builtin_tblwth(unsigned int offset
unsigned int data);
Argument:
offset desired memory offset
data data to be written
Return Value:
None.
Assembler Operator / Machine Instruction:
tblwth
Error Messages:
None.
Built-in Functions
__builtin_tblwtl
Description:
Issues the tblrdl.w instruction to write a word to Flash or EEDATA memory. You must set up
the TBLPAG to point to the appropriate page. To do this, you may make use of
_ _builtin_tbloffset() and _ _builtin_tblpage().
Please refer to the specific device data sheet or the appropriate family reference manual for
complete details regarding reading and writing program Flash.
Prototype:
void _ _builtin_tblwtl(unsigned int offset
unsigned int data);
Argument:
offset desired memory offset
data data to be written
Return Value:
None.
Assembler Operator / Machine Instruction:
tblwtl
Error Messages:
None.
// Enable 32-bit saturation, signed and fractional modes for both ACCA
and ACCB
CORCON = 0x00C0;
while(1);
}
Built-in Functions
#include <p33Fxxxx.h>
#include "divide.h"
_FOSCSEL(FNOSC_FRC);
_FOSC(FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMD_NONE);
_FWDT(FWDTEN_OFF);
int sign;
unsigned int result;
c.l = a;
sign = c.i[1] ^ b;
if (a < 0) a = (-a);
if (b < 0) b = -b;
result = __builtin_divud(a,b);
result >>= 1;
if (sign < 0) result = -result;
return result;
}
int main(void)
{
unsigned long dividend;
unsigned int divisor;
unsigned int quotient;
dividend = 0x3FFFFFFF;
divisor = 0x7FFF;
NOTES:
HIGHLIGHTS
This section of the manual contains the following major topics:
7
7.1 Instruction Bit Map ........................................................................................................ 484
7.2 Instruction Set Summary Table ..................................................................................... 486
Reference
7.3 Revision History ............................................................................................................ 496
Note: 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.
Opcode<23:20>
MAC(1) CLRAC(1) MAC(1) MOVSAC(1) SFTAC(1) ADD(1) LAC(1) ADD(1) SAC(1) SAC.R(1) FF1L
MPY(1) MPY(1) NEG(1) FF1R
MPY.N(1) MPY.N(1) SUB(1)
MSC(1) MSC(1)
1101 SL ASR RLC RRC SL ASR RLC RRC DIV.S DIVF(1) — — — SL ASR FBCL
LSR RLNC RRNC LSR RLNC RRNC DIV.U LSR
1110 CP0 CP CP0 CP — — CPBGT(2) CPBEQ(2) INC DEC COM CLR INC DEC COM CLR
CPB CPB CPBLT(2) CPBNE(2) INC2 DEC2 NEG SETM INC2 DEC2 NEG SETM
CPSGT CPSEQ
CPSLT CPSNE
1111 ED(1) — — — — PUSH POP LNK SE DISI DAW CLRWDT NOPR
EDAC(1) ULNK ZE EXCH MOVPAG(2)
SWAP PWRSAV
MAC(1)
POP.S
MPY(1)
PUSH.S
RESET
Note 1: This instruction is only available in dsPIC30F, dsPIC33F, and dsPIC33E family devices.
2: This instruction is only available in PIC24E and dsPIC33E family devices.
DS70157F-page 485
Section 7. Reference
Reference
7.2 INSTRUCTION SET SUMMARY TABLE
The complete 16-bit MCU and DSC device instruction set is summarized in Table 7-2. This table contains an alphabetized listing of the
instruction set. It includes instruction assembly syntax, description, size (in 24-bit words), execution time (in instruction cycles), affected
Status bits, and the page number in which the detailed description can be found. Table 1-2 identifies the symbols that are used in the
Instruction Set Summary Table.
DS70157F-page 486
Note: 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 “Instruction Set Summary Tables” and Section
5.4 “Instruction Descriptions” for details.
Note 1: SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
2: This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
3: This instruction/operand is only available in PIC24E and dsPIC33E devices.
4: This instruction/operand is only available in dsPIC33E devices.
5: This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
6: This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157F-page 487
Section 7. Reference
Reference
Table 7-2: Instruction Set Summary Table (Continued)
Assembly Syntax Page
Description Words Cycles OA(2) OB(2) SA(1,2) SB(1,2) OAB(2) SAB(1,2) DC N OV Z C
Mnemonic, Operands Number
DS70157F-page 488
1
BTSC f,#bit4 Bit test f, skip if clear 1 — — — — — — — — — — — 160
(2 or 3)
1
BTSC Ws,#bit4 Bit test Ws, skip if clear 1 — — — — — — — — — — — 162
(2 or 3)
1
BTSS f,#bit4 Bit test f, skip if set 1 — — — — — — — — — — — 164
(2 or 3)
1
BTSS Ws,#bit4 Bit test Ws, skip if set 1 — — — — — — — — — — — 166
(2 or 3)
BTST f,#bit4 Bit test f to Z 1 1 — — — — — — — — — — 168
Note 1: SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
2: This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
3: This instruction/operand is only available in PIC24E and dsPIC33E devices.
4: This instruction/operand is only available in dsPIC33E devices.
5: This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
6: This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157F-page 489
Section 7. Reference
Reference
Table 7-2: Instruction Set Summary Table (Continued)
Assembly Syntax Page
Description Words Cycles OA(2) OB(2) SA(1,2) SB(1,2) OAB(2) SAB(1,2) DC N OV Z C
Mnemonic, Operands Number
DS70157F-page 490
Signed 32/16-bit integer divide, Q →Wo, R →W1
DIV.U Wm,Wn Unsigned 16/16-bit integer divide, Q →Wo, R →W1 1 18 — — — — — — — 0 0 226
Note 1: SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
2: This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
3: This instruction/operand is only available in PIC24E and dsPIC33E devices.
4: This instruction/operand is only available in dsPIC33E devices.
5: This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
6: This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157F-page 491
Section 7. Reference
Reference
Table 7-2: Instruction Set Summary Table (Continued)
Assembly Syntax Page
Description Words Cycles OA(2) OB(2) SA(1,2) SB(1,2) OAB(2) SAB(1,2) DC N OV Z C
Mnemonic, Operands Number
Wm*Wm,Acc,[Wx],Wxd,[Wy],
MPY Square to accumulator 1 1 — — — — — 297
Wyd(2)
Wm*Wn,Acc,[Wx],Wxd,[Wy],
-(Multiply Wn by Wm) to accumulator 1 1 0 0 — — 0 — — — — — — 299
DS70157F-page 492
MPY.N
Wyd(2)
Wm*Wn,Acc,[Wx],Wxd,[Wy],
MSC Multiply and subtract from accumulator 1 1 — — — — — 301
Wyd,AWB(2)
MUL f W3:W2 = f * WREG 1 1 — — — — — — — — — — — 303
MUL.SS Wb,Ws,Wnd {Wnd + 1,Wnd} = signed(Wb) * signed(Ws) 1 1 — — — — — — — — — — — 305
MUL.SS Wb,Ws,Acc(4) Accumulator = signed(Wb) * signed(Ws) 1 1 — — — — — — — — — — — 307
MUL.SU Wb,#lit5,Wnd {Wnd + 1,Wnd} = signed(Wb) * unsigned(lit5) 1 1 — — — — — — — — — — — 308
MUL.SU Wb,Ws,Wnd {Wnd + 1,Wnd} = signed(Wb) * unsigned(Ws) 1 1 — — — — — — — — — — — 310
MUL.SU Wb,Ws,Acc(4) Accumulator = signed(Wb) * unsigned(Ws) 1 1 — — — — — — — — — — — 312
(4) Accumulator = signed(Wb) * unsigned(lit5) 1 1 — — — — — — — — — — — 314
MUL.SU Wb,#lit5,Acc
MUL.US Wb,Ws,Wnd {Wnd + 1,Wnd} = unsigned(Wb) * signed(Ws) 1 1 — — — — — — — — — — — 315
MUL.US Wb,Ws,Acc(4) Accumulator = unsigned(Wb) * signed(Ws) 1 1 — — — — — — — — — — — 317
MUL.UU Wb,#lit5,Wnd {Wnd + 1,Wnd} = unsigned(Wb) * unsigned(lit5) 1 1 — — — — — — — — — — — 319
MUL.UU Wb,Ws,Wnd {Wnd + 1,Wnd} = unsigned(Wb) * unsigned(Ws) 1 1 — — — — — — — — — — — 320
MUL.UU Wb,Ws,Acc(4) Accumulator = unsigned(Wb) * unsigned(Ws) 1 1 — — — — — — — — — — — 322
(4) Accumulator = unsigned(Wb) * unsigned(lit5) 1 1 — — — — — — — — — — — 323
MUL.UU Wb,#lit5,Acc
MULW.SS Wb,Ws,Wnd(3) Wnd = signed(Wb) * signed(Ws) 1 1 — — — — — — — — — — — 324
MULW.SU Wb,Ws,Wnd(3) Wnd = signed(Wb) * unsigned(Ws) 1 1 — — — — — — — — — — — 326
MULW.SU Wb,#lit5,Wnd(3) Wnd = signed(Wb) * unsigned(lit5) 1 1 — — — — — — — — — — — 328
MULW.US Wb,Ws,Wnd(3) Wnd = unsigned(Wb) * signed(Ws) 1 1 — — — — — — — — — — — 329
MULW.UU Wb,Ws,Wnd(3) Wnd = unsigned(Wb) * unsigned(Ws) 1 1 — — — — — — — — — — — 331
(3) Wnd = unsigned(Wb) * unsigned(lit5) 1 1 — — — — — — — — — — — 332
MULW.UU Wb,#lit5,Wnd
NEG f {,WREG} Destination = f + 1 1 1 — — — — — — 333
NEG Ws,Wd Wd = Ws + 1 1 1 — — — — — — 333
NEG Acc(2) Negate accumulator 1 1 — — — — — 335
NOP No operation 1 1 — — — — — — — — — — — 336
16-bit MCU and DSC Programmer’s Reference Manual
Legend: set or cleared; may be cleared, but never set; may be set, but never cleared; ‘1’ always set; ‘0’ always cleared; — unchanged
Note 1: SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
2: This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
3: This instruction/operand is only available in PIC24E and dsPIC33E devices.
4: This instruction/operand is only available in dsPIC33E devices.
5: This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
6: This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157F-page 493
Section 7. Reference
Reference
Table 7-2: Instruction Set Summary Table (Continued)
Assembly Syntax Page
Description Words Cycles OA(2) OB(2) SA(1,2) SB(1,2) OAB(2) SAB(1,2) DC N OV Z C
Mnemonic, Operands Number
DS70157F-page 494
SETM WREG WREG = 0xFFFF 1 1 — — — — — — — — — — — 395
SETM Wd Wd = 0xFFFF 1 1 — — — — — — — — — — — 396
(2) Arithmetic shift accumulator by Slit6 1 1 — — — — — 397
SFTAC Acc,#Slit6
SFTAC Acc,Wb(2) Arithmetic shift accumulator by (Wb) 1 1 — — — — — 398
SL f {,WREG} Destination = arithmetic left shift f 1 1 — — — — — — — — 399
SL Ws,Wd Wd = arithmetic left shift Ws 1 1 — — — — — — — — 401
SL Wb,#lit4,Wnd Wnd = left shift Wb by lit4 1 1 — — — — — — — — — 403
Legend: set or cleared; may be cleared, but never set; may be set, but never cleared; ‘1’ always set; ‘0’ always cleared; — unchanged
Note 1: SA, SB and SAB are only modified if the corresponding saturation is enabled, otherwise unchanged.
2: This instruction/operand is only available in dsPIC30F, dsPIC33F, and dsPIC33E devices.
3: This instruction/operand is only available in PIC24E and dsPIC33E devices.
4: This instruction/operand is only available in dsPIC33E devices.
5: This instruction/operand is only available in PIC24F, PIC24H, dsPIC30F, and dsPIC33F devices.
6: This instruction/operand is only available in dsPIC30F and dsPIC33F devices.
DS70157F-page 495
Section 7. Reference
Reference
16-bit MCU and DSC Programmer’s Reference Manual
INDEX
Symbols Immediate Addressing................................................ 59
Indirect Addressing with Effective Address Update .... 55
__builtin_addab................................................................. 447
Indirect Addressing with Register Offset .................... 56
__builtin_btg.............................................................. 447, 448
Legal Word Move Operations ..................................... 67
__builtin_divmodud ........................................................... 454
MAC Accumulator WB Syntax .................................... 87
__builtin_divsd .................................................................. 454
MAC Prefetch Syntax ................................................. 86
__builtin_edsoffset ............................................................ 458
Move with Literal Offset Instructions........................... 56
__builtin_edspage ............................................................. 458
MSC Instruction with Two Prefetches and Accumulator
__builtin_mac .................................................................... 460
Write Back .......................................................... 87
__builtin_modsd ................................................................ 462
Normalizing with FBCL ............................................... 90
__builtin_modud................................................................ 462 Register Direct Addressing......................................... 54
__builtin_mpy .................................................................... 464 Sample Byte Math Operations.................................... 65
__builtin_mpyn .................................................................. 465 Sample Byte Move Operations................................... 64
__builtin_mulss ................................................................. 468 Scaling with FBCL ...................................................... 89
__builtin_muluu ................................................................. 469 Stack Pointer Usage................................................... 71
__builtin_nop..................................................................... 470 Unsigned f and WREG Multiply (Legacy MULWF
__builtin_psvoffset ............................................................ 470 Instruction).......................................................... 80
Index
__builtin_sac ..................................................................... 472 Using 10-bit Literals for Byte Operands...................... 69
__builtin_subab ................................................................. 475 Using the Default Working Register WREG ............... 79
__builtin_tbladdress .......................................................... 475 Conditional Branch Instructions .......................................... 76
__builtin_tblwth ................................................................. 478 Core Control Register ......................................................... 24
__builtin_tblwtl .................................................................. 479
D
A
Data Addressing Mode Tree............................................... 59
Accumulator A, Accumulator B ........................................... 19 Data Addressing Modes ..................................................... 52
Accumulator Access ........................................................... 84 DCOUNT Register .............................................................. 20
Accumulator Selection ........................................................ 97 Default Working Register (WREG) ............................... 18, 79
Accumulator Usage............................................................. 83 Development Support ........................................................... 6
Addressing Modes for Wd Destination Register ................. 95 DOEND Register ................................................................ 21
Addressing Modes for Ws Source Register ........................ 95 DOSTART Register ............................................................ 20
Assigned Working Register Usage ..................................... 78 DSP Accumulator Instructions ............................................ 88
DSP Data Formats.............................................................. 81
B DSP MAC Indirect Addressing Modes................................ 57
Built-In Functions DSP MAC Instructions ........................................................ 84
__builtin_addab......................................................... 447
__builtin_btg...................................................... 447, 448 F
__builtin_divmodud ................................................... 454 File Register Addressing..................................................... 52
__builtin_divsd .......................................................... 454
__builtin_edsoffset .................................................... 458 I
__builtin_edspage..................................................... 458
__builtin_mac............................................................ 460 Immediate Addressing ........................................................ 58
__builtin_modsd........................................................ 462 Operands in the Instruction Set .................................. 58
__builtin_modud........................................................ 462 Implied DSP Operands ....................................................... 78
__builtin_mpy............................................................ 464 Implied Frame and Stack Pointer ....................................... 78
__builtin_mpyn.......................................................... 465 Instruction Bit Map ............................................................ 484
__builtin_mulss ......................................................... 468 Instruction Description Example ......................................... 98
__builtin_muluu......................................................... 469 Instruction Descriptions ...................................................... 99
__builtin_nop............................................................. 470 ADD (16-bit Signed Add to Accumulator) ................. 104
__builtin_psvoffset .................................................... 470 ADD (Add Accumulators) ......................................... 103
__builtin_sac ............................................................. 472 ADD (Add f to WREG) ................................................ 99
__builtin_subab......................................................... 475 ADD (Add Literal to Wn) ........................................... 100
__builtin_tbladdress .................................................. 475 ADD (Add Wb to Short Literal) ................................. 101
__builtin_tblwth ......................................................... 478 ADD (Add Wb to Ws)................................................ 102
__builtin_tblwtl .......................................................... 479 ADDC (Add f to WREG with Carry) .......................... 106
Byte Operations .................................................................. 64 ADDC (Add Literal to Wn with Carry) ....................... 107
ADDC (Add Wb to Short Literal with Carry).............. 108
C ADDC (Add Wb to Ws with Carry) ............................ 110
AND (AND f and WREG) .......................................... 112
Code Examples AND (AND Literal and Wn) ....................................... 113
’Z’ Status bit Operation for 32-bit Addition .................. 77 AND (AND Wb and Short Literal) ............................. 114
Base MAC Syntax....................................................... 85 AND (AND Wb and Ws) ........................................... 115
File Register Addressing............................................. 53 ASR (Arithmetic Shift Right by Short Literal) ............ 121
File Register Addressing and WREG.......................... 53 ASR (Arithmetic Shift Right by Wns) ........................ 122
Frame Pointer Usage.................................................. 73 ASR (Arithmetic Shift Right f) ................................... 117
Illegal Word Move Operations..................................... 68 ASR (Arithmetic Shift Right Ws) ............................... 119
BCLR (Bit Clear in Ws) ............................................. 124 CPSGT (Signed Compare Wb with Wn,
BCLR.B (Bit Clear f) .................................................. 123 Skip if Greater Than) ........................................ 210
BRA (Branch Unconditionally) .................................. 126 CPSGT (Signed Compare Wb with Wn, Skip if Greater
BRA (Computed Branch) .................................. 128, 129 Than) ................................................................ 211
BRA C (Branch if Carry)............................................ 130 CPSLT (Signed Compare Wb with Wn,
BRA GE (Branch if Signed Greater Than or Equal) .. 132 Skip if Less Than) ..................................... 212, 213
BRA GEU (Branch if Unsigned Greater Than CPSNE (Signed Compare Wb with Wn,
or Equal) ........................................................... 134 Skip if Not Equal)...................................... 214, 215
BRA GT (Branch if Signed Greater Than) ................ 135 DAW.B (Decimal Adjust Wn) .................................... 216
BRA GTU (Branch if Unsigned Greater Than) .......... 136 DEC (Decrement f) ................................................... 217
BRA LE (Branch if Signed Less Than or Equal) ....... 137 DEC (Decrement Ws) ............................................... 218
BRA LEU (Branch if Unsigned Less Than or Equal). 138 DEC2 (Decrement f by 2) ......................................... 220
BRA LT (Branch if Signed Less Than) ...................... 139 DEC2 (Decrement Ws by 2) ..................................... 221
BRA LTU (Branch if Not Carry) ................................. 142 DISI (Disable Interrupts Temporarily) ....................... 223
BRA LTU (Branch if Unsigned Less Than) ............... 140 DIV.S (Signed Integer Divide)................................... 224
BRA N (Branch if Negative) ...................................... 141 DIV.U (Unsigned Integer Divide) .............................. 226
BRA NN (Branch if Not Negative) ............................. 143 DIVF (Fractional Divide) ........................................... 228
BRA NOV (Branch if Not Overflow) .......................... 144 DO (Initialize Hardware Loop Literal)................ 230, 233
BRA NZ (Branch if Not Zero) .................................... 145 DO (Initialize Hardware Loop Wn) .................... 235, 237
BRA OA (Branch if Overflow Accumulator A) ........... 146 ED (Euclidean Distance, No Accumulate) ................ 239
BRA OB (Branch if Overflow Accumulator B) ........... 147 EDAC (Euclidean Distance)...................................... 241
BRA OV (Branch if Overflow).................................... 148 EXCH (Exchange Wns and Wnd)............................. 243
BRA SA (Branch if Saturation Accumulator A) ......... 149 FBCL (Find First Bit Change from Left) .................... 244
BRA SB (Branch if Saturation Accumulator B) ......... 150 FF1L (Find First One from Left) ................................ 246
BRA Z (Branch if Zero) ............................................. 151 FF1R (Find First One from Right) ............................. 248
BSET (Bit Set f)......................................................... 152 GOTO (Unconditional Indirect Jump) ............... 251, 252
BSET (Bit Set in Ws)................................................. 153 GOTO (Unconditional Jump) .................................... 250
BSW (Bit Write in Ws) ............................................... 155 GOTO.L (Unconditional Indirect Jump Long) ........... 253
BTG (Bit Toggle f) ..................................................... 157 INC (Increment f) ...................................................... 254
BTG (Bit Toggle in Ws) ............................................. 158 INC (Increment Ws) .................................................. 255
BTSC (Bit Test f, Skip if Clear) ................................. 160 INC2 (Increment f by 2) ............................................ 257
BTSC (Bit Test Ws, Skip if Clear) ............................. 162 INC2 (Increment Ws by 2) ........................................ 258
BTSS (Bit Test f, Skip if Set) ..................................... 164 IOR (Inclusive OR f and WREG) .............................. 260
BTSS (Bit Test Ws, Skip if Set)................................. 166 IOR (Inclusive OR Literal and Wn) ........................... 261
BTST (Bit Test f) ....................................................... 168 IOR (Inclusive OR Wb and Short Literal).................. 262
BTST (Bit Test in Ws) ....................................... 169, 171 IOR (Inclusive OR Wb and Ws) ................................ 263
BTSTS (Bit Test/Set f) .............................................. 173 LAC (Load Accumulator) .......................................... 265
BTSTS (Bit Test/Set in Ws) ...................................... 175 LNK (Allocate Stack Frame) ............................. 267, 268
CALL (Call Indirect Subroutine) ........................ 180, 181 LSR (Logical Shift Right by Short Literal) ................. 273
CALL (Call Subroutine) ..................................... 177, 178 LSR (Logical Shift Right by Wns) ............................. 274
CALL.L (Call Indirect Subroutine Long) .................... 183 LSR (Logical Shift Right f) ........................................ 269
CBSLT (Signed Compare Wb with Wn, Branch if LSR (Logical Shift Right Ws) .................................... 271
Less Than) ........................................................ 205 MAC (Multiply and Accumulate) ............................... 275
CLR (Clear Accumulator, Prefetch Operands).......... 186 MAC (Square and Accumulate) ................................ 277
CLR (Clear f or WREG) ............................................ 184 MOV (Move 16-bit Literal to Wn) .............................. 284
CLR (Clear Wd) ........................................................ 185 MOV (Move f to Destination) .................................... 279
CLRWDT (Clear Watchdog Timer) ........................... 188 MOV (Move f to Wnd) ............................................... 281
COM (Complement f) ................................................ 189 MOV (Move Wns to [Wd with offset])........................ 286
COM (Complement Ws)............................................ 190 MOV (Move Wns to f) ............................................... 282
CP (Compare f with WREG, Set Status Flags) ......... 191 MOV (Move WREG to f) ........................................... 280
CP (Compare Wb with lit5, Set Status Flags) ........... 192 MOV (Move Ws to Wd)............................................. 287
CP (Compare Wb with lit8, Set Status Flags) ........... 193 MOV (Move Ws with offset to Wnd).......................... 285
CP (Compare Wb with Ws, Set Status Flags) .......... 194 MOV.B (Move 8-bit Literal to Wnd)........................... 283
CP0 (Compare f with 0x0, Set Status Flags) ............ 196 MOV.D (Double-Word Move from Source to Wnd)... 289
CP0 (Compare Ws with 0x0, Set Status Flags) ........ 197 MOVPAG (Move Literal to Page Register) ............... 291
CPB (Compare f with WREG using Borrow, MOVPAG (Move Ws to Page Register).................... 292
Set Status Flags) .............................................. 198 MOVSAC (Prefetch Operands and
CPB (Compare Wb with lit5 using Borrow, Store Accumulator) ........................................... 293
Set Status Flags) ...................................... 199, 200 MPY (Multiply Wm by Wn to Accumulator)............... 295
CPB (Compare Ws with Wb using Borrow, MPY (Square to Accumulator) .................................. 297
Set Status Flags) .............................................. 201 MPY.N (Multiply -Wm by Wn to Accumulator) .......... 299
CPBEQ (Compare Wb with Wn, Branch if Equal)..... 203 MSC (Multiply and Subtract from Accumulator)........ 301
CPBGT (Signed Compare Wb with Wn, Branch if MUL (Integer Unsigned Multiply f and WREG) ......... 303
Greater Than) ................................................... 204 MUL.SS (Integer 16x16-bit Signed Multiply with
CPBNE (Signed Compare Wb with Wn, Branch if Not Accumulator Destination) ................................. 307
Equal)................................................................ 206 MUL.SS (Integer 16x16-bit Signed Multiply)............. 305
CPSEQ (Compare Wb with Wn, Skip if Equal) . 207, 208
Index
with 16-bit Result) ............................................. 324 with Borrow)...................................................... 418
MULW.SU (Integer 16x16-bit Signed-Unsigned SUBBR (Subtract Wb from Ws with Borrow) ............ 420
Multiply with 16-bit Result) ................................ 326 SUBR (Subtract f from WREG) ................................ 422
MULW.SU (Integer 16x16-bit Signed-Unsigned SUBR (Subtract Wb from Short Literal) .................... 423
Short Literal Multiply with 16-bit Result) ........... 328 SUBR (Subtract Wb from Ws) .................................. 424
MULW.US (Integer 16x16-bit Unsigned-Signed SWAP (Byte or Nibble Swap Wn)............................. 426
Multiply with 16-bit Result) ................................ 329 TBLRDH (Table Read High) ..................................... 427
MULW.UU (Integer 16x16-bit Unsigned Multiply TBLRDL (Table Read Low) ...................................... 429
with 16-bit Result) ............................................. 331 TBLWTH (Table Write High)..................................... 431
MULW.UU (Integer 16x16-bit Unsigned Short TBLWTL (Table Write Low) ...................................... 433
Literal Multiply ULNK (De-allocate Stack Frame) ..................... 435, 436
with 16-bit Result) ............................................. 332 XOR (Exclusive OR f and WREG)............................ 437
NEG (Negate Accumulator) ...................................... 335 XOR (Exclusive OR Literal and Wn)......................... 438
NEG (Negate f) ......................................................... 333 XOR (Exclusive OR Wb and Short Literal) ............... 439
NEG (Negate Ws) ..................................................... 333 XOR (Exclusive OR Wb and Ws) ............................. 440
NOP (No Operation) ................................................. 336 ZE (Zero-Extend Wn) ............................................... 442
NOPR (No Operation)............................................... 336 Instruction Encoding Field Descriptors Introduction ........... 94
POP (Pop TOS to f) .................................................. 337 Instruction Set Overview..................................................... 38
POP (Pop TOS to Wd).............................................. 338 Bit Instructions ............................................................ 45
POP.D (Double Pop TOS to Wnd/ Compare/Skip Instructions ......................................... 46
Wnd+1) ............................................................. 339 Control Instructions..................................................... 49
POP.S (Pop Shadow Registers) ............................... 340 DSP Instructions......................................................... 50
PUSH (Push f to TOS) .............................................. 341 dsPIC30F/33F Instruction Groups .............................. 38
PUSH (Push Ws to TOS).......................................... 342 Logic Instructions........................................................ 43
PUSH.D (Double Push Wns/ Math Instructions ........................................................ 41
Wns+1 to TOS) ................................................. 343 Move Instructions ....................................................... 40
PUSH.S (Push Shadow Registers)........................... 345 Program Flow Instructions .......................................... 47
PWRSAV (Enter Power Saving Mode) ..................... 346 Rotate/Shift Instructions ............................................. 44
RCALL (Computed Relative Call) ..................... 351, 353 Shadow/Stack Instructions ......................................... 49
RCALL (Relative Call)....................................... 347, 349 Instruction Set Summary Table ........................................ 486
REPEAT (Repeat Next Instruction ’lit14 + 1’ Times). 355 Instruction Set Symbols ........................................................ 8
REPEAT (Repeat Next Instruction ’lit15 + 1’ Times). 357 (text) ............................................................................. 8
REPEAT (Repeat Next Instruction Wn + 1 Times)359, 361 [text].............................................................................. 8
RESET (Reset) ......................................................... 363 { } .................................................................................. 8
RETFIE (Return from Interrupt) ........................ 365, 366 {label:}........................................................................... 8
RETLW (Return with Literal in Wn)................... 367, 369 #text.............................................................................. 8
RETURN (Return)............................................. 371, 372 <n:m> ........................................................................... 8
RLC (Rotate Left f through Carry)............................. 373 Acc................................................................................ 8
RLC (Rotate Left Ws through Carry)......................... 375 AWB ............................................................................. 8
RLNC (Rotate Left f without Carry) ........................... 377 bit4................................................................................ 8
RLNC (Rotate Left Ws without Carry)....................... 379 Expr .............................................................................. 8
RRC (Rotate Right f through Carry).......................... 381 f..................................................................................... 8
RRC (Rotate Right Ws through Carry)...................... 383 lit1 ................................................................................. 8
RRNC (Rotate Right f without Carry) ........................ 385 lit10 ............................................................................... 8
RRNC (Rotate Right Ws without Carry).................... 387 lit14 ............................................................................... 8
SAC (Store Accumulator).......................................... 389 lit16 ............................................................................... 8
SAC.R (Store Rounded Accumulator) ...................... 391 lit23 ............................................................................... 8
SE (Sign-Extend Ws) ................................................ 393 lit4 ................................................................................. 8