Results (
Thai) 2:
[Copy]Copied!
Let’s assume that on a byte-addressable machine, the 32-bit hex value 12345678
is stored at address 0. Each digit requires a nibble, so one byte holds two digits.
This hex value is stored in memory as shown in Figure 5.1, where the shaded
cells represent the actual contents of memory.
There are advantages and disadvantages to each method, although one
method is not necessarily better than the other. Big endian is more natural to most
people and thus makes it easier to read hex dumps. By having the high-order byte
come first, you can always test whether the number is positive or negative by
looking at the byte at offset zero. (Compare this to little endian where you must
know how long the number is and then must skip over bytes to find the one containing
the sign information.) Big endian machines store integers and strings in
the same order and are faster in certain string operations. Most bitmapped graphics
are mapped with a “most significant bit on the left” scheme, which means
working with graphical elements larger than one byte can be handled by the
architecture itself. This is a performance limitation for little endian computers
because they must continually reverse the byte order when working with large
graphical objects. When decoding compressed data encoded with such schemes
as Huffman and LZW (discussed in Chapter 7), the actual codeword can be used
as an index into a lookup table if it is stored in big endian (this is also true for
encoding).
However, big endian also has disadvantages. Conversion from a 32-bit integer
address to a 16-bit integer address requires a big endian machine to perform
addition. High-precision arithmetic on little endian machines is faster and easier.
Most architectures using the big endian scheme do not allow words to be written
on non-word address boundaries (for example, if a word is 2 or 4 bytes, it must
always begin on an even-numbered byte address). This wastes space. Little
endian architectures, such as Intel, allow odd address reads and writes, which
makes programming on these machines much easier. If a programmer writes an
instruction to read a value of the wrong word size, on a big endian machine it is
always read as an incorrect value; on a little endian machine, it can sometimes
result in the correct data being read. (Note that Intel finally has added an instruction
to reverse the byte order within registers.)
Being translated, please wait..