Jeu D'instructions Des Microcontrôleurs PIC
Jeu D'instructions Des Microcontrôleurs PIC
Jeu D'instructions Des Microcontrôleurs PIC
Des
Microcontrôleurs
PIC
PIC16F8X
9.0 INSTRUCTION SET SUMMARY The instruction set is highly orthogonal and is grouped
into three basic categories:
Each PIC16CXX instruction is a 14-bit word divided
into an OPCODE which specifies the instruction type • Byte-oriented operations
and one or more operands which further specify the • Bit-oriented operations
operation of the instruction. The PIC16CXX instruction • Literal and control operations
set summary in Table 9-2 lists byte-oriented, bit-ori-
All instructions are executed within one single instruc-
ented, and literal and control operations. Table 9-1
tion cycle, unless a conditional test is true or the pro-
shows the opcode field descriptions.
gram counter is changed as a result of an instruction.
For byte-oriented instructions, 'f' represents a file reg- In this case, the execution takes two instruction cycles
ister designator and 'd' represents a destination desig- with the second cycle executed as a NOP. One instruc-
nator. The file register designator specifies which file tion cycle consists of four oscillator periods. Thus, for
register is to be used by the instruction. an oscillator frequency of 4 MHz, the normal instruction
The destination designator specifies where the result of execution time is 1 µs. If a conditional test is true or the
the operation is to be placed. If 'd' is zero, the result is program counter is changed as a result of an instruc-
placed in the W register. If 'd' is one, the result is placed tion, the instruction execution time is 2 µs.
in the file register specified in the instruction. Table 9-2 lists the instructions recognized by the
For bit-oriented instructions, 'b' represents a bit field MPASM assembler.
designator which selects the number of the bit affected Figure 9-1 shows the general formats that the instruc-
by the operation, while 'f' represents the number of the tions can have.
file in which the bit is located.
Note: To maintain upward compatibility with
For literal and control operations, 'k' represents an future PIC16CXX products, do not use the
eight or eleven bit constant or literal value. OPTION and TRIS instructions.
TABLE 9-1 OPCODE FIELD All examples use the following format to represent a
DESCRIPTIONS hexadecimal number:
Description: The contents of the W register are Description: The contents of W register are
added to the eight bit literal 'k' and the AND’ed with the eight bit literal 'k'. The
result is placed in the W register. result is placed in the W register.
Words: 1 Words: 1
Cycles: 1 Cycles: 1
Q Cycle Activity: Q1 Q2 Q3 Q4 Q Cycle Activity: Q1 Q2 Q3 Q4
Decode Read Process Write to Decode Read Process Write to
literal 'k' data W literal "k" data W
Example CLRWDT
Before Instruction
WDT counter = ?
After Instruction
WDT counter = 0x00
WDT prescaler= 0
TO = 1
PD = 1
Description: GOTO is an unconditional branch. The Description: The contents of register 'f' are incre-
eleven bit immediate value is loaded mented. If 'd' is 0 the result is placed in
into PC bits <10:0>. The upper bits of the W register. If 'd' is 1 the result is
PC are loaded from PCLATH<4:3>.
GOTO is a two cycle instruction. placed back in register 'f'.
Words: 1 Words: 1
Cycles: 2 Cycles: 1
Cycles: 1(2)
Example IORLW 0x35
Q Cycle Activity: Q1 Q2 Q3 Q4
Before Instruction
Decode Read Process Write to
W = 0x9A
register 'f' data destination
After Instruction
If Skip: (2nd Cycle) W = 0xBF
Z = 1
Q1 Q2 Q3 Q4
No-Opera No-Opera No-Operati
No-Operat tion tion on
ion
MOVWF Move W to f
MOVF Move f
Syntax: [ label ] MOVWF f
Syntax: [ label ] MOVF f,d
Operands: 0 ≤ f ≤ 127
Operands: 0 ≤ f ≤ 127
d ∈ [0,1] Operation: (W) → (f)
Operation: (f) → (destination) Status Affected: None
Status Affected: Z Encoding: 00 0000 1fff ffff
Encoding: 00 1000 dfff ffff Description: Move data from W register to register
'f'.
Description: The contents of register f is moved to a
destination dependant upon the status Words: 1
of d. If d = 0, destination is W register. If
Cycles: 1
d = 1, the destination is file register f
itself. d = 1 is useful to test a file regis- Q Cycle Activity: Q1 Q2 Q3 Q4
ter since status flag Z is affected. Decode Read Process Write
Words: 1 register data register 'f'
'f'
Cycles: 1
Q Cycle Activity: Q1 Q2 Q3 Q4 Example MOVWF OPTION_REG
Decode Read Process Write to Before Instruction
register data destination
OPTION = 0xFF
'f'
W = 0x4F
After Instruction
Example MOVF FSR, 0 OPTION = 0x4F
After Instruction W = 0x4F
W = value in FSR register
Z =1
Example RETFIE
After Interrupt
PC = TOS
GIE = 1
OPTION Load Option Register
Syntax: [ label ] OPTION
Operands: None
Operation: (W) → OPTION
Status Affected: None
Encoding: 00 0000 0110 0010
Description: The contents of the W register are
loaded in the OPTION register. This
instruction is supported for code com-
patibility with PIC16C5X products.
Since OPTION is a readable/writable
register, the user can directly address
it.
Words: 1
Cycles: 1
Example
To maintain upward compatibility
with future PIC16CXX products,
do not use this instruction.
1st Cycle Decode Read No-Opera Write to W, 2nd Cycle No-Opera No-Opera No-Opera
literal 'k' tion Pop from No-Operat tion tion tion
the Stack ion
Before Instruction
W = 0x07
After Instruction
W = value of k8
RLF Rotate Left f through Carry RRF Rotate Right f through Carry
Syntax: [ label ] RLF f,d Syntax: [ label ] RRF f,d
Operands: 0 ≤ f ≤ 127 Operands: 0 ≤ f ≤ 127
d ∈ [0,1] d ∈ [0,1]
Operation: See description below Operation: See description below
Status Affected: C Status Affected: C
Encoding: 00 1101 dfff ffff Encoding: 00 1100 dfff ffff
Description: The contents of register 'f' are rotated Description: The contents of register 'f' are rotated
one bit to the left through the Carry one bit to the right through the Carry
Flag. If 'd' is 0 the result is placed in the Flag. If 'd' is 0 the result is placed in the
W register. If 'd' is 1 the result is stored W register. If 'd' is 1 the result is placed
back in register 'f'. back in register 'f'.
C Register f C Register f
Words: 1 Words: 1
Cycles: 1 Cycles: 1
Q Cycle Activity: Q1 Q2 Q3 Q4 Q Cycle Activity: Q1 Q2 Q3 Q4
Decode Read Process Write to Decode Read Process Write to
register data destination register data destination
'f' 'f'