PIC18F26K22: Sixty-Four Kilobytes and the Address That Crosses a Line
Up to 32K of program memory, an address fits in sixteen bits and almost every instruction can carry one. At 64K that stops being true, and the architecture deals with it the way architectures do: by making the common case nearly free and the general case visible.
That visibility is the useful part. A 64K image contains structural evidence of its own layout — branch sequences that only appear when code crosses a boundary, and table accesses that reveal which half of the array they address. Reading those correctly is the difference between understanding an image and misreading it.
What changes at this size
The program counter is wider than the address fields in most instructions. A two-word call or goto can carry a full address; a single-word branch cannot. So the compiler emits different code depending on where the target is.
| Target | Encoding | Size |
|---|---|---|
| Within reach of a short branch | Relative or page-relative | One word |
| Anywhere in the array | Full address | Two words |
| Computed | Via a table or a register pair | Several instructions |
Consequently, code that was written once and compiled at two memory sizes produces different instruction sequences — and code compiled for 64K contains long-form branches in places where a 32K build would have short ones. Neither is wrong, and they disassemble differently.
The boundary’s visible effects
Three artifacts appear in 64K images and rarely in smaller ones:
Two-word branches clustered at module boundaries. Functions that live far from their callers are called with long forms. A cluster of them marks the edge of a compilation unit.
Address high-byte manipulations. Loading a twenty-bit address requires setting an upper byte before the call. Those instructions are a signature, and they tell you the target’s location without following it.
Jump tables with widened entries. A switch statement compiled at 64K stores entries that carry more than a word each, so the table’s stride changes. A reader who assumes a word stride reads the table wrong.
Reading the image in the right order
- Find the reset vector. It is a long-form branch, since it jumps from the bottom of the array to wherever reset code lives.
- Follow it and identify initialisation. Clock, ports, peripherals — the sequence is regular.
- Map the interrupt vector table. Its entries identify handlers, and their targets are within the first half on most builds.
- Decode outward from each entry point rather than linearly.
- Treat everything unreferenced as data and test it for regular structure.
Step four matters more at this size than at 8K. In a small image, a linear disassembly is wrong but short; in a 64K image it is wrong and enormous, and the errors accumulate into a listing that appears to describe code and does not.
Constant tables at this size
With 64K available, firmware for this part tends to carry more tables and fewer computed values. That is good news for a reader: tables are structure, and structure is legible.
The common forms:
- Lookup tables indexed by a measurement. Regular stride, monotonic values, ends that correspond to the measurement’s range.
- Text strings. ASCII in word form, and recognisable immediately.
- Transition tables for a state machine. Small integers with regular repetition.
The first is the most informative. A monotonic table with a regular stride is a calibration curve, and its endpoints tell you the range of the quantity being measured — which is often the most commercially specific fact in the firmware and the one least protected by any bit.
The 64K configuration, and the protection that comes with it
At this size the array divides into four blocks, each with its own protection bits. That granularity is a practical advantage during analysis: a partially protected device can yield three quarters of an image, with the boundary at a block edge rather than an arbitrary address.
The same granularity applies to write protection, and the two are independent — a device with all four blocks read-protected and none write-protected is a device that can be erased but not read, which is a specific and recoverable situation.
Expectations worth setting
- A 64K image is not five times the work of a 13K image; it is perhaps twice, because structure dominates.
- The most informative content is usually in the tables, not the code.
- Protection at this size is per block, so partial outcomes are normal.
- A full read of a protected device yields nothing, and no reading strategy changes that.
Related reading
- PIC18F25K22 and what a restoration must reproduce — the configuration and data that a 64K image does not carry.
- PIC18F23K22 and the two protection gates — the bits that decide whether a read is possible.
- PIC18F67K22 and 128K of program memory — where the same boundary problem appears twice.
FAQ
Does the instruction set change at 64K? No, but the encodings do. Long-form branches appear where short forms sufficed on smaller parts.
Why do switch tables look different? Entries widen, so the stride changes. Assuming a word stride misreads the table.
How many protection blocks does this part have? Four, each with independent read and write protection bits.
Is a linear disassembly ever correct at this size? Rarely. Entry points and references are the reliable anchors.
Are tables more informative than code? Frequently, because they encode the application’s domain knowledge in a legible form.
Conclusion
Sixty-four kilobytes changes the instruction encodings before it changes anything else, and those changes are visible in the image as long branches, widened tables and high-byte manipulations. Reading from entry points outward, and treating unreferenced regions as data, turns a large image into a structured one — and in this size class the structure is where the information lives.