44.2.2 Extended Instruction Set

Important: All PIC18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. If a label is used, the instruction format then becomes:

{label} instruction argument(s)

ADDULNKAdd Literal to FSR2 and Return
SyntaxADDULNK k
Operands

0 ≤ k ≤ 63

Operation

(FSR2) + k → FSR2
(TOS) → PC

Status AffectedNone
Encoding1110100011kkkkkk
Description

The 6-bit literal ‘k’ is added to the contents of FSR2. A RETURN is then executed by loading the PC with the TOS. The instruction takes two cycles to execute; a NOP is performed during the second cycle. This may be thought of as a special case of the ADDFSR instruction, where fn = 3 (binary ‘11’); it operates only on FSR2.

Words1
Cycles2

Q Cycle Activity:

Q1Q2Q3Q4
DecodeRead literal ‘k’Process DataWrite to destination
No operationNo operationNo operationNo operation

Example: ADDULNK 23h

Before Instruction
FSR2 = 03FFh
PC = 0100h

After Instruction
FSR2 = 0422h
PC = (TOS)

MOVSFMove Indexed to f
SyntaxMOVSF [zs], fd
Operands

0 ≤ zs ≤ 127
0 ≤ fd ≤ 4095

Operation

((FSR2) + zs) → fd

Status AffectedNone
Encoding111010110zszszszszszszs
1111fdfdfdfdfdfdfdfdfdfdfdfd
Description

The contents of the source register are moved to destination register ‘fd’. The actual address of the source register is determined by adding the 7-bit literal offset ‘zs’ in the first word to the value of FSR2. The address of the destination register is specified by the 12-bit literal ‘fd’ in the second word. Both addresses can be anywhere in the 4096-byte data space (000h to FFFh).

Note:

MOVSF has curtailed the destination range to the lower 4 Kbyte space in memory (Banks 1 through 15). For everything else, use MOVSFL.

Words2
Cycles2

Q Cycle Activity:

Q1Q2Q3Q4
DecodeDetermine source addressDetermine source addressRead source register
Decode

No operation
No dummy read

No operationWrite register ‘fd

Example: MOVSF [05h], REG2

Before Instruction
FSR2 = 80h
Contents of 85h = 33h
REG2 = 11h
Address of REG2 = 100h

After Instruction
FSR2 = 80h
Contents of 85h = 33h
REG2 = 33h
Address of REG2 = 100h

MOVSFLMove Indexed to f (Long Range)
SyntaxMOVSFL [zs], fd
Operands

0 ≤ zs ≤ 127
0 ≤ fd ≤ 16383

Operation

((FSR2) + zs) → fd

Status AffectedNone
Encoding0000000001100010
1111xxxzszszszszszszsfdfd
1111fdfdfdfdfdfdfdfdfdfdfdfd
Description

The contents of the source register are moved to destination register ‘fd’. The actual address of the source register is determined by adding the 7-bit literal offset ‘zs’ in the first word to the value of FSR2 (14 bits). The address of the destination register is specified by the 14-bit literal ‘fd’ in the second word. Both addresses can be anywhere in the 16 Kbyte data space (0000h to 3FFFh). The MOVSFL instruction cannot use the PCL, TOSU, TOSH or TOSL as the destination register. If the resultant source address points to an indirect addressing register, the value returned will be 00h.

Words3
Cycles3

Q Cycle Activity:

Q1Q2Q3Q4
DecodeNo operationNo operationNo operation
DecodeRead source registerProcess DataNo operation
Decode

No operation
No dummy read

No operationWrite register ‘fd

Example: MOVSFL [05h], REG2

Before Instruction
FSR2 = 2080h
Contents of 2085h = 33h
REG2 = 11h
Address of REG2 = 2000h

After Instruction
FSR2 = 2080h
Contents of 2085h = 33h
REG2 = 33h
Address of REG2 = 2000h

MOVSSMove Indexed to Indexed
SyntaxMOVSS [zs], [zd]
Operands

0 ≤ zs ≤ 127
0 ≤ zd ≤ 127

Operation

((FSR2) + zs) → ((FSR2) + zd)

Status AffectedNone
Encoding111010111zszszszszszszs
1111xxxxxzdzdzdzdzdzdzd
Description

The contents of the source register are moved to the destination register. The addresses of the source and destination registers are determined by adding the 7-bit literal offsets ‘zs’ or ‘zd’ respectively to the value of FSR2. Both registers can be located anywhere in the 16 Kbyte data memory space (0000h to 3FFFh).

The MOVSS instruction cannot use the PCL, TOSU, TOSH or TOSL as the destination register.

If the resultant source address points to an indirect addressing register, the value returned will be 00h. If the resultant destination address points to an indirect addressing register, the instruction will execute as a NOP.

Words2
Cycles2

Q Cycle Activity:

Q1Q2Q3Q4
DecodeDetermine source addressDetermine source addressRead source register
DecodeDetermine destination addressDetermine destination addressWrite to destination register

Example: MOVSS [05h], [06h]

Before Instruction
FSR2 = 80h
Contents of 85h = 33h
Contents of 86h = 11h

After Instruction
FSR2 = 80h
Contents of 85h = 33h
Contents of 86h = 33h

PUSHLStore Literal at FSR2, Decrement FSR2
SyntaxPUSHL k
Operands

0 ≤ k ≤ 255

Operation

k → FSR2
(FSR2) – 1 → FSR2

Status AffectedNone
Encoding11111010kkkkkkkk
Description

The 8-bit literal ‘k’ is written to the data memory address specified by FSR2. FSR2 is decremented by 1 after the operation. This instruction allows users to push values onto a software stack.

Words1
Cycles1

Q Cycle Activity:

Q1Q2Q3Q4
DecodeRead literal ‘k’Process DataWrite to destination

Example: PUSHL 08h

Before Instruction
FSR2 = 01ECh
Contents of 01ECh = 00h

After Instruction
FSR2 = 01EBh
Contents of 01ECh = 08h

SUBULNKSubtract Literal from FSR2 and Return
SyntaxSUBULNK k
Operands

0 ≤ k ≤ 63

Operation

(FSR2) – k → FSR2
(TOS) → PC

Status AffectedNone
Encoding1110100111kkkkkk
Description

The 6-bit literal ‘k’ is subtracted from the contents of FSR2. A RETURN is then executed by loading the PC with the TOS. The instruction takes two cycles to execute; a NOP is performed during the second cycle. This may be thought of as a special case of the SUBFSR instruction, where fn = 3 (binary ‘11’); it operates only on FSR2.

Words1
Cycles2

Q Cycle Activity:

Q1Q2Q3Q4
DecodeRead literal ‘k’Process DataWrite to destination
No operationNo operationNo operationNo operation

Example: SUBULNK 23h

Before Instruction
FSR2 = 03FFh
PC = 0100h

After Instruction
FSR2 = 03DCh
PC = (TOS)