Instruction Sets – PIC
Done by,
Priyanga KR,
Assistant Professor,
Department of ECE,
Avinashilingam Institute.
• Complete set: 35 instructions.
• MC Architecture: RISC microcontroller.
Instruction Types:
1. Data Processing Operations:
– Copy data between registers.
– Manipulate data in a single register.
2. Arithmetic and Logic operations:
3. Bit Operation:
4. Program Sequence Control Operations:
– Unconditional Jump.
– Conditional Jump.
– Call.
– Control.
Status Register
Addressing modes
• The way by which the address of the operand
are specified in the instruction.
• Types
• Direct Addressing Modes
• Indirect Addressing Modes
• Immediate Addressing Modes
Direct Addressing Modes
Immediate Addressing modes
MOVLW 43h
Goto loop
Word list
• f - any memory location in a microcontroller
• W - work register
• b - bit position in 'f' register
• d - destination bit
• label group of eight characters which marks the
beginning of a part of the program
• TOS - top of stack
• [ ] - option
• < > - bit position inside register
Data Processing Operations
• To move or change the value (bits) from one
location to another
1. MOVLW
Syntax: Label MOVLW k
Description: 8 bit constant
is written in W reg.
Operation: k to (W)
Operand: 0 < k < 255
No. of words: 1
No. cycles: 1
Flags: Nil
2. MOVWF
Syntax: Label MOVWF f
Description: Content of W
is copied into f register
(flag register).
Operation: W to (f) (W
register to Flag register)
Operand: 0 < f < 127
No. of words: 1
No. cycles: 1
Flags: Nil
3. MOVF
•Syntax: Label MOVF f, d
•Description: Content of f
is copied into destination.
If d = 0, the destination is
W register
If d = 1, the destination is f
register
•Operation: F to (D)
•Operand: 0 < k < 127
•No. of words: 1
•No. cycles: 1
•Flags: Z
4. CLRW
•Syntax: Label CLRW
•Description: Zero is
copied into W register
Z flag in status register is
set to one
•Operation: 0 to (W)
•Operand: nil
•No. of words: 1
•No. cycles: 1
•Flags: Z
5. SWAPF
•Syntax: Label SWAPF f, d
•Description: Upper,
Lower nibbles are
exchanged
If d = 0, the destination is
W register & If d = 1, the
destination is f register
•Operation: f (0:3) to
d(4:7) and f(4:7) to d(0:3)
•Operand: 0 < f < 127
•No. of words: 1
•No. cycles: 1
•Flags: —
6. CLRF f
Syntax: Label CLRF f
Description: Zero is copied
into f register
Z flag in status register is
set to one
Operation: 0 to (f)
Operand: nil
No. of words: 1
No. cycles: 1
Flags: Z
Arithmetic and Logic operations
• The arithmetic operations are addition (ADD),
subtraction (SUB), multiplication (MUL),
division (DIV) and logical operations are AND,
OR, NOT, XOR, and so on.
1. ADDLW
Syntax: Label ADDLW k
Description: Given
constant is added with W
reg.
Operation: (w) + k to w
Operand: 0 < k < 255
No. of words: 1
No. cycles: 1
Flags: C, DC, Z
2) ADDWF
Syntax: Label ADDWF f, d
Description: Add W reg.
content with f register
Operation:
(w) + (f) to w if d = 0 and
(w) + (f) to f if d = 1
Operand: 0 < f < 127
No. of words: 1
No. cycles: 1
Flags: C, DC, Z
3) SUBLW
•Syntax: Label SUBLW k
•Description: W reg.
content is subtracted from
k
•Operation: k – (w) to w
•Operand: 0 < k < 255
•No. of words: 1
•No. cycles: 1
•Flags: C, DC, Z
4) SUBWF
•Syntax: Label SUBWF f
•Description: W reg.
content is subtracted from
f
•Operation:
f – (w) to w if d = 0 and
f – (w) to f if d = 1
•Operand: 0 < f < 127
•No. of words: 1
•No. cycles: 1
•Flags: C, DC, Z
5) ANDLW
•Syntax: Label ANDLW k
•Description: Given
constant is .and. with W
reg.
•Operation: (w) .and. k to
w
•Operand: 0 < k < 255
•No. of words: 1
•No. cycles: 1
•Flags: Z
6) IORLW
•Syntax: Label IORLW k
•Description: Given
constant is .or. with W
reg.
•Operation: (w) .or. k to w
•Operand: 0 < k < 255
•No. of words: 1
•No. cycles: 1
•Flags: Z
7) IORWF
Logic OR the W reg. with f
•Syntax: Label IORWF f, d
•Description: W reg. is .or.
with f reg.
•Operation:
(w) .and. f to w, if d = 0
(w) .and. f to f, if d = 1
•Operand: 0 < f < 127
•No. of words: 1
•No. cycles: 1
•Flags: Z
8 ) XORLW
•Syntax: Label XORLW k
•Description: Given
constant is .XOR. with W
reg.
•Operation: (w) .xor. k to
w
•Operand: 0 < k < 255
•No. of words: 1
•No. cycles: 1
•Flags: Z
9) XORWF
•Syntax: Label XORWF f, d
•Description: W reg. is
.xor. with f reg.
•Operation:
(w) .and. f to w, if d = 0
(w) .and. f to f, if d = 1
•Operand: 0 < f < 127
•No. of words: 1
•No. cycles: 1
•Flags: Z
10) INCF
•Syntax: Label INCF f, d
•Description: Increment
the content of f register
•Operation:
(f) + 1 to w, if d = 0 and
(f) + 1 to f, if d = 1
•Operand: 0 < f < 127
•No. of words: 1
•No. cycles: 1
•Flags: Z
11) DECF
•Syntax: Label DECF f, d
•Description: Decrement
the content of f register
•Operation:
(f) – 1 to w, if d = 0 and
(f) – 1 to f, if d = 1
•Operand: 0 < f < 127
•No. of words: 1
•No. cycles: 1
•Flags: Z
12) RLF
•Syntax: Label RLF f, d
•Description: Rotate f
content left through Carry
•Operation:
Result to w, if d = 0 and
Result to f, if d = 1
•Operand: 0 < f < 127
•No. of words: 1
•No. cycles: 1
•Flags: C
13) RRF
•Syntax: Label RRF f, d
•Description: Rotate f
content right through
Carry
•Operation:
Result to w, if d = 0 and
Result to f, if d = 1
•Operand: 0 < f < 127
•No. of words: 1
•No. cycles: 1
•Flags: C
14) COMF
•Syntax: Label COMF f, d
•Description: Complement
the register content
•Operation:
Result to w, if d = 0 and
Result to f, if d = 1
•Operand: 0 < f < 127
•No. of words: 1
•No. cycles: 1
•Flags: Z
Bit Operation
1)BCF
Bit clearing flag or bit
clearing command
•Syntax: Label BCF f, b
•Description: Reset the
specified bit of register f
•Operation: Result to f
•Operand: 0 < f < 127 and
0 < b < 7
•No. of words: 1
•No. cycles: 1
•Flags: nil
2 ) BSF
Inversing operation of
BCF.
•Syntax: Label BSF f, b
•Description: Set the
specified bit of register f
•Operation: Result to f
•Operand: 0 < f < 127 and
0 < b < 7
•No. of words: 1
•No. cycles: 1
•Flags: nil
Program Sequence Control Operations:
1) BTFSC
•Current program flow.
•Syntax: Label BTFSC f, b
•Description: Test the specified
bit of register f, skip the next
instruction if it is zero
•Operation: Skip the next
instruction if f (b) = 0
•Operand: 0 < f < 127 and 0 < b
< 7
•No. of words: 1
•No. cycles: 1 or 2 depends on
bit value
•Flags: NIL
2) BTFSS
•Program flow control
instruction.
•Syntax: Label BTFSS f, b
•Description: Test the specified
bit of register f, skip the next
instruction if it is one
•Operation: Skip the next
instruction if f (b) = 1
•Operand: 0 < f < 127 and 0 < b
< 7
•No. of words: 1
•No. cycles: 1 or 2 depends on
bit value
•Flags: nil
3) INCFSZ
•INCFSZ is a content increment
command
•Syntax: Label INCFSZ f, d
•Description: Increment the f
content, skip the next
instruction if f is zero
•Operation: Skip the next
instruction if f = zero
•Operand: (f) + 1 = w if d = 0
and (f) + 1 = f if d = 1
•No. of words: 1
•No. cycles: 1 or 2 depends on
bit value
•Flags: nil
4) DECFSZ
•DECFSZ command Decrement
f content
•Syntax: Label DECFSZ f, d
•Description: Decrement the f
content, skip the next
instruction if f is zero
•Operation: Skip the next
instruction if f = zero
•Operand: (f) – 1 = w if d = 0
and (f) – 1 = f if d = 1
•No. of words: 1
•No. cycles: 1 or 2 depends on
bit value
•Flags: nil
5) GOTO
•Syntax: Label GOTO Label
•Description:
Unconditional jump to
specified label
•Operation: k to PC(10:0),
PCLATH(4:3) to PC(12:11)
•Operand: 0 < k < 2048
•No. of words: 1
•No. cycles: 2
•Flags: nil
6) CALL
•Syntax: Label CALL Label
•Description:
Unconditional call the
label
•Operation: (PC) + 1 to Top
of stack, k to PC(10:0),
PCLATH(4:3) to PC(12:11)
•Operand: 0 < k < 2048
•No. of words: 1
•No. cycles: 2
•Flags: nil
7) RETURN
•Syntax: Label RETURN
•Description:
Unconditional return from
subroutine
•Operation: Top of stack
to (PC)
•Operand: nil
•No. of words: 1
•No. cycles: 2
•Flags: nil
8) RETLW
•Syntax: Label RETLW k
•Description:
Unconditional return from
subroutine
•Operation: Top of stack
to (PC) and k loaded in w
register
•Operand: 0 < k < 255
•No. of words: 1
•No. cycles: 2
•Flags: nil
9) RETFIE
•Syntax: Label RETFIE
•Description:
Unconditional return from
subroutine
•Operation: Top of stack
to (PC) and Global
Interrupt bit is enabled
•Operand: nil
•No. of words: 1
•No. cycles: 2
•Flags: nil
Other Instructions in
PIC
1) NOP
•Syntax: Label NOP
•Description: No
operation
•Operation: nil
•Operand: nil
•No. of words: 1
•No. cycles: 1
•Flags: nil
2) CLRWDT
•Initialize watchdog timer
feature .
•Syntax: Label CLRWDT
•Description: Watchdog
timer and pre-scalar is
reset and TO and PD are
set
•Operation: 0 to WDT, 0 to
pre-scalar and Status bits
TO and PD are set
•Operand: TO and PD
•No. of words: 1
•No. cycles: 1
•Flags: nil
3) SLEEP
•Initialize Standby mode.
•Syntax: Label SLEEP
•Description: Goes into
low consumption, OSC is
stopped, Watchdog timer
and pre-scalar is reset and
TO and PD bits are set
•Operation: 0 to WDT, 0 to
pre-scalar and Status bits,
TO is set and PD is reset
•Operand: TO and PD
•No. of words: 1
•No. cycles: 1
•Flags: nil

Instruction sets picc done by Priyanga KR

  • 1.
    Instruction Sets –PIC Done by, Priyanga KR, Assistant Professor, Department of ECE, Avinashilingam Institute.
  • 2.
    • Complete set:35 instructions. • MC Architecture: RISC microcontroller. Instruction Types: 1. Data Processing Operations: – Copy data between registers. – Manipulate data in a single register. 2. Arithmetic and Logic operations: 3. Bit Operation: 4. Program Sequence Control Operations: – Unconditional Jump. – Conditional Jump. – Call. – Control.
  • 3.
  • 4.
    Addressing modes • Theway by which the address of the operand are specified in the instruction. • Types • Direct Addressing Modes • Indirect Addressing Modes • Immediate Addressing Modes
  • 5.
  • 7.
  • 8.
    Word list • f- any memory location in a microcontroller • W - work register • b - bit position in 'f' register • d - destination bit • label group of eight characters which marks the beginning of a part of the program • TOS - top of stack • [ ] - option • < > - bit position inside register
  • 9.
    Data Processing Operations •To move or change the value (bits) from one location to another
  • 10.
    1. MOVLW Syntax: LabelMOVLW k Description: 8 bit constant is written in W reg. Operation: k to (W) Operand: 0 < k < 255 No. of words: 1 No. cycles: 1 Flags: Nil 2. MOVWF Syntax: Label MOVWF f Description: Content of W is copied into f register (flag register). Operation: W to (f) (W register to Flag register) Operand: 0 < f < 127 No. of words: 1 No. cycles: 1 Flags: Nil
  • 11.
    3. MOVF •Syntax: LabelMOVF f, d •Description: Content of f is copied into destination. If d = 0, the destination is W register If d = 1, the destination is f register •Operation: F to (D) •Operand: 0 < k < 127 •No. of words: 1 •No. cycles: 1 •Flags: Z 4. CLRW •Syntax: Label CLRW •Description: Zero is copied into W register Z flag in status register is set to one •Operation: 0 to (W) •Operand: nil •No. of words: 1 •No. cycles: 1 •Flags: Z
  • 12.
    5. SWAPF •Syntax: LabelSWAPF f, d •Description: Upper, Lower nibbles are exchanged If d = 0, the destination is W register & If d = 1, the destination is f register •Operation: f (0:3) to d(4:7) and f(4:7) to d(0:3) •Operand: 0 < f < 127 •No. of words: 1 •No. cycles: 1 •Flags: — 6. CLRF f Syntax: Label CLRF f Description: Zero is copied into f register Z flag in status register is set to one Operation: 0 to (f) Operand: nil No. of words: 1 No. cycles: 1 Flags: Z
  • 13.
    Arithmetic and Logicoperations • The arithmetic operations are addition (ADD), subtraction (SUB), multiplication (MUL), division (DIV) and logical operations are AND, OR, NOT, XOR, and so on.
  • 14.
    1. ADDLW Syntax: LabelADDLW k Description: Given constant is added with W reg. Operation: (w) + k to w Operand: 0 < k < 255 No. of words: 1 No. cycles: 1 Flags: C, DC, Z 2) ADDWF Syntax: Label ADDWF f, d Description: Add W reg. content with f register Operation: (w) + (f) to w if d = 0 and (w) + (f) to f if d = 1 Operand: 0 < f < 127 No. of words: 1 No. cycles: 1 Flags: C, DC, Z
  • 15.
    3) SUBLW •Syntax: LabelSUBLW k •Description: W reg. content is subtracted from k •Operation: k – (w) to w •Operand: 0 < k < 255 •No. of words: 1 •No. cycles: 1 •Flags: C, DC, Z 4) SUBWF •Syntax: Label SUBWF f •Description: W reg. content is subtracted from f •Operation: f – (w) to w if d = 0 and f – (w) to f if d = 1 •Operand: 0 < f < 127 •No. of words: 1 •No. cycles: 1 •Flags: C, DC, Z
  • 16.
    5) ANDLW •Syntax: LabelANDLW k •Description: Given constant is .and. with W reg. •Operation: (w) .and. k to w •Operand: 0 < k < 255 •No. of words: 1 •No. cycles: 1 •Flags: Z 6) IORLW •Syntax: Label IORLW k •Description: Given constant is .or. with W reg. •Operation: (w) .or. k to w •Operand: 0 < k < 255 •No. of words: 1 •No. cycles: 1 •Flags: Z
  • 17.
    7) IORWF Logic ORthe W reg. with f •Syntax: Label IORWF f, d •Description: W reg. is .or. with f reg. •Operation: (w) .and. f to w, if d = 0 (w) .and. f to f, if d = 1 •Operand: 0 < f < 127 •No. of words: 1 •No. cycles: 1 •Flags: Z 8 ) XORLW •Syntax: Label XORLW k •Description: Given constant is .XOR. with W reg. •Operation: (w) .xor. k to w •Operand: 0 < k < 255 •No. of words: 1 •No. cycles: 1 •Flags: Z
  • 18.
    9) XORWF •Syntax: LabelXORWF f, d •Description: W reg. is .xor. with f reg. •Operation: (w) .and. f to w, if d = 0 (w) .and. f to f, if d = 1 •Operand: 0 < f < 127 •No. of words: 1 •No. cycles: 1 •Flags: Z 10) INCF •Syntax: Label INCF f, d •Description: Increment the content of f register •Operation: (f) + 1 to w, if d = 0 and (f) + 1 to f, if d = 1 •Operand: 0 < f < 127 •No. of words: 1 •No. cycles: 1 •Flags: Z
  • 19.
    11) DECF •Syntax: LabelDECF f, d •Description: Decrement the content of f register •Operation: (f) – 1 to w, if d = 0 and (f) – 1 to f, if d = 1 •Operand: 0 < f < 127 •No. of words: 1 •No. cycles: 1 •Flags: Z 12) RLF •Syntax: Label RLF f, d •Description: Rotate f content left through Carry •Operation: Result to w, if d = 0 and Result to f, if d = 1 •Operand: 0 < f < 127 •No. of words: 1 •No. cycles: 1 •Flags: C
  • 20.
    13) RRF •Syntax: LabelRRF f, d •Description: Rotate f content right through Carry •Operation: Result to w, if d = 0 and Result to f, if d = 1 •Operand: 0 < f < 127 •No. of words: 1 •No. cycles: 1 •Flags: C 14) COMF •Syntax: Label COMF f, d •Description: Complement the register content •Operation: Result to w, if d = 0 and Result to f, if d = 1 •Operand: 0 < f < 127 •No. of words: 1 •No. cycles: 1 •Flags: Z
  • 21.
    Bit Operation 1)BCF Bit clearingflag or bit clearing command •Syntax: Label BCF f, b •Description: Reset the specified bit of register f •Operation: Result to f •Operand: 0 < f < 127 and 0 < b < 7 •No. of words: 1 •No. cycles: 1 •Flags: nil 2 ) BSF Inversing operation of BCF. •Syntax: Label BSF f, b •Description: Set the specified bit of register f •Operation: Result to f •Operand: 0 < f < 127 and 0 < b < 7 •No. of words: 1 •No. cycles: 1 •Flags: nil
  • 22.
    Program Sequence ControlOperations: 1) BTFSC •Current program flow. •Syntax: Label BTFSC f, b •Description: Test the specified bit of register f, skip the next instruction if it is zero •Operation: Skip the next instruction if f (b) = 0 •Operand: 0 < f < 127 and 0 < b < 7 •No. of words: 1 •No. cycles: 1 or 2 depends on bit value •Flags: NIL 2) BTFSS •Program flow control instruction. •Syntax: Label BTFSS f, b •Description: Test the specified bit of register f, skip the next instruction if it is one •Operation: Skip the next instruction if f (b) = 1 •Operand: 0 < f < 127 and 0 < b < 7 •No. of words: 1 •No. cycles: 1 or 2 depends on bit value •Flags: nil
  • 23.
    3) INCFSZ •INCFSZ isa content increment command •Syntax: Label INCFSZ f, d •Description: Increment the f content, skip the next instruction if f is zero •Operation: Skip the next instruction if f = zero •Operand: (f) + 1 = w if d = 0 and (f) + 1 = f if d = 1 •No. of words: 1 •No. cycles: 1 or 2 depends on bit value •Flags: nil 4) DECFSZ •DECFSZ command Decrement f content •Syntax: Label DECFSZ f, d •Description: Decrement the f content, skip the next instruction if f is zero •Operation: Skip the next instruction if f = zero •Operand: (f) – 1 = w if d = 0 and (f) – 1 = f if d = 1 •No. of words: 1 •No. cycles: 1 or 2 depends on bit value •Flags: nil
  • 24.
    5) GOTO •Syntax: LabelGOTO Label •Description: Unconditional jump to specified label •Operation: k to PC(10:0), PCLATH(4:3) to PC(12:11) •Operand: 0 < k < 2048 •No. of words: 1 •No. cycles: 2 •Flags: nil 6) CALL •Syntax: Label CALL Label •Description: Unconditional call the label •Operation: (PC) + 1 to Top of stack, k to PC(10:0), PCLATH(4:3) to PC(12:11) •Operand: 0 < k < 2048 •No. of words: 1 •No. cycles: 2 •Flags: nil
  • 25.
    7) RETURN •Syntax: LabelRETURN •Description: Unconditional return from subroutine •Operation: Top of stack to (PC) •Operand: nil •No. of words: 1 •No. cycles: 2 •Flags: nil 8) RETLW •Syntax: Label RETLW k •Description: Unconditional return from subroutine •Operation: Top of stack to (PC) and k loaded in w register •Operand: 0 < k < 255 •No. of words: 1 •No. cycles: 2 •Flags: nil
  • 26.
    9) RETFIE •Syntax: LabelRETFIE •Description: Unconditional return from subroutine •Operation: Top of stack to (PC) and Global Interrupt bit is enabled •Operand: nil •No. of words: 1 •No. cycles: 2 •Flags: nil Other Instructions in PIC 1) NOP •Syntax: Label NOP •Description: No operation •Operation: nil •Operand: nil •No. of words: 1 •No. cycles: 1 •Flags: nil
  • 27.
    2) CLRWDT •Initialize watchdogtimer feature . •Syntax: Label CLRWDT •Description: Watchdog timer and pre-scalar is reset and TO and PD are set •Operation: 0 to WDT, 0 to pre-scalar and Status bits TO and PD are set •Operand: TO and PD •No. of words: 1 •No. cycles: 1 •Flags: nil 3) SLEEP •Initialize Standby mode. •Syntax: Label SLEEP •Description: Goes into low consumption, OSC is stopped, Watchdog timer and pre-scalar is reset and TO and PD bits are set •Operation: 0 to WDT, 0 to pre-scalar and Status bits, TO is set and PD is reset •Operand: TO and PD •No. of words: 1 •No. cycles: 1 •Flags: nil