Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
PIC microcontrollers
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Instruction set=== {{Further|PIC instruction listings}} PIC instruction sets vary from about 35 instructions for the low-end PICs to over 80 instructions for the high-end PICs. The instruction set includes instructions to perform a variety of operations on registers directly, on the [[Accumulator (computing)|accumulator]] and a literal constant, or on the accumulator and a [[Processor register|register]], as well as for conditional execution, and program branching. A few operations, such as bit setting and testing, can be performed on any numbered register, but 2-input arithmetic operations always involve W (the accumulator), writing the result back to either W or the other operand register. To load a constant, it is necessary to load it into W before it can be moved into another register. On the older cores, all register moves needed to pass through W, but this changed on the "high-end" cores. PIC cores have skip instructions, which are used for conditional execution and branching. The skip instructions are "skip if bit set" and "skip if bit not set". Because cores before PIC18 had only unconditional branch instructions, conditional jumps are implemented by a conditional skip (with the opposite condition) followed by an unconditional branch. Skips are also of utility for conditional execution of any immediate single following instruction. It is possible to skip skip instructions. For example, the instruction sequence "skip if A; skip if B; C" will execute C if A is true or if B is false. The PIC18 series implemented shadow registers: these are registers which save several important registers during an interrupt, providing hardware support for automatically saving processor state when servicing interrupts. In general, PIC instructions fall into five classes: * Operation on working register (WREG) with 8-bit immediate ("literal") operand. E.g. <code>movlw</code> (move literal to WREG), <code>andlw</code> (AND literal with WREG). One instruction peculiar to the PIC is <code>retlw</code>, load immediate into WREG and return, which is used with computed [[branch (computer science)|branch]]es to produce [[lookup table]]s. * Operation with WREG and indexed register. The result can be written to either the working register (e.g. <code>addwf ''reg'',w</code>). or the selected register (e.g. <code>addwf ''reg'',f</code>). * Bit operations. These take a register number and a bit number, and perform one of 4 actions: set or clear a bit, and test and skip on set/clear. The latter are used to perform conditional branches. The usual ALU status flags are available in a numbered register so operations such as "branch on carry clear" are possible. * Control transfers. Other than the skip instructions previously mentioned, there are only two: <code>goto</code> and <code>call</code>. * A few miscellaneous zero-operand instructions, such as return from subroutine, and <code>sleep</code> to enter low-power mode.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)