IBM SA14-2339-04 Personal Computer User Manual


 
2-18 PPC405 Core User’s Manual
storage, the scalar is stored in four consecutive byte addresses. It thus becomes meaningful to
discuss the order of the byte addresses with respect to the value of the scalar: that is, which byte
contains the highest-order eight bits of the scalar, which byte contains the next-highest-order eight
bits, and so on.
Given a scalar that contains multiple bytes, the choice of byte ordering is essentially arbitrary. There
are 4! = 24 ways to specify the ordering of four bytes within a word, but only two of these orderings
are commonly used:
The ordering that assigns the lowest address to the highest-order (“leftmost”) eight bits of the
scalar, the next sequential address to the next-highest-order eight bits, and so on.
This ordering is called
big endian
because the “big end” of the scalar, considered as a binary
number, comes first in storage.
The ordering that assigns the lowest address to the lowest-order (“rightmost”) eight bits of the
scalar, the next sequential address to the next-lowest-order eight bits, and so on.
This ordering is called
little endian
because the “little end” of the scalar, considered as a binary
number, comes first in storage.
2.5.1 Structure Mapping Examples
The following C language structure,
s
, contains an assortment of scalars and a character string. The
comments show the value assumed to be in each structure element; these values show how the
bytes comprising each structure element are mapped into storage.
struct {
int a; /* 0x1112_1314 word */
long long b; /* 0x2122_2324_2526_2728 doubleword */
char *c; /* 0x3132_3334 word */
char d[7]; /* 'A','B','C','D','E','F','G' array of bytes */
short e; /* 0x5152 halfword */
int f; /* 0x6162_6364 word */
} s;
C structure mapping rules permit the use of padding (skipped bytes) to align scalars on desirable
boundaries. The structure mapping examples show each scalar aligned at its natural boundary. This
alignment introduces padding of four bytes between
a
and
b
, one byte between
d
and
e
, and two
bytes between
e
and
f
. The same amount of padding is present in both big endian and little endian
mappings.