Vault 7: Projects
This publication series is about specific projects related to the Vault 7 main publication.
© 2007 Microchip Technology Inc. Advance Information DS39715A-page 4-11
Section 4. Program Memory
Program
Memory
4
4.6.1 Using Table Read Instructions
Table reads require two steps. First, an Address Pointer is set up using the TBLPAG register and
one of the W registers. Then, the program memory contents at the address location may be read.
4.6.1.1 READING PROGRAM MEMORY USING TABLE INSTRUCTIONS
The following code examples show how to read a word of program memory using the table
instructions in Word/Byte mode:
Example 4-1: Read Word Mode
Example 4-2: Read Byte Mode
; Setup the address pointer to program space
MOV #tblpage(PROG_ADDR),W0 ; get table page value
MOV W0,TBLPAG ; load TBLPAG register
MOV #tbloffset(PROG_ADDR),W0 ; load address LS word
; Read the program memory location
TBLRDH [W0],W3 ; Read high byte to W3
TBLRDL [W0],W4 ; Read low word to W4
Equivalent C Code
int addrOffset;
int VarWord;
int VarWord1;
{
:
:
TBLPAG = ((PROG_ADDR & 0x7F0000)>>16);
addrOffset = (PROG_ADDR & 0x00FFFF);
asm("tblrdh.w [%1], %0" : "=r"(VarWord1) : "r"(addrOffset));
asm("tblrdl.w [%1], %0" : "=r"(VarWord) : "r"(addrOffset));
:
:
}
Note: Save all the working registers prior to using them.
; Setup the address pointer to program space
MOV #tblpage(PROG_ADDR),W0 ; get table page value
MOV W0,TBLPAG ; load TBLPAG register
MOV #tbloffset(PROG_ADDR),W0 ; load address LS word
; Read the program memory location
TBLRDH.B [W0],W3 ; Read high byte to W3
TBLRDL.B [W0++],W4 ; Read low byte to W4
TBLRDL.B [W0++],W5 ; Read middle byte to W5
Equivalent C Code
int addrOffset;
char VarByte1;
char VarByte2;
char VarByte3;
{
:
:
TBLPAG = ((PROG_ADDR & 0x7F0000)>>16);
addr = (PROG_ADDR & 0x00FFFF);
asm("tblrdl.b [%1], %0" : "=r"(LocalVarByte1) : "r"(addrOffset)) ; // Read low byte
asm("tblrdl.b [%1], %0" : "=r"(LocalVarByte2) : "r"(addrOffset +1)) ;//Read middle byte
asm("tblrdh.b [%1], %0" : "=r"(LocalVarByte3) : "r"(addrOffset)) ; // Read high byte
:
:
}
Note: Save all the working registers prior to using them.
Protego_Release_01_05-Related-OEM-Documentation-PIC24FJ32MC10X-Reference_Manual-Section4-Program_Memory.pdf