Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Porting from Linux to MacOS



At 10:41 AM -0800 12/20/00, Eugene Foss wrote:

I would actually say that the bytes are reversed on Intel
processors, since Intel's bits go (8 - 1)(16 - 9) in disregard of the Arabic
numeral convention of MSB first.

Actually, things are counted from zero, so it's (7-0)(15-8). And if you dump memory with high addresses on the left and low addresses on the right, it's displayed in (15-0) order.

But you ain't seen nothing yet. PowerPCs are consistent in their big-endianness, meaning that they use true big-endian bit numbering. In other words, a 32-bit word stored in memory at address 0 looks like this:

byte address | 0 | 1 | 2 | 3 |
bit number | 0 ... 7 | 8 ... 15 | 16 ... 23 | 24 ... 31 |

where byte 0 is the most significant byte, bit 0 is the most significant bit, and bit 31 is the least significant bit. In other words, two to the power of the bit number is NOT equal to the value of a binary '1' at that bit position; you have to use 2^(31-bitnumber) instead. I am not making this up.

This is hidden from the programmer for the most part, but I'm a hardware type and it causes me no end of pain that PowerPC busses are numbered this way. I believe it's only visible in the instruction set if you use the rlwimi type instructions, where you have to specify the beginning and end of the mask with big-endian bit numbers.

Motorola's 68K series used little-endian bit numbering with big-endian byte ordering. People who grew up on it generally ended up thinking that little-endian bit numbering is big-endian.

Moral of the story: big-endian and little-endian are both screwed up. Pick one and live with it.

Tim Seufert


References: 
 >RE: Porting from Linux to MacOS (From: "Eugene Foss" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.