ATtiny461: Relative Jumps Stop Reaching at Four Kilobytes
Instruction encoding is a budget. A relative jump on this architecture spends twelve bits on the offset, which reaches about two thousand words in each direction — four kilobytes of address space in total. That is fine for a small program and insufficient for one that grows past it.
The consequence is that a C compiler, once the image crosses the boundary, stops emitting relative jumps and starts emitting absolute ones. The generated code changes shape, and a disassembly read with a uniform assumption will look wrong in exactly the region where the program got big.
What the two forms look like
A relative jump is a single word: opcode plus offset. It is cheap, it is position-independent, and it cannot leave its window.
An absolute jump is two words: the opcode plus the target’s low bits, followed by the target’s high bits. It reaches anywhere in the address space and costs twice the space.
The distinction is visible in a dump without a symbol table, which is what makes it useful. A region full of single-word branches is a small, self-contained function. A region with two-word jumps is either a large function or a table of dispatch targets.
| Form | Size | Reach | Where it appears |
|---|---|---|---|
| Relative jump | one word | ±2K words | Most branches, loops, small functions |
| Absolute jump | two words | full space | Long branches, vector table, dispatch |
| Relative call | one word | ±2K words | Ordinary function calls |
| Absolute call | two words | full space | Calls across the boundary |
Why this misleads a disassembly
Start reading at the wrong offset and everything after is nonsense — that is true everywhere. The subtler problem is starting at the right offset and misjudging instruction length.
If a two-word jump is decoded as a one-word branch, the second word is read as the next instruction. It usually decodes as something plausible, because most 16-bit values decode as some instruction on a dense architecture. The reader then follows a control flow that does not exist, and the reconstruction drifts.
The cure is to check the opcode, not to guess from context. Two-word forms are identifiable from the first word alone; there is no ambiguity at the instruction level, only in a reader who is pattern-matching.
What the boundary means for structure
A 4 KB image that uses absolute jumps throughout is telling you something about how it was built: the compiler targeted a larger part, or the linker was configured for one. That is not a defect, and it does mean the code is larger than the source would suggest.
Conversely, a 4 KB image full of relative jumps is dense and probably hand-optimised or compiled with size optimisation. The two produce very different disassembly experiences, and knowing which you have sets expectations for how much of the image will be library code.
Where the vector table fits
Vectors are jumps, and on this part the reset vector is an absolute jump because it must reach the start of the application regardless of where that is. The interrupt vectors follow at fixed spacing, and each is either a jump to a handler or a placeholder.
Because an absolute jump occupies two words, the vectors consume more space than a reader expecting one-word entries would assume. The spacing is fixed and documented, so the table is a reliable anchor: count entries at the documented interval and they will line up.
Reading the image
- Read signature, fuses, lock byte before the array. A part configured for a missing clock will not run.
- Read the array twice, page by page, comparing.
- Disassemble from address zero and confirm the reset vector decodes as an absolute jump.
- Walk the vector table at the documented spacing and confirm each entry lands inside the application region.
- Only then follow code, checking instruction width at every branch.
Step 5 is where patience pays. Every two-word instruction decoded as one introduces an error that propagates, and there is no checksum downstream to catch it.
Related notes
- ATtiny461V and the serial interface — the peripheral whose code is easiest to recognise.
- ATtiny261 and the vector table — the same table on a smaller array.
- ATtiny861 and the three address spaces — where tables get placed.
FAQ
Can a relative jump reach the whole 4 KB image? Not from every position. The range is ±2K words, which covers 4 KB only from the middle.
Does the compiler always switch to absolute jumps past the boundary? It does when the target is out of range. Short functions can still use relative forms.
Is a two-word jump easy to confuse with two instructions? Only if the opcode is not checked. It is unambiguous at the instruction level.
Does this matter for a 2 KB part? Less. The whole image fits inside one relative window, so the mixed encoding rarely appears.
Conclusion
Instruction width is a structural property of an image, and on a part at the boundary between small and medium it varies within the same program. Checking the opcode rather than assuming a width is what keeps a reconstruction from drifting, and the vector table is the anchor that confirms the reading started in the right place.