PATH 
ADC Home > Documentation > Hardware > Device Managers and Drivers > PCI Card Services > Designing PCI Cards and Drivers for Power Macintosh Computers


  

Endian Theory

To give a concrete example around which to discuss endian format issues, consider writing code for a system that contains a DBDMA-like controller. The DMA code includes a descriptor format whose C definition might be as follows:

struct {
    UInt8       C;      // "command" byte
    UInt8       F;      // "flags"
    UInt16      L;      // "length" (count)
    UInt32      A;      // "address"
    UInt64      X;      // "field64"
        }       DMA_Descriptor;

A compiler would assign offsets to the fields of the descriptor as follows:

C       0
F       1
L       2
A       4
X       8

Consider the diagram in Figure A-1, which presents the layout of the descriptor in a format that is neither big-endian nor little-endian. In Figure A-1, the numbers represent byte offsets to the descriptor's fields.

Figure A-1 Neutral descriptor layout

In Figure A-1 the byte offsets are associated with the "beginning" of each field. As discussed in the next sections, the primary difference between big-endian and little-endian addressing has to do with what is defined as the "beginning" of a field.

Big-Endian Addressing

Little-Endian Addressing

Scalar Accesses

Address Invariance and Byte Swapping


© 1999 Apple Computer, Inc. – (Last Updated 26 March 99)