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-13
Section 4. Program Memory
Program
Memory
4
To write a single program memory latch location in Byte mode, the following code sequence can
be used:
Example 4-4: Write Byte Mode
In the code example above, the post-increment operator on the write to the low byte causes the
address in W0 to increment by one. This sets EA<0> = 1 for access to the middle byte in the third
write instruction. The last post-increment sets W0 back to an even address, pointing to the next
program memory location.
; 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
; Load data into working registers
MOV #LOW_BYTE,W2
MOV #MID_BYTE,W3
MOV #HIGH_BYTE,W4
; Write data to the latch
TBLWTH.B W4
,
[W0] ; write high byte
TBLWTL.B W2
,
[W0++] ; write low byte
TBLWTL.B W3
,
[W0++] ; write middle byte
Equivalent C Code
char VarByte1 = 0xXX;
char VarByte2 = 0xXX;
char VarByte3 = 0xXX;
{
:
:
TBLPAG = ((PROG_ADDR & 0x7F0000)>>16);
addr = (PROG_ADDR & 0x00FFFF);
asm("tblwtl.b %1, [%0]" : "=r"(addr) : "d"(VarByte1)) ;//Low Byte
asm("tblwth.b %1, [%0]" : "=r"(addr) : "d"(VarByte3)) ;//Upper Byte
addr++;
asm("tblwtl.b %1, [%0]" : "=r"(addr) : "d"(VarByte2)) ;//Middle Byte
:
}
Note: Save all the working registers prior to using them.

e-Highlighter

Click to send permalink to address bar, or right-click to copy permalink.

Un-highlight all Un-highlight selectionu Highlight selectionh