PIC16F7X
For example, a “clrf PORTB” instruction will read
PORTB, clear all the data bits, then write the result
back to PORTB. This example would have the unin-
tended result that the condition that sets the RBIF flag
would be cleared for pins configured as inputs and
using the PORTB interrupt-on-change feature.
13.0 INSTRUCTION SET SUMMARY
The PIC16 instruction set is highly orthogonal and is
comprised of three basic categories:
• Byte-oriented operations
• Bit-oriented operations
• Literal and control operations
TABLE 13-1: OPCODE FIELD
DESCRIPTIONS
Each PIC16 instruction is a 14-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 formats for each of the categories
are presented in Figure 13-1, while the various opcode
fields are summarized in Table 13-1.
Field
Description
f
W
b
k
x
Register file address (0x00 to 0x7F)
Working register (accumulator)
Bit address within an 8-bit file register
Literal field, constant data or label
Table 13-2 lists the instructions recognized by the
MPASMTM Assembler. A complete description of each
instruction is also available in the PICmicro™ Mid-
Range Reference Manual (DS33023).
Don't care location (= 0or 1).
The assembler will generate code with x = 0.
It is the recommended form of use for
compatibility with all Microchip software tools.
For byte-oriented instructions, ‘f’ represents a file reg-
ister designator and ‘d’ represents a destination desig-
nator. The file register designator specifies which file
register is to be used by the instruction.
d
Destination select; d = 0: store result in W,
d = 1: store result in file register f.
Default is d = 1.
The destination designator specifies where the result of
the operation is to be placed. If ‘d’ is zero, the result is
placed in the W register. If ‘d’ is one, the result is placed
in the file register specified in the instruction.
PC
TO
PD
Program Counter
Time-out bit
Power-down bit
For bit-oriented instructions, ‘b’ represents a bit field
designator, which selects the bit affected by the opera-
tion, while ‘f’ represents the address of the file in which
the bit is located.
FIGURE 13-1:
GENERAL FORMAT FOR
INSTRUCTIONS
Byte-oriented file register operations
13
For literal and control operations, ‘k’ represents an
eight- or eleven-bit constant or literal value
8
7
6
0
OPCODE
d
f (FILE #)
One instruction cycle consists of four oscillator periods;
for an oscillator frequency of 4 MHz, this gives a normal
instruction execution time of 1 µs. All instructions are
executed within a single instruction cycle, unless a con-
ditional test is true, or the program counter is changed
as a result of an instruction. When this occurs, the exe-
cution takes two instruction cycles, with the second
cycle executed as a NOP.
d = 0 for destination W
d = 1 for destination f
f = 7-bit file register address
Bit-oriented file register operations
13 10 9
b (BIT #)
7
6
0
OPCODE
f (FILE #)
b = 3-bit bit address
f = 7-bit file register address
Note: To maintain upward compatibility with
future PIC16F7X products, do not use the
OPTIONand TRISinstructions.
Literal and control operations
All instruction examples use the format ‘0xhh’ to repre-
sent a hexadecimal number, where ‘h’ signifies a hexa-
decimal digit.
General
13
8
7
0
0
OPCODE
k (literal)
13.1 READ-MODIFY-WRITE
OPERATIONS
k = 8-bit immediate value
CALLand GOTOinstructions only
13 11 10
OPCODE
k = 11-bit immediate value
Any instruction that specifies a file register as part of
the instruction performs a Read-Modify-Write (R-M-W)
operation. The register is read, the data is modified,
and the result is stored according to either the instruc-
tion, or the destination designator ‘d’. A read operation
is performed on a register even if the instruction writes
to that register.
k (literal)
2002 Microchip Technology Inc.
DS30325B-page 105