# Support of C language on PIC-18 architecture

cpik generates code for PIC-18 processors running in legacy (ie: non-enhanced) mode. The PIC-18 core is fundamentally a 8 bit processor with 16 bit pointers and distinct program/data spaces. From the C programmer point of view, up to 64K bytes of program space and 64K bytes of data space are available. Pointer generally points to data space, but pointer to function points to program space. Programs can be larger than 64K bytes (when the device has enough memory), but pointers to functions can only reach the lower 64 KB of memory. This is not an issue because it is easy to force the addresses of target functions to be less than `0xFFFF`.

`cpik` has been designed to produce a stack-based code. This kind of code is easy to understand, robust and potentially reentrant without any trick. Interruptions are easy to support (see section 11.12.4 for details). Thanks to auto-incremented and indirect addressing modes, this design leads to efficient code.

The memory model is flat and covers the totality of program/data spaces. There is no banks, "small" stacks, "far" pointers or other tricky ways to save memory but to confuse everybody.

Subsections

- Stacks
- Memory layout
- Register usage
- Computation model
- Function calling conventions
- Stack frame allocation and interrupts
- Optimizations
- Data in ROM
  - Creating a block of data in ROM
  - Passing immediate ROM data to a subroutine
  - Passing ROM data to a subroutine with a pointer to ROM
  - Accessing data in ROM with a ROM accessor