44.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 a few instructions that require two- or three-program memory locations.

Each single-word instruction is a 16-bit word divided into an opcode that specifies the instruction type and one or more operands, which further specifies 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 44-2 lists byte-oriented, bit-oriented, literal and control operations. Table 44-1 shows the opcode field descriptions.

Most byte-oriented instructions have three operands:

  • The file register (specified by ‘f’)
  • The destination of the result (specified by ‘d’)
  • 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:

  • The file register (specified by ‘f’)
  • The bit in the file register (specified by ‘b’)
  • 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 a few two- or three-word instructions. These instructions were made two- or three-words to contain the required information in 32 or 48 bits. In the second and third words, the four MSbs are ‘1’s. If this second or third 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 two-word instructions execute in two instruction cycles and three-word instructions execute in three 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) take 3 μs.

Figure 44-1, Figure 44-2 and Figure 44-3 show 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 44-2, lists the standard instructions recognized by the Microchip MPASMTM Assembler.

The Standard Instruction Set section provides a description of each instruction.

Table 44-1. Opcode Field Descriptions
FieldDescription
a

RAM access bit
a = 0: RAM location in Access RAM (BSR register is ignored)
a = 1: RAM bank is specified by BSR register (default)

ACCESS ACCESS = 0: RAM access bit symbol
BANKED BANKED = 1: RAM access bit symbol
bbb Bit address within an 8-bit file register (0 to 7)
BSR Bank Select Register (BSR). Used to select the current RAM bank.
d

Destination select bit
d = 0: store result in WREG
d = 1: store result in file register f (default)

dest Destination: either the WREG register or the specified register file location
f 8-bit register file address (00h to FFh)
fn FSR Number (0 to 2)
fs 12-bit register file address (000h to FFFh) or 14-bit register file address (0000h to 3FFFh). This is the source address.
fd 12-bit register file address (000h to FFFh) or 14-bit register file address (0000h to 3FFFh). This is the destination address.
zs 7-bit literal offset for FSR2 to used as register file address (000h to FFFh). This is the source address.
zd 7-bit literal offset for FSR2 to used as register file address (000h to FFFh). This is the destination address.
k Literal field, constant data or label (may be either a 6-bit, 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 (two’s complement number) for relative branch instructions or the direct address for call/branch and return instructions
PRODH Product of multiply high byte
PRODL Product of multiply low byte
s

Fast Call/Return mode select bit
s = 0: do not update into/from shadow registers (default)
s = 1: certain registers loaded into/from shadow registers (Fast mode)

u Unused or unchanged
W W = 0: Destination select bit symbol
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.
TBLPTR 21-bit Table Pointer (points to a program memory location)
TABLAT 8-bit table latch
TOS Top-of-stack (TOS)
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
GIE Global Interrupt Enable bit
WDT Watchdog Timer
TO Time-Out bit
PD Power-Down bit
C, DC, Z, OV, N ALU Status bits: Carry, Digit Carry, Zero, Overflow, Negative
{ } Optional argument
[ ] Indexed address
( ) Contents
< > Register bit field
[expr]<n> Specifies bit n of the register indicated by pointer expr
Assigned to
In the set of
italics User defined term (font is Courier)
Figure 44-1. General Format for Byte-Oriented Instructions
Figure 44-2. General Format for Bit-Oriented and Literal Instructions
Figure 44-3. General Format for Control Instructions
Table 44-2. Standard Instruction Set
Mnemonic,

Operands

DescriptionCycles16-Bit Instruction WordStatus

Affected

Notes
MSbLSb
BYTE-ORIENTED FILE REGISTER INSTRUCTIONS
ADDWFf, d, aAdd WREG and f10010 01da ffff ffff C, DC, Z, OV, N1
ADDWFCf, d, aAdd WREG and Carry bit to f1 0010 00da ffff ffff C, DC, Z, OV, N1
ANDWFf, d, aAND WREG with f1 0001 01da ffff ffff Z, N1
CLRFf, aClear f1 0110 101a ffff ffff Z
COMFf, d, aComplement f1 0001 11da ffff ffff Z, N1
DECFf, d, aDecrement f1 0000 01da ffff ffff C, DC, Z, OV, N1
INCFf, d, aIncrement f1 0010 10da ffff ffff C, DC, Z, OV, N1
IORWFf, d, aInclusive OR WREG with f1 0001 00da ffff ffff Z, N1
MOVFf, d, aMove f to WREG or f1 0101 00da ffff ffff Z, N1
MOVFFfs, fdMove fs (12-bit source)

to fd (12-bit destination)

2 1100 fsfsfsfs fsfsfsfs fsfsfsfs None1, 3, 4
1111 fdfdfdfd fdfdfdfd fdfdfdfd
MOVFFLfs, fdMove fs (14-bit source)

to fd (14-bit destination)

3 0000 0000 0110 fsfsfsfs None1, 3
1111 fsfsfsfs fsfsfsfs fsfsfdfd
1111 fdfdfdfd fdfdfdfd fdfdfdfd
MOVWFf, aMove WREG to f1 0110 111a ffff ffff None
MULWFf, aMultiply WREG with f1 0000 001a ffff ffff None1
NEGFf, aNegate f1 0110 110a ffff ffff C, DC, Z, OV, N1
RLCFf, d, aRotate Left f through Carry1 0011 01da ffff ffff C, Z, N1
RLNCFf, d, aRotate Left f (No Carry)1 0100 01da ffff ffff Z, N1
RRCFf, d, aRotate Right f through Carry1 0011 00da ffff ffff C, Z, N1
RRNCFf, d, aRotate Right f (No Carry)1 0100 00da ffff ffff Z, N1
SETFf, aSet f1 0110 100a ffff ffff None
SUBFWBf, d, aSubtract f from WREG with 
Borrow1 0101 01da ffff ffff C, DC, Z, OV, N1
SUBWFf, d, aSubtract WREG from f1 0101 11da ffff ffff C, DC, Z, OV, N1
SUBWFBf, d, aSubtract WREG from f with Borrow1 0101 10da ffff ffff C, DC, Z, OV, N1
SWAPFf, d, aSwap nibbles in f1 0011 10da ffff ffff None1
XORWFf, d, aExclusive OR WREG with f1 0001 10da ffff ffff Z, N1
BYTE-ORIENTED SKIP INSTRUCTIONS
CPFSEQf, aCompare f with WREG, skip if =1 – 4 0110 001a ffff ffff None1, 2
CPFSGTf, aCompare f with WREG, skip if >1 – 4 0110 010a ffff ffff None1, 2
CPFSLTf, aCompare f with WREG, skip if <1 – 4 0110 000a ffff ffff None1, 2
DECFSZf, d, aDecrement f, Skip if 01 – 4 0010 11da ffff ffff None1, 2
DCFSNZf, d, aDecrement f, Skip if Not 01 – 4 0100 11da ffff ffff None1, 2
INCFSZf, d, aIncrement f, Skip if 01 – 4 0011 11da ffff ffff None1, 2
INFSNZf, d, aIncrement f, Skip if Not 01 – 4 0100 10da ffff ffff None1, 2
TSTFSZf, aTest f, skip if 01 – 4 0110 011a ffff ffff None1, 2
BIT-ORIENTED FILE REGISTER INSTRUCTIONS
BCFf, b, aBit Clear f1 1001 bbba ffff ffff None1
BSFf, b, aBit Set f1 1000 bbba ffff ffff None1
BTGf, b, aBit Toggle f1 0111 bbba ffff ffff None1
BIT-ORIENTED SKIP INSTRUCTIONS
BTFSCf, b, aBit Test f, Skip if Clear1 – 4 1011 bbba ffff ffff None1, 2
BTFSSf, b, aBit Test f, Skip if Set1 – 4 1010 bbba ffff ffff None1, 2
CONTROL INSTRUCTIONS
BCnBranch if Carry1 – 2 1110 0010 nnnn nnnn

None

2
BNnBranch if Negative1 – 2 1110 0110 nnnn nnnn

None

2
BNCnBranch if Not Carry1 – 2 1110 0011 nnnn nnnn

None

2
BNNnBranch if Not Negative1 – 2 1110 0111 nnnn nnnn

None

2
BNOVnBranch if Not Overflow1 – 2 1110 0101 nnnn nnnn

None

2
BNZnBranch if Not Zero1 – 2 1110 0001 nnnn nnnn

None

2
BOVnBranch if Overflow1 – 2 1110 0100 nnnn nnnn

None

2
BRAnBranch Unconditionally2 1101 0nnn nnnn nnnn

None

2
BZnBranch if Zero1 – 2 1110 0000 nnnn nnnn

None

2
CALLk, sCall subroutine2 1110 110s kkkk kkkk

None

2, 3
1111 kkkk kkkk kkkk
CALLWCall subroutine using WREG2 0000 0000 0001 0100 None2
GOTOkGo to address2 1110 1111 kkkk kkkk None3
1111 kkkk kkkk kkkk
RCALLnRelative Call2 1101 1nnn nnnn nnnn None2
RETFIEsReturn from interrupt enable2 0000 0000 0001 000s INTCONx STAT bits2
RETLWkReturn with literal in WREG2 0000 1100 kkkk kkkk None2
RETURNsReturn from Subroutine2 0000 0000 0001 001s None2
INHERENT INSTRUCTIONS
CLRWDTClear Watchdog Timer1 0000 0000 0000 0100 TO, PD
DAWDecimal Adjust WREG1 0000 0000 0000 0111 C
NOPNo Operation1 0000 0000 0000 0000 None
NOPNo Operation1 1111 xxxx xxxx xxxx None3
POP

Pop top of return stack (TOS)1 0000 0000 0000 0110 None
PUSHPush top of return stack (TOS)1 0000 0000 0000 0101 None
RESETSoftware device Reset1 0000 0000 1111 1111 All
SLEEPGo into Standby mode1 0000 0000 0000 0011 TO, PD
LITERAL INSTRUCTIONS
ADDFSRfn, kAdd FSR (fn) with literal (k)111101000fnfnkkkkkkNone
ADDLWkAdd literal and WREG1 0000 1111 kkkk kkkk C, DC, Z, OV, N
ANDLWkAND literal with WREG1 0000 1011 kkkk kkkk Z, N
IORLWkInclusive OR literal with WREG1 0000 1001 kkkk kkkk Z, N
LFSRfn, kLoad FSR(fn) with a 14-bit literal (k)2 1110 1110 00fnfn kkkk None3
1111 00kk kkkk kkkk
MOVLBkMove literal to BSR<5:0>1 0000 0001 00kk kkkk None
MOVLWkMove literal to WREG1 0000 1110 kkkk kkkk None
MULLWkMultiply literal with WREG1 0000 1101 kkkk kkkk None
RETLWkReturn with literal in WREG2 0000 1100 kkkk kkkk None
SUBFSRfn, kSubtract literal (k) from FSR (fn)111101001fnfnkkkkkkNone
SUBLWkSubtract WREG from literal1 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 INSTRUCTIONS
TBLRD*Table Read2 0000 0000 0000 1000 None
TBLRD*+Table Read with post-increment2 0000 0000 0000 1001 None
TBLRD*-Table Read with post-decrement2 0000 0000 0000 1010 None
TBLRD+*Table Read with pre-increment2 0000 0000 0000 1011 None
TBLWT*Table Write2 0000 0000 0000 1100 None
TBLWT*+Table Write with post-increment2 0000 0000 0000 1101 None
TBLWT*-Table Write with post-decrement2 0000 0000 0000 1110 None
TBLWT+*Table Write with pre-increment2 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 input and is driven low by an external device, the data will be written back with a ‘0’.
  2. If Program Counter (PC) is modified or a conditional test is true, the instruction requires two cycles. The second cycle is executed as a NOP.
  3. Some instructions are multi-word instructions. The extra words 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.
  4. fs and fd do not cover the full memory range. 2 MSbs of bank selection are forced to 0b00 to limit the range of these instructions to the lower 4k addressing space.