5 PIC18 AddressingModes FSRs Table Part2
5 PIC18 AddressingModes FSRs Table Part2
Set/Clear Operations
The data copy operations are classified as:
o Loading 8-bit data directly in WREG
o Copying data between WREG and data (file) register
including I/O ports
o Copying data from one data (file) register to another data
(file) register
o Clearing or setting all data bits in data (file) register
o Exchanging low-order four bits (nibble) with high-order
four bits in data (file) register
Frequently Used Registers in ALU,
Memory, and I/O Ports for Data Copy
o Literal to W
o Wà F
o Fà F
o Fà Program
memory
o Swapping lower
order with the
higher-order
Addressing Modes
o A way of specifying of an operand
n Direct addressing
o The operand is a part of the instruction
n Indirect addressing
o An address is specified in a register and the MPU
looks up the address in that register
MOV (Copy) Operations
Instructions
o MOVLW 8-bit Examples
o MOVLW 0xF2
Load F2H in WREG
o MOVWF F, a
o MOVWF REG1, 0
Copy WREG in REG1
o MOVF F,d, a o MOVF REG1, 1
Copy REG1 in REG1 (check for
flag)
o MOVF REG1, 0
Copy REG1 into WREG
o MOVFF Fs, Fd
o MOVFF REG1,REG2
Copy REG1 into REG2
d=0 or omitted then à WREG
a=0 or omitted then à data reg is from Access Bank
SET/CLR Instructions
Instructions Examples
o CLRF F,a o CLRF REG1,0
Clear REG1 located in
o SETF F, a access bank
o SETF REG1,0
o SWAP F,d,a Set all bits in REG1
o SWAP REG1,1,0
Exchange low and high
nibbles in REG1, save in
REG1
Using File Select Registers (FSRs) as Pointers
to Data Registers – Indirect addressing
o Memory pointer is a register that holds the address of a data register
n This is called indirect addressing
n Easy to move/copy an entire block
o Three registers: FSR0, FSR1, and FSR2
n Each FSR has a High and Low byte associated with an index
n Used as memory pointers to data registers
o Each can be used in five different formats (operands) :
n INDF0: Use FSR0 as pointer (index)
n POSTINC0: Use FSR0 as pointer and increment FSR0
n POSTDEC0: Use FSR0 as pointer and decrement SR0
n PREINC0: Increment FSR0 first and use as pointer
n PLUSW0: Add W to FSR0 and use as pointer
LFSR FSR1,120 ; LOAD 12-BIT ADDRESS 120h INTO FSR1
A3
Indirect Addressing Example (2)
Examples:
MOVFF INDF0,INDF1 ; COPY BYTE FROM REGISTERS SHOWN BY
;FSR0 TO FSR1- NO CHANGE IN FSR
ADDWF POSTINC0,1 ; ADD BYTE FROM REGISTERS SHOWN BY
;FSR0 AND WàREG ;
;FSR0 IS INCREMENTED
A3
Initializing the RAM –
Application of Indirect Addressing
16 bit
Using Table Pointers to Copy Data from
Program Memory into Table Latch (REFER TO PAGE 82-83)
o TBLRD* o TBLRD*-
n Copy from Program n Copy from Program
Memory into Table Memory into Table
Latch Using Table Latch and Decrement
Pointer Table Pointer
o TBLRD*+ o TBLRD+*
n Copy from Program n Increment Table
Memory into Table Pointer first and then
Latch and Increment copy from Program
Table Pointer Memory into Table
Latch
Using Table Pointers to Copy Data from Table
Latch into Program Memory
o TBLWT* o TBL WT*-
n Copy from Table Latch n Copy from Table Latch
into Program Memory into Program Memory
Using Table Pointer and Decrement Table
Pointer
o TBL WT*+
n Copy from Table Latch o TBLWT+*
into Program Memory n Increment Table
and Increment Table Pointer first and then
Pointer copy from Table Latch
into Program Memory
Copying Data from Program
Memory to Table Latch
76
Using TBLRD*:
Address: 01251H = 76
TABLAT=76
TBLPTR=01251H
Copying Data from Table
Latch to Program Memory