SlideShare a Scribd company logo
1 of 3
Download to read offline
Instructions
There are only 35 instruction sets for PIC Microcontroller which makes the use of PIC as
compared to other microcontroller more advantageous. These 35 instruction sets are
discussed below along with their descriptions. These 35 instructions can also be used in some
combination
Before starting with the instruction set, let us know some of the used letters.
 F: Any file register (specified by address or label)
 L: Literal value (follows instruction)
 W: Working Register
 Labels:
o Register labels must be declared in include file or by register label equate (e.g.
GPR1 EQU 0C)
o Bit labels must be declared in include file or by bit label equate (e.g. bit1 EQU 3)
o Address labels must be placed at the left margin of the source code file (e.g. start,
delay)
The instruction is subdivided into seven different instruction types. These types include:
MOVE
The contents of a register are copied to another. Notice that we cannot move a byte directly
from one file register to another, it has to go via the working register. To put data into the
system from the program (a literal) we must use MOVLW to place the literal into W initially.
It can then be moved to another register as required. The syntax is not symmetrical; to move a
byte from W to a file register, MOVWF is used. To move it the other way, MOVF F,W is
used, where F is any file register address. This means that MOVF F,F is also available. This
may seem pointless, but in fact can be used to test a register without changing it.
REGISTER
Register operations affect only a single register, and all except CLRW (clear W) operate on
file registers. Clear sets all bits to zero (00h), decrement decreases the value by 1 and
increment increases it by 1. Swap exchanges the upper and lower four bits (nibbles).
Complement inverts all the bits, which in effect negates the number. Rotate moves all bits left
or right, including the carry flag in this process (see below for flags). Clear and set a bit
operate on a selected bit, where the register and bit need to be specified in the instruction.
ARITHMETIC & LOGIC
Addition and subtraction in binary gives the same result as in decimal or hex. If the result
generates an extra bit (e.g. FF FF 1FE), or requires a borrow (e.g. 1FE–FF FF), the carry
flag is used. Logic operations are carried out on bit pairs in two numbers to give the result
which would be obtained if they were fed to the corresponding logic gate (e.g. 00001111 and
01010101 00000101). If necessary, reference should be made to an introductory text for
further details of arithmetic and logical operations, and conversion between number systems.
Some examples will be discussed later.
TEST, SKIP & JUMP
A mechanism is needed to make decisions (conditional program branches) which depend on
some input condition or the result of a calculation. Programmed jumps are initiated using a
bit test and conditional skip, followed by a GOTO or CALL. The bit test can be made on any
file register bit. This could be a port bit, to check if an input has changed, or a status bit in a
control register. BTFSC (Bit Test and Skip if Clear) and BTFSS (Bit Test and Skip if Set) are
used to test the bit and skip the next instruction, or not, according to the state of the bit tested.
DECFSZ and INCFSZ embody a commonly used test – decrement or increment a register
and jump depending on the effect of the result on the zero flag (Z is set if result 0).
Decrement is probably used more often (see BIN4 delay routine), but increment also works
because when a register is incremented from the maximum value (FFh) it goes to zero (00h).
The bit test and skip may be followed by a single instruction to be carried out conditionally,
but GOTO and CALL allow a block of conditional code. Using GOTO label simply transfers
the program execution point to some other point in the program indicated by a label in the
first column of the source code line, but CALL label means that the program returns to the
instruction following the CALL when RETURN is encountered at the end of the subroutine.
Another option, which is useful for making program data tables, is RETLW (Return with
Literal in W). See the KEYPAD program later for an example of this. RETFIE (Return From
Interrupt) is explained below.
CONTROL
NOP simply does nothing for one instruction cycle (four clock cycles). This may seem
pointless, but is in fact very useful for putting short delays in the program so that, for
example, external hardware can be synchronised or a delay loop adjusted for an exact time
interval. In the LCD driver program (Chapter 4), NOP is used to allow in-circuit debugging
to be incorporated later when the program is downloaded, and to pad a timing loop so that it
is exactly 1 ms. SLEEP stops the program, such that it can be restarted with an external
interrupt. It should also be used at the end of any program that does not loop back
continuously, to prevent the program execution continuing into unused locations. The unused
locations contain the code 3FFF (all 1 s), which is a valid instruction (ADDLW FF). If the
program is not stopped, it will run through, repeating this instruction, and start again when
the program counter rolls over to 0000. CLRWDT means clear the watchdog timer. If the
program gets stuck in a loop or stops for any other reason, it will be restarted automatically
by the watchdog timer. To stop this happening when the program is operating normally, the
watchdog timer must be reset at regular intervals of less than, say, 10 ms, within the program
loop, using CLRWDT.
Instruction Types Description Example
Move
Move data from F to W MOVF GPR1,W
Move data from W to F MOVWF GPR1
Move literal into W MOVLW num1
Test the register data MOVF GPR1,F
Register
Clear W (reset all bits and value to 0) CLRW
Clear F (reset all bits and value to 0) CLRF GPR1
Decrement F (reduce by 1) DECF GPR1
Increment F (increase by 1) INCF GPR1
Swap the upper and lower four bits in F SWAPF GPR1
Complement F value (invert all bits) COMF GPR1
Rotate bits Left through carry flag RLF GPR1
Rotate bits Right through carry flag RRF GPR1
Clear ( =0) the bit specified BCF GPR1,but1
Set ( =1) the bit specified BSF GPR1,but1
Arithmetic
Add W to F, with carry out ADDWF GPR1
Add F to W, with carry out ADDWF GPR1,W
Add L to W, with carry out ADDLW num1
Subtract W from F, using borrow SUBWF GPR1
Subtract W from F, placing result in W SUBWF GPR1,W
Subtract W from L, placing result in W SUBLW num1
Logic
AND the bits of W and F, result in F ANDWF GPR1
AND the bits of W and F, result in W ANDWF GPR1,W
AND the bits of L and W, result in W ANDLW num1
OR the bits of W and F, result in F IORWF GPR1
OR the bits of W and F, result in W IORWF GPR1,W
OR the bits of L and W, result in W IORLW num1
Exclusive OR the bits of W and F, result in F XORWF GPR1
Exclusive OR the bits of W and F, result in W XORWF GPR1,W
Exclusive OR the bits of L and W XORLW num1
Test & Skip
Test a bit in F and Skip next instruction if it is
Clear (=0)
BTFSC GPR1,but1
Test a bit in F and Skip next instruction if it is
Set ( =1)
BTFSS GPR1,but1
Decrement F and Skip next instruction if F=0 DECFSZ GPR1
Increment F and Skip next instruction if F=0 INCFSZ GPR1
Jump
Go to a labelled line in the program GOTO start
Jump to the label at the start of a subroutine CALL delay
Return at the end of a subroutine to the next
instruction
RETURN
Return at the end of a subroutine with L in W RETLW num1
Return From Interrupt service routine RETFIE
Control
No Operation - delay for 1 cycle NOP
Go into standby mode to save power SLEEP
Clear watchdog timer to prevent automatic reset CLRWDT
References
1. Interfacing PIC Microcontroller Embedded Design by interactive simulation by martin bates

More Related Content

What's hot

1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086techbed
 
Chp5 pic microcontroller instruction set copy
Chp5 pic microcontroller instruction set   copyChp5 pic microcontroller instruction set   copy
Chp5 pic microcontroller instruction set copymkazree
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Anwar Hasan Shuvo
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051techbed
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086asrithak
 
Flags
FlagsFlags
FlagsCME
 
subroutines and interrupts
subroutines and interruptssubroutines and interrupts
subroutines and interruptsManoj Chowdary
 
The 8051 assembly language
The 8051 assembly languageThe 8051 assembly language
The 8051 assembly languagehemant meena
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutinemilandhara
 
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp011347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01bvenkanna
 
Flag register 8086 assignment
Flag register 8086 assignmentFlag register 8086 assignment
Flag register 8086 assignmentZia3130
 
microprocessor ppt (branching and logical instructions)
microprocessor ppt (branching and logical instructions)microprocessor ppt (branching and logical instructions)
microprocessor ppt (branching and logical instructions)Nemish Bhojani
 
Data transfer instruction set of 8085 micro processor
Data transfer instruction set of 8085 micro processorData transfer instruction set of 8085 micro processor
Data transfer instruction set of 8085 micro processorvishalgohel12195
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction setprakash y
 
8051-mazidi-solution
8051-mazidi-solution8051-mazidi-solution
8051-mazidi-solutionZunAib Ali
 

What's hot (20)

1344 Alp Of 8086
1344 Alp Of 80861344 Alp Of 8086
1344 Alp Of 8086
 
Chp5 pic microcontroller instruction set copy
Chp5 pic microcontroller instruction set   copyChp5 pic microcontroller instruction set   copy
Chp5 pic microcontroller instruction set copy
 
Flag Registers (Assembly Language)
Flag Registers (Assembly Language)Flag Registers (Assembly Language)
Flag Registers (Assembly Language)
 
1347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 80511347 Assembly Language Programming Of 8051
1347 Assembly Language Programming Of 8051
 
Hd10
Hd10Hd10
Hd10
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086
 
Flags
FlagsFlags
Flags
 
subroutines and interrupts
subroutines and interruptssubroutines and interrupts
subroutines and interrupts
 
The 8051 assembly language
The 8051 assembly languageThe 8051 assembly language
The 8051 assembly language
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp011347 assemblylanguageprogrammingof8051-100523023308-phpapp01
1347 assemblylanguageprogrammingof8051-100523023308-phpapp01
 
Flag register 8086 assignment
Flag register 8086 assignmentFlag register 8086 assignment
Flag register 8086 assignment
 
microprocessor ppt (branching and logical instructions)
microprocessor ppt (branching and logical instructions)microprocessor ppt (branching and logical instructions)
microprocessor ppt (branching and logical instructions)
 
Data transfer instruction set of 8085 micro processor
Data transfer instruction set of 8085 micro processorData transfer instruction set of 8085 micro processor
Data transfer instruction set of 8085 micro processor
 
Emb day2 8051
Emb day2 8051Emb day2 8051
Emb day2 8051
 
boolean 8051
boolean 8051boolean 8051
boolean 8051
 
Uc 2(vii)
Uc 2(vii)Uc 2(vii)
Uc 2(vii)
 
8051 instruction set
8051 instruction set8051 instruction set
8051 instruction set
 
8051-mazidi-solution
8051-mazidi-solution8051-mazidi-solution
8051-mazidi-solution
 
Stack and subroutine
Stack and subroutineStack and subroutine
Stack and subroutine
 

Similar to Instructions

Flag registers, addressing modes, instruction set
Flag registers, addressing modes, instruction setFlag registers, addressing modes, instruction set
Flag registers, addressing modes, instruction setaviban
 
Basic programming of 8085
Basic programming of 8085 Basic programming of 8085
Basic programming of 8085 vijaydeepakg
 
Instruction_Set.pdf
Instruction_Set.pdfInstruction_Set.pdf
Instruction_Set.pdfboukomra
 
Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)Tish997
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copymkazree
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptssuser2b759d
 
B sc e 5.2 mp unit 2 soft ware(alp)
B sc e 5.2 mp unit 2 soft ware(alp)B sc e 5.2 mp unit 2 soft ware(alp)
B sc e 5.2 mp unit 2 soft ware(alp)MahiboobAliMulla
 
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...nipunkrn
 
PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...
PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...
PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...SANTIAGO PABLO ALBERTO
 
8085 microprocessor(1)
8085 microprocessor(1)8085 microprocessor(1)
8085 microprocessor(1)Reevu Pal
 
Cpe103 03 [processor flags]
Cpe103   03 [processor flags]Cpe103   03 [processor flags]
Cpe103 03 [processor flags]Nessabel Bacani
 
8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.pptnotagain0712
 
Advanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILPAdvanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILPA B Shinde
 

Similar to Instructions (20)

assembly flag resister
assembly flag resisterassembly flag resister
assembly flag resister
 
Flag registers, addressing modes, instruction set
Flag registers, addressing modes, instruction setFlag registers, addressing modes, instruction set
Flag registers, addressing modes, instruction set
 
Basic programming of 8085
Basic programming of 8085 Basic programming of 8085
Basic programming of 8085
 
Instruction_Set.pdf
Instruction_Set.pdfInstruction_Set.pdf
Instruction_Set.pdf
 
Instruction set
Instruction setInstruction set
Instruction set
 
Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copy
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.ppt
 
B sc e 5.2 mp unit 2 soft ware(alp)
B sc e 5.2 mp unit 2 soft ware(alp)B sc e 5.2 mp unit 2 soft ware(alp)
B sc e 5.2 mp unit 2 soft ware(alp)
 
Modul PLC Programming.pdf
Modul PLC Programming.pdfModul PLC Programming.pdf
Modul PLC Programming.pdf
 
Chapter6-mikroprocessor
Chapter6-mikroprocessorChapter6-mikroprocessor
Chapter6-mikroprocessor
 
MPMC UNIT-2.pdf
MPMC UNIT-2.pdfMPMC UNIT-2.pdf
MPMC UNIT-2.pdf
 
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
Gain Experience with GPIO, LED Interface and Functions in TI TIVA C Launchpad...
 
PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...
PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...
PLC y Electroneumática: Controladores lógicos programables por W. Bolton 4 ed...
 
8085 microprocessor(1)
8085 microprocessor(1)8085 microprocessor(1)
8085 microprocessor(1)
 
Cpe103 03 [processor flags]
Cpe103   03 [processor flags]Cpe103   03 [processor flags]
Cpe103 03 [processor flags]
 
8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt8051 MMD Chapter 1.ppt
8051 MMD Chapter 1.ppt
 
12 mt06ped008
12 mt06ped008 12 mt06ped008
12 mt06ped008
 
Advanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILPAdvanced Techniques for Exploiting ILP
Advanced Techniques for Exploiting ILP
 
Dsp Datapath
Dsp DatapathDsp Datapath
Dsp Datapath
 

More from Jamia Hamdard

More from Jamia Hamdard (8)

Unit v
Unit vUnit v
Unit v
 
Embedded system software
Embedded system softwareEmbedded system software
Embedded system software
 
Wireless sensor network
Wireless sensor networkWireless sensor network
Wireless sensor network
 
Registers
RegistersRegisters
Registers
 
Programming
ProgrammingProgramming
Programming
 
Interrupts
InterruptsInterrupts
Interrupts
 
Pic microcontroller architecture
Pic microcontroller architecturePic microcontroller architecture
Pic microcontroller architecture
 
Introduction to vlsi design
Introduction to vlsi designIntroduction to vlsi design
Introduction to vlsi design
 

Recently uploaded

(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 

Recently uploaded (20)

(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 

Instructions

  • 1. Instructions There are only 35 instruction sets for PIC Microcontroller which makes the use of PIC as compared to other microcontroller more advantageous. These 35 instruction sets are discussed below along with their descriptions. These 35 instructions can also be used in some combination Before starting with the instruction set, let us know some of the used letters.  F: Any file register (specified by address or label)  L: Literal value (follows instruction)  W: Working Register  Labels: o Register labels must be declared in include file or by register label equate (e.g. GPR1 EQU 0C) o Bit labels must be declared in include file or by bit label equate (e.g. bit1 EQU 3) o Address labels must be placed at the left margin of the source code file (e.g. start, delay) The instruction is subdivided into seven different instruction types. These types include: MOVE The contents of a register are copied to another. Notice that we cannot move a byte directly from one file register to another, it has to go via the working register. To put data into the system from the program (a literal) we must use MOVLW to place the literal into W initially. It can then be moved to another register as required. The syntax is not symmetrical; to move a byte from W to a file register, MOVWF is used. To move it the other way, MOVF F,W is used, where F is any file register address. This means that MOVF F,F is also available. This may seem pointless, but in fact can be used to test a register without changing it. REGISTER Register operations affect only a single register, and all except CLRW (clear W) operate on file registers. Clear sets all bits to zero (00h), decrement decreases the value by 1 and increment increases it by 1. Swap exchanges the upper and lower four bits (nibbles). Complement inverts all the bits, which in effect negates the number. Rotate moves all bits left or right, including the carry flag in this process (see below for flags). Clear and set a bit operate on a selected bit, where the register and bit need to be specified in the instruction. ARITHMETIC & LOGIC Addition and subtraction in binary gives the same result as in decimal or hex. If the result generates an extra bit (e.g. FF FF 1FE), or requires a borrow (e.g. 1FE–FF FF), the carry flag is used. Logic operations are carried out on bit pairs in two numbers to give the result which would be obtained if they were fed to the corresponding logic gate (e.g. 00001111 and 01010101 00000101). If necessary, reference should be made to an introductory text for
  • 2. further details of arithmetic and logical operations, and conversion between number systems. Some examples will be discussed later. TEST, SKIP & JUMP A mechanism is needed to make decisions (conditional program branches) which depend on some input condition or the result of a calculation. Programmed jumps are initiated using a bit test and conditional skip, followed by a GOTO or CALL. The bit test can be made on any file register bit. This could be a port bit, to check if an input has changed, or a status bit in a control register. BTFSC (Bit Test and Skip if Clear) and BTFSS (Bit Test and Skip if Set) are used to test the bit and skip the next instruction, or not, according to the state of the bit tested. DECFSZ and INCFSZ embody a commonly used test – decrement or increment a register and jump depending on the effect of the result on the zero flag (Z is set if result 0). Decrement is probably used more often (see BIN4 delay routine), but increment also works because when a register is incremented from the maximum value (FFh) it goes to zero (00h). The bit test and skip may be followed by a single instruction to be carried out conditionally, but GOTO and CALL allow a block of conditional code. Using GOTO label simply transfers the program execution point to some other point in the program indicated by a label in the first column of the source code line, but CALL label means that the program returns to the instruction following the CALL when RETURN is encountered at the end of the subroutine. Another option, which is useful for making program data tables, is RETLW (Return with Literal in W). See the KEYPAD program later for an example of this. RETFIE (Return From Interrupt) is explained below. CONTROL NOP simply does nothing for one instruction cycle (four clock cycles). This may seem pointless, but is in fact very useful for putting short delays in the program so that, for example, external hardware can be synchronised or a delay loop adjusted for an exact time interval. In the LCD driver program (Chapter 4), NOP is used to allow in-circuit debugging to be incorporated later when the program is downloaded, and to pad a timing loop so that it is exactly 1 ms. SLEEP stops the program, such that it can be restarted with an external interrupt. It should also be used at the end of any program that does not loop back continuously, to prevent the program execution continuing into unused locations. The unused locations contain the code 3FFF (all 1 s), which is a valid instruction (ADDLW FF). If the program is not stopped, it will run through, repeating this instruction, and start again when the program counter rolls over to 0000. CLRWDT means clear the watchdog timer. If the program gets stuck in a loop or stops for any other reason, it will be restarted automatically by the watchdog timer. To stop this happening when the program is operating normally, the watchdog timer must be reset at regular intervals of less than, say, 10 ms, within the program loop, using CLRWDT.
  • 3. Instruction Types Description Example Move Move data from F to W MOVF GPR1,W Move data from W to F MOVWF GPR1 Move literal into W MOVLW num1 Test the register data MOVF GPR1,F Register Clear W (reset all bits and value to 0) CLRW Clear F (reset all bits and value to 0) CLRF GPR1 Decrement F (reduce by 1) DECF GPR1 Increment F (increase by 1) INCF GPR1 Swap the upper and lower four bits in F SWAPF GPR1 Complement F value (invert all bits) COMF GPR1 Rotate bits Left through carry flag RLF GPR1 Rotate bits Right through carry flag RRF GPR1 Clear ( =0) the bit specified BCF GPR1,but1 Set ( =1) the bit specified BSF GPR1,but1 Arithmetic Add W to F, with carry out ADDWF GPR1 Add F to W, with carry out ADDWF GPR1,W Add L to W, with carry out ADDLW num1 Subtract W from F, using borrow SUBWF GPR1 Subtract W from F, placing result in W SUBWF GPR1,W Subtract W from L, placing result in W SUBLW num1 Logic AND the bits of W and F, result in F ANDWF GPR1 AND the bits of W and F, result in W ANDWF GPR1,W AND the bits of L and W, result in W ANDLW num1 OR the bits of W and F, result in F IORWF GPR1 OR the bits of W and F, result in W IORWF GPR1,W OR the bits of L and W, result in W IORLW num1 Exclusive OR the bits of W and F, result in F XORWF GPR1 Exclusive OR the bits of W and F, result in W XORWF GPR1,W Exclusive OR the bits of L and W XORLW num1 Test & Skip Test a bit in F and Skip next instruction if it is Clear (=0) BTFSC GPR1,but1 Test a bit in F and Skip next instruction if it is Set ( =1) BTFSS GPR1,but1 Decrement F and Skip next instruction if F=0 DECFSZ GPR1 Increment F and Skip next instruction if F=0 INCFSZ GPR1 Jump Go to a labelled line in the program GOTO start Jump to the label at the start of a subroutine CALL delay Return at the end of a subroutine to the next instruction RETURN Return at the end of a subroutine with L in W RETLW num1 Return From Interrupt service routine RETFIE Control No Operation - delay for 1 cycle NOP Go into standby mode to save power SLEEP Clear watchdog timer to prevent automatic reset CLRWDT References 1. Interfacing PIC Microcontroller Embedded Design by interactive simulation by martin bates