0% found this document useful (0 votes)
105 views

5 PIC18 AddressingModes FSRs Table Part2

The document discusses various data copy and set/clear operations that can be performed using registers and addressing modes in a microprocessor, including loading data directly into registers, copying between registers, clearing or setting register bits, and using indirect addressing with file select registers to point to data registers for easy data copying or movement. It provides examples of instructions like MOV, CLR, and SET as well as using table pointers to copy data between program memory and table latches.

Uploaded by

Zain UL ABIDIN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
105 views

5 PIC18 AddressingModes FSRs Table Part2

The document discusses various data copy and set/clear operations that can be performed using registers and addressing modes in a microprocessor, including loading data directly into registers, copying between registers, clearing or setting register bits, and using indirect addressing with file select registers to point to data registers for easy data copying or movement. It provides examples of instructions like MOV, CLR, and SET as well as using table pointers to copy data between program memory and table latches.

Uploaded by

Zain UL ABIDIN
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Data Copy (Move) and

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

Indirect Addressing - Example


0x0
0x0

• Initially FSR values are 0 and


status of registers are given as
above
• LFSR FSR1,0x0120 ; load the
• LFSR FSR2,0x0150
• MOVFF POSTINC1, POSTINC2
; Load the content of FSR1àFSR2 and increment FSR1 & FSR2
Indirect Addressing – Example (1)
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

- Hence, we will have A3 in register


0x151 after the MOVFF instruction
- Note that the pointer indexes are not FSR0
changing!
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

Assume W=2; after the ADD operation,


A3+2=A5àReg 0x0121, then FSR=0x0122
FSR0 0x0122
FSR1 A5

A3
Initializing the RAM –
Application of Indirect Addressing

What is this doing?


Using Table Pointers to Copy Data

8-bit data registers


21 bit

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

You might also like