Modernization Hub

Indirect Addressing - Pointer-based

Enhanced Definition

Indirect addressing, in the mainframe context, refers to accessing data or instructions not directly by their absolute memory address, but by an address (a pointer) stored at another memory location. It's a fundamental mechanism that allows programs to reference data whose location might be dynamic or determined at runtime, providing flexibility in memory management and data manipulation.

Key Characteristics

    • Multi-Step Access: Involves at least two memory accesses: one to retrieve the pointer's value (the target address), and a second to retrieve the actual data using that target address.
    • Pointers and Addresses: Relies on memory addresses (pointers) stored in registers or other memory locations to point to the desired data. These pointers hold virtual storage addresses.
    • Flexibility and Dynamism: Enables programs to work with data structures that can grow or shrink dynamically, or to pass data by reference without knowing its fixed location at compile time.
    • Base-Displacement Interaction: While z/OS uses base-displacement addressing (e.g., D(X,B)) for most instructions, indirect addressing often complements this, where a base register B might hold a pointer, and D is an offset from that pointer. True indirect addressing involves a memory location holding the *full* target address.
    • Performance Considerations: Introduces a slight performance overhead due to the additional memory access required to fetch the pointer's value before accessing the data.
    • Error Prone: Incorrect manipulation of pointers (e.g., uninitialized pointers, wild pointers, storage overlays, NULL pointers) can lead to severe program errors, ABENDs (Abnormal Ends), and data corruption.

Use Cases

    • Dynamic Data Structures: Implementing complex data structures like linked lists, trees, and queues in Assembler or C/C++ where elements are allocated dynamically and connected via pointers.
    • Parameter Passing by Reference: Passing the address of a data item to a subroutine (e.g., CALL BY REFERENCE in COBOL, PL/I, or passing pointers in Assembler/C), allowing the called routine to directly modify the caller's data.
    • Working with BASED Variables: In COBOL, BASED data items are implicitly addressed indirectly via an associated POINTER data item or the ADDRESS OF special register, enabling dynamic assignment of storage areas.
    • System Programming and Control Blocks: Used extensively within the z/OS operating system, CICS, IMS, and other system software to manage control blocks, buffers, and system resources, where the location of these structures can vary.
    • Memory Management Routines: Heap management and storage allocation services rely on indirect addressing to track available memory blocks and return pointers to allocated storage.

Related Concepts

Indirect addressing is a cornerstone of Assembler programming, where instructions like L (Load), ST (Store), and LA (Load Address) are frequently used with register-based pointers. It is fundamental to how CALL BY REFERENCE works across languages like COBOL, PL/I, and C, enabling subroutines to operate on the caller's data. It interacts closely with virtual storage concepts, as pointers hold virtual addresses that are translated by the hardware's DAT (Dynamic Address Translation) mechanism into real memory addresses.

Best Practices:
  • Always Initialize Pointers: Ensure all pointers are initialized to a valid address or NULL before use to prevent accessing arbitrary memory locations, which can lead to unpredictable behavior or ABENDs.
  • Validate Pointer Values: When receiving pointers from external sources or after dynamic allocation, always validate their contents (e.g., check for NULL or out-of-bounds conditions) before dereferencing them.
  • Manage Storage Lifetime: Be acutely aware of the lifetime of the memory pointed to. Ensure that the target memory remains valid and accessible for as long as the pointer is in use, and avoid dangling pointers.
  • Explicitly Free Allocated Storage: For dynamically allocated memory, always FREE (or RELEASE in Assembler/C) the storage when it is no longer needed to prevent storage leaks

Related Vendors

Trax Softworks

3 products

Tone Software

14 products

Related Categories

Browse and Edit

64 products

Operating System

154 products

Automation

222 products