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.


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

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.

In order to read or modify the 14-bit PC with an 8-bit MCU, two Special Function Registers (SFRs) are utilized:

  • PCL - contains the lower 8 bits of the program counter <PC7:0>
  • PCLATH - content depends upon MCU operation being performed

PCL and PCLATH are used when the program writes to the PC, reads the program counter, or executes a GOTO or CALL instruction.

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.


Reading the PC

When PCL is read by an application, PC<14:8> is captured into PCLATH.


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>.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.