C Programming Register Variables

Last modified by Microchip on 2023/11/09 09:06

Variables Placed in a Processor’s “Hardware Registers”

On PCs and other microprocessor-based systems where the processor and RAM are completely separate devices, the register keyword may be used to force a variable to be located in the hardware registers on board the microprocessor. This will provide much faster access to a commonly used variable since the data doesn't have to be accessed from an external chip.

Doesn’t Usually Make Sense in Embedded Microcontroller System

On a microcontroller where the CPU and memory are integrated into the same package, the access times associated with retrieving data from RAM are generally very fast, so declaring a register variable doesn't often make sense. This is especially true for the PIC18 which has only one working register. The 16-bit products with their 16 working registers can accommodate a register variable much more easily, but they are still somewhat limited with respect to a high-end microprocessor.

May Be Done With PIC® MCUs and dsPIC® Digital Signal Controllers (DSCs)

Register variables may be declared with our microcontrollers, but the syntax used and how it is actually handled are very dependent on the underlying architecture. Therefore this will be covered in the compiler tutorials which cover the platform-specific implementation details.