44.2.4 Considerations when Enabling the Extended Instruction Set

It is important to note that the extensions to the instruction set may not be beneficial to all users. In particular, users who are not writing code that uses a software stack may not benefit from using the extensions to the instruction set.

Additionally, the Indexed Literal Offset Addressing mode may create issues with legacy applications written to the PIC18 assembler. This is because instructions in the legacy code may attempt to address registers in the Access Bank below 5Fh. Since these addresses are interpreted as literal offsets to FSR2 when the instruction set extension is enabled, the application may read or write to the wrong data addresses.

When porting an application to a PIC18 device supporting extensions to the instruction set, it is very important to consider the type of code. A large, re-entrant application that is written in ‘C’ and benefits from efficient compilation will do well when using the instruction set extensions. Legacy applications that heavily use the Access Bank will most likely not benefit from using the extended instruction set.

ADDWFAdd W to Indexed (Indexed Literal Offset Mode)
SyntaxADDWF [k] {,d}
Operands

0 ≤ k ≤ 95
d ∈ [0, 1]

Operation(W) + ((FSR2) + k) → dest
Status AffectedN, OV, C, DC, Z
Encoding001001d0kkkkkkkk
DescriptionThe contents of W are added to the contents of the register indicated by FSR2, offset by the value ‘k’. If ‘d’ is ‘0’, the result is stored in W. If ‘d’ is ‘1’, the result is stored back in the register ‘f’ (default).
Words1
Cycles1

Q Cycle Activity:

Q1Q2Q3Q4
DecodeRead literal ‘k’Process DataWrite to destination

Example: ADDWF [OFST], 0

Before Instruction
W = 17h
OFST = 2Ch
FSR2 = 0A00h
Contents of 0A2Ch = 20h

After Instruction
W = 37h
Contents of 0A2Ch = 20h

BSFBit Set Indexed (Indexed Literal Offset Mode)
SyntaxBSF [k], b
Operands

0 ≤ k ≤ 95
0 ≤ b ≤ 7

Operation1 → ((FSR2) + k)<b>
Status AffectedNone
Encoding1000bbb0kkkkkkkk
DescriptionBit ‘b’ of the register indicated by FSR2, offset by the value ‘k’, is set
Words1
Cycles1

Q Cycle Activity:

Q1Q2Q3Q4
DecodeRead literal ‘k’Process DataWrite to destination

Example: BSF [FLAG_OFST], 7

Before Instruction
FLAG_OFST = 0Ah
FSR2 = 0A00h
Contents of 0A0Ah = 55h

After Instruction
Contents of 0A0Ah = D5h

SETFSet Indexed (Indexed Literal Offset Mode)
SyntaxSETF [k]
Operands

0 ≤ k ≤ 95

OperationFFh → ((FSR2) + k)
Status AffectedNone
Encoding01101000kkkkkkkk
DescriptionThe contents of the register indicated by FSR2, offset by the value ‘k’, are set to FFh
Words1
Cycles1

Q Cycle Activity:

Q1Q2Q3Q4
DecodeRead literal ‘k’Process DataWrite to destination

Example: SETF [OFST]

Before Instruction
OFST = 2Ch
FSR2 = 0A00h
Contents of 0A2Ch = 00h

After Instruction
Contents of 0A2Ch = FFh