PostHeaderIcon PIC18F43K20: Eight Kilobytes, Two Vectors, and No Room to Hide

There is a relationship between array size and how much a firmware can conceal. Eight kilobytes is roughly four thousand instructions, and after start-up code, a serial stack and a couple of tables, the application-specific part is small — small enough that the code’s structure is largely determined by what the device does.

The 40-pin package sharpens this. More pins means more I/O, which means the firmware’s job is visible at the edges. A device with eight pins could be doing almost anything; a device with thirty-two I/O pins is doing something specific, and the specific thing is measurable.

Where the vectors sit, and why it matters

On this family the reset vector and the interrupt vectors occupy the bottom of the array, in the same protection block as the start of the application. That has a consequence for partial reads: if the first block is protected, the vectors are gone.

Losing the vectors costs more than losing the same number of bytes elsewhere, because the vectors are the primary anchor for disassembly. Without them, entry points have to be found by scanning for branch-shaped words and testing candidates — a slower and less certain method.

Block Typical contents What is lost if closed
First Vectors, start-up, small functions Every entry point
Second Application body Control flow details
Third, fourth (if present) Tables, remaining code Domain constants

On an 8K part there are two blocks, so the loss is coarser: half the application, including the anchors.

Reading with a missing lower block

If the first block is closed and the second is not, the image begins with code whose entry points are unknown. Three techniques recover the structure:

  1. Scan for call targets. A call instruction encodes its destination. Collect every destination in the readable region and the frequently-called addresses will emerge as functions.
  2. Look for the interrupt handlers by shape. A handler saves context, does a little work, restores and returns. The shape is recognisable even without the vector that points at it.
  3. Use the tables. On a small part, tables are indexed by measured quantities; the instructions that read them identify the routines that use them.

None of these is as good as the vector table. All of them are enough to produce a call graph for a four-thousand-instruction image.

The pin map as a specification

With 40 pins, the pin assignment is most of the specification. What can be measured without any access to memory:

  • which pins are outputs, and their idle states;
  • which toggle at a fixed rate, and therefore which timers are configured;
  • which carry a serial protocol, and at what rate;
  • which are analog inputs, from the presence of a reference and the shape of the readings.

Add the response of each output to a change in each input and the interaction structure appears. On a device this size that is often enough to describe the application completely, with the code contributing confirmation rather than discovery.

Protection on this part

Two protection concepts, as on the rest of the family: code protection per block, and write protection per block, plus table-read protection for reads from code.

For an 8K device the practical effect is stark. A protected part loses half its array at minimum, and a fully protected part loses all of it. There is no partial outcome that leaves a useful fraction, which is why the behavioural route matters more here than on a 64K part.

What an 8K image tells you about its compiler

Small images have a distinctive texture. A compiler optimising for size emits denser code, reuses registers more aggressively, and inlines short functions. The result is a listing where function boundaries are less obvious and where a routine may be entered at more than one point.

That texture is worth recognising, because applying a 64K-part reading method to an 8K image produces confusion: the code does not look like well-separated functions, because it was not written that way.

Expectations

  • Half the array is the smallest useful unit of loss on this part.
  • The vectors are worth more than their size.
  • The pin map is a specification in its own right.
  • A fully protected 8K device is a behavioural problem, and a short one.

Related reading

FAQ

How many protection blocks does an 8K member have? Two. On a device this size that is a coarse division.

Where are the interrupt vectors? At the bottom of the array, in the first block. If that block is closed, they are unavailable.

Can entry points be found without vectors? Yes, from call targets and handler shapes, at some cost in certainty.

Is the pin map really a specification? For a device with this many I/O pins, largely yes — it defines the interfaces the firmware serves.

Why does the code look unsmooth? Small-image compilers optimise for size, which merges and inlines functions.

Conclusion

An eight-kilobyte part in a forty-pin package is legible because it cannot afford to be otherwise. The vectors are the expensive loss, the pin map is the specification, and the analysis is short enough to complete. Where the array is closed, that brevity is the compensating advantage.

Comments are closed.