goto PIC Tips

 
12-Bit/14-Bit PSEUDO Instruction Mnemonics 

 

Mnemonic
Description
Equivalent
Operation(s)
Status
ADDCF
f,d
Add Carry to File
BTFSC
INCF
3,0
f,d
Z
ADDDCF
f,d
Add Digit Carry to File
BTFSC
INCF
3,1
f,d
Z
B
k
Branch
GOTO
k
-
BC
k
Branch on Carry
BTFSC
GOTO
3,0
k
-
BDC
k
Branch on Digit Carry
BTFSC
GOTO
3,1
k
-
BNC
k
Branch on No Carry
BTFSS
GOTO
3,0
k
-
BNDC
k
Branch on No Digit Carry
BTFSS
GOTO
3,1
k
-
BNZ
k
Branch on No Zero
BTFSS
GOTO
3,2
k
-
BZ
k
Branch on Zero
BTFSC
GOTO
3,2
k
-
CLRC
 
Clear Carry
BCF
3,0
-
CLRDC
 
Clear Digit Carry
BCF
3,1
-
CLRZ
 
Clear Zero
BCF
3,2
-
LCALL
k
Long Call
BCF/BSF
BCF/BSF
CALL
0x0A,3
0x0A,4
k
 
LGOTO
k
Long GOTO
BCF/BSF
BCF/BSF
GOTO
0x0A,3
0x0A,4
k
 
MOVFW
f
Move File to W
MOVF
f,0
Z
NEGF
f,d
Negate File
COMF
INCF
f,1
f,d
Z
SETC
 
Set Carry
BSF
3,0
-
SETDC
 
Set Digit Carry
BSF
3,1
-
SETZ
 
Set Zero
BSF
3,2
-
SKPC
 
Skip on Carry
BTFSS
3,0
-
SKPDC
 
Skip on Digit Carry
BTFSS
3,1
-
SKPNC
 
Skip on No Carry
BTFSC
3,0
-
SKPNDC
 
Skip on No Digit Carry
BTFSC
3,1
-
SKPNZ
 
Skip on Non Zero
BTFSC
3,2
-
SKPZ
 
Skip on Zero
BTFSS
3,2
-
SUBCF
f,d
Subtract Carry from File
BTFSC
DECF
3,0
f,d
Z
SUBDCF
f,d
Subtract Digit Carry from File
BTFSC
DECF
3,1
f,d
Z
TSTF
f
Test File
MOVF
f,1
Z
 
'Equivalent Operation(s)' what's with the numbers?

These Pseudo instructions are taken from the Help file in Microchip's MPLAB IDE. See under Help - Topics - MPASM Assembler - Reference - Instruction Sets

The meaning of the 'Equivalent Operation(s)' is a little confusing because they use numbers without explaining what they mean.  If you dig into the datasheet for the PIC and look at the instruction set it will become clearer (maybe), but for a quick explanation see below.

The numbers are the file register and bit position.  The Special File Register (SFR) at address 3 is the STATUS register and within the STATUS register the bits are numbered as:

  • 0 - C  (carry)
  • 1 - DC (digit carry)
  • 2 - Z  (zero)

So the instruction BSF 3,0  could also be written as BSF  STATUS, C.  This mean Set the Carry bit in the STATUS register.

Another examples BTFSC 3,2  is the same as BTFSC STATUS, Z meaning 'skip next instruction if Z flag bit is clear'

The other instruction that looks confusing is the f,d  (SFR, Destination).  For example DECF f,d.  Here f is the file register and d the destination.  If d == 0 then the result is placed in the W register, if d == 1 the result is placed back in the file register.

When writing code you should use names rather than numbers otherwise your code will be hard for you to understand while you're writing it and nigh on impossible for you or anyone else later.

So rather than writing MOVF  5,0   which is saying move the contents of file register address 5 (PORTA) to destination 0 (W register) you'd write MOVF PORTA, W   - easy to see what's going where.

Device Specifc Include Files and Templates

The include file for each device has all the Special Functions Register names and bit names defined so all you need to do is include the correct file and start writing code, no need to manually define them yourself.

If you're using the MPLAB IDE you will find include files for all the PIC variants in
C:\Program Files\Microchip\MPASM Suite.  They have a .inc extension and look like this.  P16F628A.INC

If your using the MPLAB IDE you can find assembler  .ASM template files which are an even better way to get started.  These are located in C:\Program Files\Microchip\MPASM Suite\Template\Code an example file looks like this 16F628ATEMP.ASM    Just remember to use save as and put it in a working directory - don't overwrite the original!