Microchip PIC18 datasheet: 26.0 Instruction set summary

Published by Microchip · pages 315–339 of 438 · Original PDF

63 discussions about the Microchip PIC18

All 18 parts of the datasheet

26.0 INSTRUCTION SET SUMMARY

PIC18F2455/2550/4455/4550 devices incorporate the standard set of 75 PIC18 core instructions, as well as an extended set of eight new instructions for the optimization of code that is recursive or that utilizes a software stack. The extended set is discussed later in this section.

26.1 Standard Instruction Set

The standard PIC18 instruction set adds many enhancements to the previous PIC MCU instruction sets, while maintaining an easy migration from these PIC MCU instruction sets. Most instructions are a single program memory word (16 bits) but there are four instructions that require two program memory locations.

Each single-word instruction is a 16-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction.

The instruction set is highly orthogonal and is grouped into four basic categories:

  • Byte-oriented operations
  • Bit-oriented operations
  • Literal operations
  • Control operations

The PIC18 instruction set summary in Table 26-2 lists byte-oriented, bit-oriented, literal and control operations. Table 26-1 shows the opcode field descriptions.

Most byte-oriented instructions have three operands:

  1. The file register (specified by 'f')
  2. The destination of the result (specified by 'd')
  3. The accessed memory (specified by 'a')

The file register designator 'f' specifies which file register is to be used by the instruction. The destination designator 'd' specifies where the result of the operation is to be placed. If 'd' is zero, the result is placed in the WREG register. If 'd' is one, the result is placed in the file register specified in the instruction.

All bit-oriented instructions have three operands:

  1. The file register (specified by 'f')
  2. The bit in the file register (specified by 'b')
  3. The accessed memory (specified by 'a')

The bit field designator 'b' selects the number of the bit affected by the operation, while the file register designator 'f' represents the number of the file in which the bit is located.

The literal instructions may use some of the following operands:

  • A literal value to be loaded into a file register (specified by 'k')
  • The desired FSR register to load the literal value into (specified by 'f')
  • No operand required (specified by '—')

The control instructions may use some of the following operands:

  • A program memory address (specified by 'n')
  • The mode of the CALL or RETURN instructions (specified by 's')
  • The mode of the table read and table write instructions (specified by 'm')
  • No operand required (specified by '—')

All instructions are a single word, except for four double-word instructions. These instructions were made double-word to contain the required information in 32 bits. In the second word, the 4 MSBs are '1's. If this second word is executed as an instruction (by itself), it will execute as a NOP.

All single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter is changed as a result of the instruction. In these cases, the execution takes two instruction cycles with the additional instruction cycle(s) executed as a NOP.

The double-word instructions execute in two instruction cycles.

One instruction cycle consists of four oscillator periods. Thus, for an oscillator frequency of 4 MHz, the normal instruction execution time is 1 µs. If a conditional test is true, or the program counter is changed as a result of an instruction, the instruction execution time is 2 µs. Two-word branch instructions (if true) would take 3 µs.

Figure 26-1 shows the general formats that the instructions can have. All examples use the convention 'nnh' to represent a hexadecimal number.

The instruction set summary, shown in Table 26-2, lists the standard instructions recognized by the Microchip MPASM™ Assembler.

Section 26.1.1 "Standard Instruction Set" provides a description of each instruction.

TABLE 26-1: OPCODE FIELD DESCRIPTIONS

Field Description
a RAM access bita = 0: RAM location in Access RAM (BSR register is ignored)a = 1: RAM bank is specified by BSR register
bbb Bit address within an 8-bit file register (0 to 7).
BSR Bank Select Register. Used to select the current RAM bank.
C, DC, Z, OV, N ALU Status bits: Carry, Digit Carry, Zero, Overflow, Negative.
d Destination select bitd = 0: store result in WREGd = 1: store result in file register f
dest Destination: either the WREG register or the specified register file location.
f 8-bit register file address (00h to FFh) or 2-bit FSR designator (0h to 3h).
fs 12-bit register file address (000h to FFFh). This is the source address.
fd 12-bit register file address (000h to FFFh). This is the destination address.
GIE Global Interrupt Enable bit.
k Literal field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value).
label Label name.
mm The mode of the TBLPTR register for the table read and table write instructions.Only used with table read and table write instructions: No change to register (such as TBLPTR with table reads and writes) Post-Increment register (such as TBLPTR with table reads and writes) Post-Decrement register (such as TBLPTR with table reads and writes) Pre-Increment register (such as TBLPTR with table reads and writes)
*
*+
*–
+*
n The relative address (2’s complement number) for relative branch instructions or the direct address for Call/Branch and Return instructions.
PC Program Counter.
PCL Program Counter Low Byte.
PCH Program Counter High Byte.
PCLATH Program Counter High Byte Latch.
PCLATU Program Counter Upper Byte Latch.
PD Power-Down bit.
PRODH Product of Multiply High Byte.
PRODL Product of Multiply Low Byte.
s Fast Call/Return mode select bits = 0: do not update into/from shadow registerss = 1: certain registers loaded into/from shadow registers (Fast mode)
TBLPTR 21-bit Table Pointer (points to a program memory location).
TABLAT 8-bit Table Latch.
TO Time-out bit.
TOS Top-of-Stack.
u Unused or unchanged.
WDT Watchdog Timer.
WREG Working register (accumulator).
x Don’t care (‘0’ or ‘1’). The assembler will generate code with x = 0. It is the recommended form of use for compatibility with all Microchip software tools.
zs 7-bit offset value for indirect addressing of register files (source).
zd 7-bit offset value for indirect addressing of register files (destination).
{ } Optional argument.
[text] Indicates an indexed address.
(text) The contents of text.
[expr] Specifies bit n of the register indicated by the pointer expr.
→ Assigned to.
< > Register bit field.
∈ In the set of.
italics User-defined term (font is Courier New).

FIGURE 26-1: GENERAL FORMAT FOR INSTRUCTIONS

Byte-oriented file register operations

Example Instruction ADDWF MYREG, W, B

\begin{tabular}{|l|l|l|l|} \hline

  • \multicolumn{4}{l}{15 \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \ ........ 10 \quad 9 \quad 8 \quad 7 \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \ ........ 0} \ \hline OPCODE & d & a & f (FILE #) \ \hline \end{tabular}

d = 0 for result destination to be WREG register d = 1 for result destination to be file register (f) a = 0 to force Access Bank a = 1 for BSR to select bank f = 8-bit file register address

Byte to Byte move operations (2-word)

Example Instruction MOVFF MYREG1, MYREG2

\begin{tabular}{|l|l|} \hline

  • \multicolumn{2}{l}{15 \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \quad \ ........

Figure from the manual

TABLE 26-2: PIC18FXXXX INSTRUCTION SET

Mnemonic, Operands Description Cycles 16-Bit Instruction Word Status Affected Notes
MSb LSb
BYTE-ORIENTED OPERATIONS
ADDWF f, d, a Add WREG and f 1 0010 01da ffff ffff C, DC, Z, OV, N 1, 2
ADDWFC f, d, a Add WREG and Carry bit to f 1 0010 00da ffff ffff C, DC, Z, OV, N 1, 2
ANDWF f, d, a AND WREG with f 1 0001 01da ffff ffff Z, N 1,2
CLRF f, a Clear f 1 0110 101a ffff ffff Z 2
COMF f, d, a Complement f 1 0001 11da ffff ffff Z, N 1, 2
CPFSEQ f, a Compare f with WREG, Skip = 1 (2 or 3) 0110 001a ffff ffff None 4
CPFSGT f, a Compare f with WREG, Skip > 1 (2 or 3) 0110 010a ffff ffff None 4
CPFSLT f, a Compare f with WREG, Skip < 1 (2 or 3) 0110 000a ffff ffff None 1, 2
DECF f, d, a Decrement f 1 0000 01da ffff ffff C, DC, Z, OV, N 1, 2, 3, 4
DECFSZ f, d, a Decrement f, Skip if 0 1 (2 or 3) 0010 11da ffff ffff None 1, 2, 3, 4
DCFSNZ f, d, a Decrement f, Skip if Not 0 1 (2 or 3) 0100 11da ffff ffff None 1, 2
INCF f, d, a Increment f 1 0010 10da ffff ffff C, DC, Z, OV, N 1, 2, 3, 4
INCFSZ f, d, a Increment f, Skip if 0 1 (2 or 3) 0011 11da ffff ffff None 4
INFSNZ f, d, a Increment f, Skip if Not 0 1 (2 or 3) 0100 10da ffff ffff None 1, 2
IORWF f, d, a Inclusive OR WREG with f 1 0001 00da ffff ffff Z, N 1, 2
MOVF f, d, a Move f 1 0101 00da ffff ffff Z, N 1
MOVFF fs, fd Move fs (source) to 1st word fd (destination) 2nd word 2 1100 ffff ffff ffff None
1111 ffff ffff ffff
MOVWF f, a Move WREG to f 1 0110 111a ffff ffff None
MULWF f, a Multiply WREG with f 1 0000 001a ffff ffff None 1, 2
NEGF f, a Negate f 1 0110 110a ffff ffff C, DC, Z, OV, N
RLCF f, d, a Rotate Left f through Carry 1 0011 01da ffff ffff C, Z, N 1, 2
RLNCF f, d, a Rotate Left f (No Carry) 1 0100 01da ffff ffff Z, N
RRCF f, d, a Rotate Right f through Carry 1 0011 00da ffff ffff C, Z, N
RRNCF f, d, a Rotate Right f (No Carry) 1 0100 00da ffff ffff Z, N
SETF f, a Set f 1 0110 100a ffff ffff None 1, 2
SUBFWB f, d, a Subtract f from WREG with Borrow 1 0101 01da ffff ffff C, DC, Z, OV, N
SUBWF f, d, a Subtract WREG from f 1 0101 11da ffff ffff C, DC, Z, OV, N 1, 2
SUBWFB f, d, a Subtract WREG from f with Borrow 1 0101 10da ffff ffff C, DC, Z, OV, N
SWAPF f, d, a Swap Nibbles in f 1 0011 10da ffff ffff None 4
TSTFSZ f, a Test f, Skip if 0 1 (2 or 3) 0110 011a ffff ffff None 1, 2
XORWF f, d, a Exclusive OR WREG with f 1 0001 10da ffff ffff Z, N

Note 1: When a PORT register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value present on the pins themselves. For example, if the data latch is ‘1’ for a pin configured as an input and is driven low by an external device, the data will be written back with a ‘0’.

2: If this instruction is executed on the TMR0 register (and where applicable, ‘d’ = 1), the prescaler will be cleared if assigned.

3: If the Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP.

4: Some instructions are two-word instructions. The second word of these instructions will be executed as a NOP unless the first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory locations have a valid instruction.

TABLE 26-2: PIC18FXXXX INSTRUCTION SET (CONTINUED)

Mnemonic, Operands Description Cycles 16-Bit Instruction Word Status Affected Notes
MSb LSb
BIT-ORIENTED OPERATIONS
BCF f, b, a Bit Clear f 1 1001 bbb a ffff ffff None 1, 2
BSF f, b, a Bit Set f 1 1000 bbb a ffff ffff None 1, 2
BTFSC f, b, a Bit Test f, Skip if Clear 1 (2 or 3) 1011 bbb a ffff ffff None 3, 4
BTFSS f, b, a Bit Test f, Skip if Set 1 (2 or 3) 1010 bbb a ffff ffff None 3, 4
BTG f, d, a Bit Toggle f 1 0111 bbb a ffff ffff None 1, 2
CONTROL OPERATIONS
BC n Branch if Carry 1 (2) 1110 0010 nnnn nnnn None
BN n Branch if Negative 1 (2) 1110 0110 nnnn nnnn None
BNC n Branch if Not Carry 1 (2) 1110 0011 nnnn nnnn None
BNN n Branch if Not Negative 1 (2) 1110 0111 nnnn nnnn None
BNOV n Branch if Not Overflow 1 (2) 1110 0101 nnnn nnnn None
BNZ n Branch if Not Zero 1 (2) 1110 0001 nnnn nnnn None
BOV n Branch if Overflow 1 (2) 1110 0100 nnnn nnnn None
BRA n Branch Unconditionally 2 1101 0nnn nnnn nnnn None
BZ n Branch if Zero 1 (2) 1110 0000 nnnn nnnn None
CALL n, s Call Subroutine 1st word2nd word 2 1110 110s kkkk kkkk1111 kkkk kkkk kkkk None
CLRWDT — Clear Watchdog Timer 1 0000 0000 0000 0100 \overlineTO, \overlinePD
DAW — Decimal Adjust WREG 1 0000 0000 0000 0111 C
GOTO n Go to Address 1st word2nd word 2 1110 1111 kkkk kkkk1111 kkkk kkkk kkkk None
NOP — No Operation 1 0000 0000 0000 0000 None 4
NOP — No Operation 1 1111 xxxx xxxx xxxx None
POP — Pop Top of Return Stack (TOS) 1 0000 0000 0000 0110 None
PUSH — Push Top of Return Stack (TOS) 1 0000 0000 0000 0101 None
RCALL n Relative Call 2 1101 1nnn nnnn nnnn None
RESET — Software Device Reset 1 0000 0000 1111 1111 All
RETFIE s Return from Interrupt Enable 2 0000 0000 0001 000s GIE/GIEH,PEIE/GIEL
RETLW k Return with Literal in WREG 2 0000 1100 kkkk kkkk None
RETURN s Return from Subroutine 2 0000 0000 0001 001s None
SLEEP — Go into Standby mode 1 0000 0000 0000 0011 \overlineTO, \overlinePD

Note 1: When a PORT register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value present on the pins themselves. For example, if the data latch is ‘1’ for a pin configured as an input and is driven low by an external device, the data will be written back with a ‘0’.

2: If this instruction is executed on the TMR0 register (and where applicable, ‘d’ = 1), the prescaler will be cleared if assigned.

3: If the Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP.

4: Some instructions are two-word instructions. The second word of these instructions will be executed as a NOP unless the first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory locations have a valid instruction.

TABLE 26-2: PIC18FXXXX INSTRUCTION SET (CONTINUED)

Mnemonic, Operands Description Cycles 16-Bit Instruction Word Status Affected Notes
MSb LSb
LITERAL OPERATIONS
ADDLW k Add Literal and WREG 1 0000 1111 kkkk kkkk C, DC, Z, OV, N
ANDLW k AND Literal with WREG 1 0000 1011 kkkk kkkk Z, N
IORLW k Inclusive OR Literal with WREG 1 0000 1001 kkkk kkkk Z, N
LFSR f, k Move Literal (12-bit) 2nd word to FSR(f) 1st word 2 1110 1110 00ff kkkk 1111 0000 kkkk kkkk None
MOVLB k Move Literal to BSR<3:0> 1 0000 0001 0000 kkkk None
MOVLW k Move Literal to WREG 1 0000 1110 kkkk kkkk None
MULLW k Multiply Literal with WREG 1 0000 1101 kkkk kkkk None
RETLW k Return with Literal in WREG 2 0000 1100 kkkk kkkk None
SUBLW k Subtract WREG from Literal 1 0000 1000 kkkk kkkk C, DC, Z, OV, N
XORLW k Exclusive OR Literal with WREG 1 0000 1010 kkkk kkkk Z, N
DATA MEMORY ↔ PROGRAM MEMORY OPERATIONS
TBLRD* Table Read 2 0000 0000 0000 1000 None
TBLRD*+ Table Read with Post-Increment 0000 0000 0000 1001 None
TBLRD*- Table Read with Post-Decrement 0000 0000 0000 1010 None
TBLRD+* Table Read with Pre-Increment 0000 0000 0000 1011 None
TBLWT* Table Write 2 0000 0000 0000 1100 None
TBLWT*+ Table Write with Post-Increment 0000 0000 0000 1101 None
TBLWT*- Table Write with Post-Decrement 0000 0000 0000 1110 None
TBLWT+* Table Write with Pre-Increment 0000 0000 0000 1111 None

Note 1: When a PORT register is modified as a function of itself (e.g., MOVF PORTB, 1, 0), the value used will be that value present on the pins themselves. For example, if the data latch is ‘1’ for a pin configured as an input and is driven low by an external device, the data will be written back with a ‘0’.

2: If this instruction is executed on the TMR0 register (and where applicable, ‘d’ = 1), the prescaler will be cleared if assigned.

3: If the Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP.

4: Some instructions are two-word instructions. The second word of these instructions will be executed as a NOP unless the first word of the instruction retrieves the information embedded in these 16 bits. This ensures that all program memory locations have a valid instruction.

26.1.1 STANDARD INSTRUCTION SET

ADDLW ADD Literal to W

Syntax:
ADDLW k

Operands:
0 ≤ k ≤ 255

Operation:
(W) + k → W

Status Affected:
N, OV, C, DC, Z

Encoding:
| 0000 | 1111 | kkkk | kkkk |

Description:
The contents of W are added to the 8-bit literal ‘k’ and the result is placed in W.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to W

Example:
ADDLW 15h

Before Instruction
W = 10h

After Instruction
W = 25h


ADDWF ADD W to f

Syntax:
ADDWF f {,d {,a}}

Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]

Operation:
(W) + (f) → dest

Status Affected:
N, OV, C, DC, Z

Encoding:
| 0010 | 01da | ffff | ffff |

Description:
Add W to register ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back in register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

Example:
ADDWF REG, 0, 0

Before Instruction
W = 17h
REG = 0C2h

After Instruction
W = 0D9h
REG = 0C2h


Note: All PIC18 instructions may take an optional label argument, preceding the instruction mnemonic, for use in symbolic addressing. If a label is used, the instruction format then becomes: {label} instruction argument(s).

Figure from the manual

ADDWFC

ADD W and Carry bit to f

Syntax:
ADDWFC f {,d {,a}}

Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]

Operation:
(W) + (f) + (C) → dest

Status Affected:
N, OV, C, DC, Z

Encoding:
| 0010 | 00da | ffff | ffff |

Description:
Add W, the Carry flag and data memory location ‘f’. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’, the result is placed in data memory location ‘f’.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

Example:
ADDWFC REG, 0, 1

Before Instruction
Carry bit = 1
REG = 02h
W = 4Dh

After Instruction
Carry bit = 0
REG = 02h
W = 50h


ANDLW

AND Literal with W

Syntax:
ANDLW k

Operands:
0 ≤ k ≤ 255

Operation:
(W) .AND. k → W

Status Affected:
N, Z

Encoding:
| 0000 | 1011 | kkkk | kkkk |

Description:
The contents of W are ANDed with the 8-bit literal ‘k’. The result is placed in W.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to W

Example:
ANDLW 05Fh

Before Instruction
W = A3h

After Instruction
W = 03h


Figure from the manual

Figure from the manual

ANDWF — AND W with f

Syntax:
ANDWF f{,d{,a}}

Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]

Operation:
(W) .AND. (f) → dest

Status Affected:
N, Z

Encoding:
| 0001 | 01da | ffff | ffff |

Description:
The contents of W are ANDed with register ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back in register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

Example:
ANDWF REG, 0, 0

Before Instruction
W = 17h
REG = C2h

After Instruction
W = 02h
REG = C2h


BC — Branch if Carry

Syntax:
BC n

Operands:
-128 ≤ n ≤ 127

Operation:
if Carry bit is ‘1’,
(PC) + 2 + 2n → PC

Status Affected:
None

Encoding:
| 1110 | 0010 | nnnn | nnnn |

Description:
If the Carry bit is ‘1’, then the program will branch.
The 2’s complement number ‘2n’ is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.

Words:
1

Cycles:
1(2)

Q Cycle Activity:

If Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation

If No Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation

Example:
HERE BC 5

Before Instruction
PC = address (HERE)

After Instruction
If Carry = 1;
PC = address (HERE + 12)
If Carry = 0;
PC = address (HERE + 2)

Figure from the manual

BCF Bit Clear f

Syntax: BCF f, b {,a}

Operands:

  • 0 ≤ f ≤ 255
  • 0 ≤ b ≤ 7
  • a ∈ [0,1]

Operation: 0 → f

Status Affected: None

Encoding:

| 1001 | bbb a | ffff | ffff |

Description: Bit ‘b’ in register ‘f’ is cleared. If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default). If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words: 1

Cycles: 1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’

Example: BCF FLAG_REG, 7, 0 Before Instruction FLAG_REG = C7h After Instruction FLAG_REG = 47h

BN Branch if Negative

Syntax: BN n

Operands: -128 ≤ n ≤ 127

Operation: if Negative bit is ‘1’, (PC) + 2 + 2n → PC

Status Affected: None

Encoding:

| 1110 | 0110 | nnnn | nnnn |

Description: If the Negative bit is ‘1’, then the program will branch. The 2’s complement number ‘2n’ is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.

Words: 1

Cycles: 1(2)

Q Cycle Activity: If Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC

If No Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation

Example: HERE BN Jump Before Instruction PC = address (HERE) After Instruction If Negative = 1; PC = address (Jump) If Negative = 0; PC = address (HERE + 2)

Figure from the manual

BNC Branch if Not Carry

Syntax: BNC n
Operands: -128 ≤ n ≤ 127
Operation: if Carry bit is ‘0’, (PC) + 2 + 2n → PC
Status Affected: None
Encoding:
| 1110 | 0011 | nnnn | nnnn |
Description: If the Carry bit is ‘0’, then the program will branch. The 2’s complement number ‘2n’ is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
Words: 1
Cycles: 1(2)
Q Cycle Activity:
If Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
If No Jump:
Q1 Q2 Q3 Q4
--- --- --- ---
Decode Read literal ‘n’ Process Data No operation

Example:
HERE BNC Jump
Before Instruction
PC = address (HERE)
After Instruction
If Carry = 0; PC = address (Jump)
If Carry = 1; PC = address (HERE + 2)

BNN Branch if Not Negative

Syntax: BNN n
Operands: -128 ≤ n ≤ 127
Operation: if Negative bit is ‘0’, (PC) + 2 + 2n → PC
Status Affected: None
Encoding:
| 1110 | 0111 | nnnn | nnnn |
Description: If the Negative bit is ‘0’, then the program will branch. The 2’s complement number ‘2n’ is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.
Words: 1
Cycles: 1(2)
Q Cycle Activity:
If Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation
If No Jump:
Q1 Q2 Q3 Q4
--- --- --- ---
Decode Read literal ‘n’ Process Data No operation

Example:
HERE BNN Jump
Before Instruction
PC = address (HERE)
After Instruction
If Negative = 0; PC = address (Jump)
If Negative = 1; PC = address (HERE + 2)

BNOV Branch if Not Overflow

Syntax:
BNOV n

Operands:
-128 ≤ n ≤ 127

Operation:
if Overflow bit is ‘0’,
(PC) + 2 + 2n → PC

Status Affected:
None

Encoding:
| 1110 | 0101 | nnnn | nnnn |

Description:
If the Overflow bit is ‘0’, then the program will branch.
The 2’s complement number ‘2n’ is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.

Words:
1

Cycles:
1(2)

Q Cycle Activity:
If Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation

If No Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation

Example:
HERE BNOV Jump
Before Instruction
PC = address (HERE)
After Instruction
If Overflow = 0;
PC = address (Jump)
If Overflow = 1;
PC = address (HERE + 2)

BNZ Branch if Not Zero

Syntax:
BNZ n

Operands:
-128 ≤ n ≤ 127

Operation:
if Zero bit is ‘0’,
(PC) + 2 + 2n → PC

Status Affected:
None

Encoding:
| 1110 | 0001 | nnnn | nnnn |

Description:
If the Zero bit is ‘0’, then the program will branch.
The 2’s complement number ‘2n’ is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.

Words:
1

Cycles:
1(2)

Q Cycle Activity:
If Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation

If No Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation

Example:
HERE BNZ Jump
Before Instruction
PC = address (HERE)
After Instruction
If Zero = 0;
PC = address (Jump)
If Zero = 1;
PC = address (HERE + 2)

Figure from the manual

Figure from the manual

BRA Unconditional Branch

Syntax:
BRA n

Operands:
-1024 ≤ n ≤ 1023

Operation:
(PC) + 2 + 2n → PC

Status Affected:
None

Encoding:
| 1101 | 0nnn | nnnn | nnnn |

Description:
Add the 2’s complement number ‘2n’ to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is a two-cycle instruction.

Words:
1

Cycles:
2

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC
No operation No operation No operation No operation

Example:
HERE BRA Jump
Before Instruction
PC = address (HERE)
After Instruction
PC = address (Jump)

BSF Bit Set f

Syntax:
BSF f, b {,a}

Operands:
0 ≤ f ≤ 255
0 ≤ b ≤ 7
a ∈ [0,1]

Operation:
1 → f

Status Affected:
None

Encoding:
| 1000 | bbb a | ffff | ffff |

Description:
Bit ‘b’ in register ‘f’ is set.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’

Example:
BSF FLAG_REG, 7, 1
Before Instruction
FLAG_REG = 0Ah
After Instruction
FLAG_REG = 8Ah

Figure from the manual

BTFSC Bit Test File, Skip if Clear

Syntax:
BTFSC f, b {,a}

Operands:
0 ≤ f ≤ 255
0 ≤ b ≤ 7
a ∈ [0,1]

Operation:
skip if (f) = 0

Status Affected:
None

Encoding:
| 1011 | bbb a | ffff | ffff |

Description:
If bit ‘b’ in register ‘f’ is ‘0’, then the next instruction is skipped. If bit ‘b’ is ‘0’, then the next instruction fetched during the current instruction execution is discarded and a NOP is executed instead, making this a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh).
See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1(2)
Note: 3 cycles if skip and followed by a 2-word instruction.

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation

If skip:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation

If skip and followed by 2-word instruction:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation
No operation No operation No operation No operation

Example:
HERE BTFSC FLAG, 1, 0
FALSE :
TRUE :

Before Instruction
PC = address (HERE)

After Instruction
If FLAG<1> = 0;
PC = address (TRUE)
If FLAG<1> = 1;
PC = address (FALSE)


BTFSS Bit Test File, Skip if Set

Syntax:
BTFSS f, b {,a}

Operands:
0 ≤ f ≤ 255
0 ≤ b < 7
a ∈ [0,1]

Operation:
skip if (f) = 1

Status Affected:
None

Encoding:
| 1010 | bbb a | ffff | ffff |

Description:
If bit ‘b’ in register ‘f’ is ‘1’, then the next instruction is skipped. If bit ‘b’ is ‘1’, then the next instruction fetched during the current instruction execution is discarded and a NOP is executed instead, making this a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh).
See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1(2)
Note: 3 cycles if skip and followed by a 2-word instruction.

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation

If skip:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation

If skip and followed by 2-word instruction:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation
No operation No operation No operation No operation

Example:
HERE BTFSS FLAG, 1, 0
FALSE :
TRUE :

Before Instruction
PC = address (HERE)

After Instruction
If FLAG<1> = 0;
PC = address (FALSE)
If FLAG<1> = 1;
PC = address (TRUE)


Figure from the manual

BTG Bit Toggle f

Syntax:
BTG f, b {,a}

Operands:
0 ≤ f ≤ 255
0 ≤ b < 7
a ∈ [0,1]

Operation:
(f) → f

Status Affected:
None

Encoding:
| 0111 | bbba | ffff | ffff |

Description:
Bit ‘b’ in data memory location ‘f’ is inverted.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’

Example:
BTG PORTC, 4, 0

Before Instruction:
PORTC = 0111 0101 [75h]

After Instruction:
PORTC = 0110 0101 [65h]


BOV Branch if Overflow

Syntax:
BOV n

Operands:
-128 ≤ n ≤ 127

Operation:
if Overflow bit is ‘1’,
(PC) + 2 + 2n → PC

Status Affected:
None

Encoding:
| 1110 | 0100 | nnnn | nnnn |

Description:
If the Overflow bit is ‘1’, then the program will branch.
The 2’s complement number ‘2n’ is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction.

Words:
1

Cycles:
1(2)

Q Cycle Activity:
If Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data Write to PC

If No Jump:

Q1 Q2 Q3 Q4
Decode Read literal ‘n’ Process Data No operation

Example:
HERE BOV Jump

Before Instruction
PC = address (HERE)

After Instruction
If Overflow = 1;
PC = address (Jump)
If Overflow = 0;
PC = address (HERE + 2)


BZ Branch if Zero Syntax: BZ n Operands: -128 ≤ n ≤ 127 Operation: if Zero bit is '1', (PC) + 2 + 2n → PC Status Affected: None Encoding: 1110 0000 nnnn nnnn Description: If the Zero bit is '1', then the program will branch. The 2's complement number '2n' is added to the PC. Since the PC will have incremented to fetch the next instruction, the new address will be PC + 2 + 2n. This instruction is then a two-cycle instruction. Words: 1 Cycles: 1(2) Q Cycle Activity: If Jump:

\begin{tabular}{|l|l|l|l|} \hline Q1 & Q2 & Q3 & Q4 \ \hline Decode & Read literal 'n' & Process Data & Write to PC \ \hline No operation & No operation & No operation & No operation \ \hline \end{tabular} If No Jump:

\begin{tabular}{|l|l|l|l|} \hline Q1 & Q2 & Q3 & Q4 \ \hline Decode & Read literal 'n' & Process Data & No operation \ \hline \end{tabular} Example: HERE BZ Jump Before Instruction PC = address (HERE) After Instruction If Zero = 1; PC = address (Jump) If Zero = 0; PC = address (HERE + 2)

CALL Subroutine Call Syntax: CALL k,{s} Operands: 0 ≤ k ≤ 1048575 s ∈ [0,1] Operation: (PC) + 4 → TOS, k → PC<20:1>; if s = 1, (W) → WS, (STATUS) → STATUSS, (BSR) → BSRS Status Affected: None Encoding: 1st word (k<7:0>) 1110 110s k$_7$kkk kkkk$0$ 2nd word(k<19:8>) 1111 k${19}$kkk kkkk kkkk$_8$ Description: Subroutine call of entire 2-Mbyte memory range. First, return address (PC + 4) is pushed onto the return stack. If 's' = 1, the W, STATUS and BSR registers are also pushed into their respective shadow registers, WS, STATUSS and BSRS. If 's' = 0, no update occurs (default). Then, the 20-bit value 'k' is loaded into PC<20:1>. CALL is a two-cycle instruction. Words: 2 Cycles: 2 Q Cycle Activity:

\begin{tabular}{|l|l|l|l|} \hline Q1 & Q2 & Q3 & Q4 \ \hline Decode & Read literal 'k'<7:0>, & Push PC to stack & Read literal 'k'<19:8>, Write to PC \ \hline No operation & No operation & No operation & No operation \ \hline \end{tabular} Example: HERE CALL THERE, 1 Before Instruction PC = address (HERE) After Instruction PC = address (THERE) TOS = address (HERE + 4) WS = W BSRS = BSR STATUSS = STATUS

DS39632E-page 328 © 2009 Microchip Technology Inc.

Figure from the manual

Figure from the manual

CLRF Clear f

Syntax:
CLRF f {,a}

Operands:
0 ≤ f ≤ 255
a ∈ [0,1]

Operation:
000h → f,
1 → Z

Status Affected:
Z

Encoding:
| 0110 | 101a | ffff | ffff |

Description:
Clears the contents of the specified register.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write register ‘f’

Example:
CLRF FLAG_REG, 1

Before Instruction
FLAG_REG = 5Ah
After Instruction
FLAG_REG = 00h

CLRWDT Clear Watchdog Timer

Syntax:
CLRWDT

Operands:
None

Operation:
000h → WDT,
000h → WDT postscaler,
1 → TO,
1 → PD

Status Affected:
TO, PD

Encoding:
| 0000 | 0000 | 0000 | 0100 |

Description:
CLRWDT instruction resets the Watchdog Timer. It also resets the postscaler of the WDT. Status bits, TO and PD, are set.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode No operation Process Data No operation

Example:
CLRWDT

Before Instruction
WDT Counter = ?
After Instruction
WDT Counter = 00h
WDT Postscaler = 0
TO = 1
PD = 1

COMF Complement f

Syntax: COMF f {,d {,a}}

Operands:

  • 0 ≤ f ≤ 255
  • d ∈ [0,1]
  • a ∈ [0,1]

Operation: (f̄) → dest

Status Affected: N, Z

Encoding:

| 0001 | 11da | ffff | ffff |

Description: The contents of register ‘f’ are complemented. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back in register ‘f’ (default). If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default). If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words: 1

Cycles: 1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

Example:

COMF REG, 0, 0

Before Instruction REG = 13h

After Instruction REG = 13h W = ECh

CPFSEQ Compare f with W, Skip if f = W

Syntax: CPFSEQ f {,a}

Operands:

  • 0 ≤ f ≤ 255
  • a ∈ [0,1]

Operation: (f) – (W), skip if (f) = (W) (unsigned comparison)

Status Affected: None

Encoding:

| 0110 | 001a | ffff | ffff |

Description: Compares the contents of data memory location ‘f’ to the contents of W by performing an unsigned subtraction. If ‘f’ = W, then the fetched instruction is discarded and a NOP is executed instead, making this a two-cycle instruction. If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default). If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words: 1

Cycles: 1(2)

Note: 3 cycles if skip and followed by a 2-word instruction.

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation

If skip:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation

If skip and followed by 2-word instruction:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation
No operation No operation No operation No operation

Example:

HERE CPFSEQ REG, 0 NEQUAL : EQUAL :

Before Instruction PC Address = HERE W = ? REG = ?

After Instruction If REG = W; PC = Address (EQUAL) If REG ≠ W; PC = Address (NEQUAL)

Figure from the manual

CPFS GT

Compare f with W, Skip if f > W

Syntax:
CPFS GT f {,a}

Operands:
0 ≤ f ≤ 255
a ∈ [0,1]

Operation:
(f) – (W),
skip if (f) > (W)
(unsigned comparison)

Status Affected:
None

Encoding:
| 0110 | 010a | ffff | ffff |

Description:
Compares the contents of data memory location ‘f’ to the contents of the W by performing an unsigned subtraction.
If the contents of ‘f’ are greater than the contents of WREG, then the fetched instruction is discarded and a NOP is executed instead, making this a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1(2)
Note: 3 cycles if skip and followed by a 2-word instruction.

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation

If skip:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation

If skip and followed by 2-word instruction:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation
No operation No operation No operation No operation

Example:

HERE CPFS GT REG, 0 NGREATER : GREATER :

Before Instruction

PC = Address (HERE) W = ?

After Instruction

If REG > W; PC = Address (GREATER) If REG ≤ W; PC = Address (NGREATER)

CPFS LT

Compare f with W, Skip if f < W

Syntax:
CPFS LT f {,a}

Operands:
0 ≤ f ≤ 255
a ∈ [0,1]

Operation:
(f) – (W),
skip if (f) < (W)
(unsigned comparison)

Status Affected:
None

Encoding:
| 0110 | 000a | ffff | ffff |

Description:
Compares the contents of data memory location ‘f’ to the contents of W by performing an unsigned subtraction.
If the contents of ‘f’ are less than the contents of W, then the fetched instruction is discarded and a NOP is executed instead, making this a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).

Words:
1

Cycles:
1(2)
Note: 3 cycles if skip and followed by a 2-word instruction.

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data No operation

If skip:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation

If skip and followed by 2-word instruction:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation
No operation No operation No operation No operation

Example:

HERE CPFS LT REG, 1 NLESS : LESS :

Before Instruction

PC = Address (HERE) W = ?

After Instruction

If REG < W; PC = Address (LESS) If REG ≥ W; PC = Address (NLESS)

DAW Decimal Adjust W Register

Syntax: DAW
Operands: None
Operation:
If [W<3:0> > 9] or [DC = 1] then,
(W<3:0>) + 6 → W<3:0>;
else,
(W<3:0>) → W<3:0>;

If [W<7:4> + DC > 9] or [C = 1] then,
(W<7:4>) + 6 + DC → W<7:4>;
else,
(W<7:4>) + DC → W<7:4>

Status Affected: C
Encoding:
| 0000 | 0000 | 0000 | 0111 |
Description: DAW adjusts the eight-bit value in W, resulting from the earlier addition of two variables (each in packed BCD format) and produces a correct packed BCD result.
Words: 1
Cycles: 1
Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register W Process Data Write W

Example 1: DAW

Before Instruction
W = A5h
C = 0
DC = 0

After Instruction
W = 05h
C = 1
DC = 0

Example 2:

Before Instruction
W = CEh
C = 0
DC = 0

After Instruction
W = 34h
C = 1
DC = 0

DECF Decrement f

Syntax: DECF f {,d {,a}}
Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]
Operation: (f) – 1 → dest
Status Affected: C, DC, N, OV, Z
Encoding:
| 0000 | 01da | ffff | ffff |
Description: Decrement register ‘f’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back in register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.
Words: 1
Cycles: 1
Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

Example: DECF CNT, 1, 0

Before Instruction
CNT = 01h
Z = 0

After Instruction
CNT = 00h
Z = 1

Figure from the manual

Figure from the manual

Figure from the manual

DECFSZ Decrement f, Skip if 0

Syntax:
DECFSZ f {,d {,a}}

Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]

Operation:
(f) – 1 → dest,
skip if result = 0

Status Affected:
None

Encoding:
| 0010 | 11da | ffff | ffff |

Description:
The contents of register ‘f’ are decremented. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’, the result is placed back in register ‘f’ (default). If the result is ‘0’, the next instruction, which is already fetched, is discarded and a NOP is executed instead, making it a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1(2)
Note: 3 cycles if skip and followed by a 2-word instruction.

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

If skip:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation

If skip and followed by 2-word instruction:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation
No operation No operation No operation No operation

Example:

HERE DECFSZ CNT, 1, 1 GOTO LOOP CONTINUE

Before Instruction
PC = Address (HERE)

After Instruction
CNT = CNT – 1
If CNT = 0;
 PC = Address (CONTINUE)
If CNT ≠ 0;
 PC = Address (HERE + 2)


DCFSNZ Decrement f, Skip if Not 0

Syntax:
DCFSNZ f {,d {,a}}

Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]

Operation:
(f) – 1 → dest,
skip if result ≠ 0

Status Affected:
None

Encoding:
| 0100 | 11da | ffff | ffff |

Description:
The contents of register ‘f’ are decremented. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’, the result is placed back in register ‘f’ (default). If the result is not ‘0’, the next instruction, which is already fetched, is discarded and a NOP is executed instead, making it a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1(2)
Note: 3 cycles if skip and followed by a 2-word instruction.

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

If skip:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation

If skip and followed by 2-word instruction:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation
No operation No operation No operation No operation

Example:

HERE DCFSNZ TEMP, 1, 0 ZERO : NZERO :

Before Instruction
TEMP = ?

After Instruction
TEMP = TEMP – 1,
If TEMP = 0;
 PC = Address (ZERO)
If TEMP ≠ 0;
 PC = Address (NZERO)


Figure from the manual

GOTO Unconditional Branch

Syntax:
GOTO k

Operands:
0 ≤ k ≤ 1048575

Operation:
k → PC<20:1>

Status Affected:
None

Encoding:
1st word (k<7:0>)
2nd word(k<19:8>)

1110 1111 k₇kkk kkkk₀
1111 k₁₉kkk kkkk kkkk₈

Description:
GOTO allows an unconditional branch anywhere within the entire 2-Mbyte memory range. The 20-bit value ‘k’ is loaded into PC<20:1>. GOTO is always a two-cycle instruction.

Words:
2

Cycles:
2

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read literal ‘k’<7:0>, No operation Read literal ‘k’<19:8>, Write to PC
No operation No operation No operation No operation

Example:
GOTO THERE

After Instruction
PC = Address (THERE)

INCF Increment f

Syntax:
INCF f {,d {,a}}

Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]

Operation:
(f) + 1 → dest

Status Affected:
C, DC, N, OV, Z

Encoding:

0010 10da ffff ffff

Description:
The contents of register ‘f’ are incremented. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’, the result is placed back in register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

Example:
INCF CNT, 1, 0

Before Instruction
CNT = FFh
Z = 0
C = ?
DC = ?

After Instruction
CNT = 00h
Z = 1
C = 1
DC = 1

Figure from the manual

INCFSZ Increment f, Skip if 0

Syntax:
INCFSZ f {,d {,a}}

Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]

Operation:
(f) + 1 → dest,
skip if result = 0

Status Affected:
None

Encoding:
| 0011 | 11da | ffff | ffff |

Description:
The contents of register ‘f’ are incremented. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’, the result is placed back in register ‘f’. (default)
If the result is ‘0’, the next instruction, which is already fetched, is discarded and a NOP is executed instead, making it a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1(2)
Note: 3 cycles if skip and followed by a 2-word instruction.

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

If skip:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation

If skip and followed by 2-word instruction:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation
No operation No operation No operation No operation

Example:

HERE INCFSZ CNT, 1, 0 NZERO : ZERO :

Before Instruction
PC = Address (HERE)

After Instruction
CNT = CNT + 1
If CNT = 0;
PC = Address (ZERO)
If CNT ≠ 0;
PC = Address (NZERO)


INFSNZ Increment f, Skip if Not 0

Syntax:
INFSNZ f {,d {,a}}

Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]

Operation:
(f) + 1 → dest,
skip if result ≠ 0

Status Affected:
None

Encoding:
| 0100 | 10da | ffff | ffff |

Description:
The contents of register ‘f’ are incremented. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’, the result is placed back in register ‘f’ (default).
If the result is not ‘0’, the next instruction, which is already fetched, is discarded and a NOP is executed instead, making it a two-cycle instruction.
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words:
1

Cycles:
1(2)
Note: 3 cycles if skip and followed by a 2-word instruction.

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

If skip:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation

If skip and followed by 2-word instruction:

Q1 Q2 Q3 Q4
No operation No operation No operation No operation
No operation No operation No operation No operation

Example:

HERE INFSNZ REG, 1, 0 ZERO : NZERO :

Before Instruction
PC = Address (HERE)

After Instruction
REG = REG + 1
If REG ≠ 0;
PC = Address (NZERO)
If REG = 0;
PC = Address (ZERO)


Figure from the manual

IORLW Inclusive OR Literal with W

Syntax: IORLW k
Operands: 0 ≤ k ≤ 255
Operation: (W) .OR. k → W
Status Affected: N, Z
Encoding:

0000 1001 kkkk kkkk

Description: The contents of W are ORed with the eight-bit literal ‘k’. The result is placed in W.
Words: 1
Cycles: 1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read literal ‘k’ Process Data Write to W

Example: IORLW 35h
Before Instruction
W = 9Ah
After Instruction
W = BFh

IORWF Inclusive OR W with f

Syntax: IORWF f {,d {,a}}
Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]
Operation: (W) .OR. (f) → dest
Status Affected: N, Z
Encoding:

0001 00da ffff ffff

Description: Inclusive OR W with register ‘f’. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’, the result is placed back in register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).
If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.
Words: 1
Cycles: 1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write to destination

Example: IORWF RESULT, 0, 1
Before Instruction
RESULT = 13h
W = 91h
After Instruction
RESULT = 13h
W = 93h

Figure from the manual

LFSR Load FSR

Syntax: LFSR f, k

Operands:

  • 0 ≤ f ≤ 2
  • 0 ≤ k ≤ 4095

Operation: k → FSRf

Status Affected: None

Encoding:

1110 1110 00ff k₁₁kkk
1111 0000 k₇kkk kkkk

Description: The 12-bit literal ‘k’ is loaded into the File Select Register pointed to by ‘f’.

Words: 2

Cycles: 2

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read literal ‘k’ MSB Process Data Write literal ‘k’ MSB to FSRfH
Decode Read literal ‘k’ LSB Process Data Write literal ‘k’ to FSRfL

Example:

LFSR 2, 3ABh

After Instruction

  • FSR2H = 03h
  • FSR2L = ABh

MOVF Move f

Syntax: MOVF f{,d{,a}}

Operands:

  • 0 ≤ f ≤ 255
  • d ∈ [0,1]
  • a ∈ [0,1]

Operation: f → dest

Status Affected: N, Z

Encoding:

0101 00da ffff ffff

Description: The contents of register ‘f’ are moved to a destination dependent upon the status of ‘d’. If ‘d’ is ‘0’, the result is placed in W. If ‘d’ is ‘1’, the result is placed back in register ‘f’ (default). Location ‘f’ can be anywhere in the 256-byte bank.

If ‘a’ is ‘0’, the Access Bank is selected. If ‘a’ is ‘1’, the BSR is used to select the GPR bank (default).

If ‘a’ is ‘0’ and the extended instruction set is enabled, this instruction operates in Indexed Literal Offset Addressing mode whenever f ≤ 95 (5Fh). See Section 26.2.3 “Byte-Oriented and Bit-Oriented Instructions in Indexed Literal Offset Mode” for details.

Words: 1

Cycles: 1

Q Cycle Activity:

Q1 Q2 Q3 Q4
Decode Read register ‘f’ Process Data Write W

Example:

MOVF REG, 0, 0

Before Instruction

  • REG = 22h
  • W = FFh

After Instruction

  • REG = 22h
  • W = 22h

Text converted from the manufacturer's document. A □ marks a character that could not be read in the original. Back to the Microchip PIC18 discussions