Enhanced Mid-Range PIC® MCU Program Memory
Program memory on the Enhanced Mid-Range PIC® MCU consists of up to 32 MB of 14-bit wide Flash memory. After the MCU is programmed, the program memory contains the user's application code. Program memory is accessed by a 15-bit Program Counter (PC) register.
![Program Memory Layout](/xwiki/bin/download/products/mcu-mpu/8bit-pic/enhanced-family/empm/WebHome/pm-layout.png?width=600&height=322&rev=1.1)
Program Memory Layout
![Program Memory Vector](/xwiki/bin/download/products/mcu-mpu/8bit-pic/enhanced-family/empm/WebHome/pm-vectors.png?width=300&height=395&rev=1.1)
Program Memory Vector
RESET Vector
At RESET, the program counter is cleared, resulting in all zeros. This allows program memory address 0h to be the location of the first instruction executed after a RESET condition.
Interrupt Vector
When an interrupt occurs, program control is transferred to address 04h. The "Interrupts" section provides a complete description of the interrupt process
![return stack](/xwiki/bin/download/products/mcu-mpu/8bit-pic/enhanced-family/empm/WebHome/return-stack.png?rev=1.1)
Return Stack
Return Stack
A 16-entry, 15-bit wide hardware return stack stores the PC in the event of either an interrupt or call to a subroutine. The return stack works on a last-in-first-out basis.
Upon executing a RETURN instruction, (RETFIE or RETURN), the top element of the stack is removed from the stack and placed into the program counter.
Writing to the PC
When the application writes to PCL, the current contents of PCLATH<5:0> will be written to PC<14:8>. Because of this, the contents of PCLATH<5:0> MUST always be correct BEFORE writing to PCL.
![Writing to the PC](/xwiki/bin/download/products/mcu-mpu/8bit-pic/enhanced-family/empm/WebHome/pcl-write.png?width=600&height=423&rev=1.1)
Writing to the PC
Reading the PC
When PCL is read by an application, PC<14:8> is captured into PCLATH.
![Reading from PC Latch](/xwiki/bin/download/products/mcu-mpu/8bit-pic/enhanced-family/empm/WebHome/pcl-read.png?width=600&height=338&rev=1.1)
Reading from PC Latch
Executing a CALL or GOTO instruction
The CALL and GOTO instructions only have 11 bits available to specify the destination address. PCLATH is used to extend the operand to access all the program memory addresses. When either a CALL or GOTO is executed, the 11-bit address from the operand is loaded into PC<10:0> and PCLATH<6:3> is loaded into PC<14:11>.
![Executing a GoTo](/xwiki/bin/download/products/mcu-mpu/8bit-pic/enhanced-family/empm/WebHome/goto.png?width=600&height=426&rev=1.1)
Executing a GoTo