Lesson 5: Instruction Set

The set of assembler instruction that the PIC12F508 chip understands is described on pages 57 to 64 of the datasheet and listed below:

Instruction Description
addwf f, d Add W and f
andwf f, d AND W with f
clrf f Clear f
clrw Clear W
comf f, d Complement f
decf f, d Decrement f
decfsz f, d Decrement f, skip next instruction if 0
incf f, d Increment f
incfsz f, d Increment f, skip next instruction if 0
iorwf f, d Inclusive OR W with f
movf f, d Move f
movwf f Move W to f
nop No Operation
rlf f, d Rotate left f through Carry
rrf f, d Rotate right f through Carry
subwf f, d Subtract W from f
swapf f, d Swap nibbles of f
xorwf f, d Exclusive OR W with f
bcf f, b Bit Clear f
bsf f, b Bit Set f
btfsc f, b Bit Test f, skip next instruction if Clear
btfss f, b Bit Test f, skip next instruction if Set
andlw k AND literal with W
call k Call Subroutine
clrwdt Clear Watchdog Timer
goto k Unconditional branch
iorlw k Inclusive OR literal with W
movlw k Move literal to W
option Load hidden OPTION register
retlw k Return, place literal in W
sleep Go into Standby mode
tris f Load hidden TRIS register
xorlw k Exclusive OR literal to W

As explained before, each instruction in the device maps directly to a 12-bit binary op-code stored in the program memory. Simple instructions map directly to an op-code:

clrw // op-code: 000001000000b nop // op-code: 000000000000b

However, most instructions require an operand that defines a data memory address (f), program memory address (k), or constant value (k) to use during execution:

clrf reg_addr // op-code: 0000011 + reg_addr // First 7 bits are always 0000011 // Last 5 bits encode memory address to clear

Many instructions also have a second operand (d) that tells the ALU where to store the result. If this is set to 0 the result is written into the Working Register and if it is 1 the result is written back into the register specified in the first operand:

incf f, d // f - the address of the register to increment // d = 0 - write result into working register // d = 1 - write result into register at address f

If you look in the Constants Window of the simulator you can see that the constants 'w' and 'f' are already defined. We can use these in our programs for this second operand to make our code easier to understand.

Next we will look at specific instructions in more detail.

Next Lesson >>