Skip to content
Techniques & Technology

Position-Independent Code

Code that runs anywhere

Code that executes correctly regardless of memory location, using PC-relative addressing rather than absolute addresses, pioneered on the 6809 and standard in modern systems.

cross-platform assembly6809addressingrelocation

Overview

Position-independent code (PIC) is code that executes correctly regardless of its location in memory. Rather than using absolute addresses, PIC uses relative addressing (typically PC-relative) so the code works wherever it’s loaded. The 6809 pioneered this in microprocessors.

Fast Facts

  • Concept: Code works at any address
  • Method: PC-relative addressing
  • Pioneer: Motorola 6809 (1978)
  • Modern use: Shared libraries, ASLR

Why It Matters

BenefitApplication
RelocationLoad anywhere in memory
Shared librariesOne copy serves all programs
SecurityASLR randomises locations
ROM cartridgesWork in various memory maps

6809 Implementation

; PC-relative data access
    LEAX DATA,PCR    ; Load effective address, PC-relative
    LDA ,X           ; Access data

; Relative branching
    BRA LABEL        ; Always relative on 6809
    LBRA FAR_LABEL   ; Long relative branch

vs Absolute Code

AbsolutePosition-Independent
JMP $8000BRA LABEL
LDA $1234LDA OFFSET,PCR
Fixed locationRelocatable
SimplerMore flexible

Modern Relevance

PIC is now standard:

  • Shared libraries use PIC to load at any address
  • ASLR randomises code location for security
  • Dynamic linking relies on relocatable code

Legacy

The 6809’s PIC support was revolutionary for 1978. Concepts that seemed academic then—code that runs anywhere—are now fundamental to operating system security and efficiency.

See Also