Reputation: 1378
Endianess determines the ordering of bytes in a word. Let us consider the following
memory system :
so this is a byte addressable 32 bit memory.
If I move a hex value 'val = 0x56789A'
into the memory location with word address 0, it will look like this for big endian:
And like this for little endian:
but we know that in the register the values are stored as '56789A' itslef, so that is no problem if we have a big endian type byte ordering, as the value can be loaded in the correct order.
but what about in the case of little endian where the order has to be reversed? In little endian it will be loaded as '9A7856', which is wrong.
Then do we store it like this in the memory, (i.e.) have a different organization for little endian type ordering? such as :
Now we can load the value at word address location '0' into a register for any further operation.
this was a possible solution.
but now it would mean that the endianess will dependend on the memory cell arrangement and not exactly the processor...... How exactly does this work?
Or is it the case that endianess is not at all affected by the memory architecture but rather ONLY the processor? So finally Does endianess depend on processor or memory?
Upvotes: 3
Views: 857
Reputation: 76
Endianness is really a question of interfaces. For a 32 bit register load one interface is asking for a 32 bit value, and the memory interface provides an array of bytes. Something has to resolve that interface. If it resolves the byte array as the low order bytes going into the most significant bits of the returned value, then it is big endian. If it resolves it with the low order bytes going into the least significant bits of the returned value it is little endian.
So, really your question is who resolves those interfaces. Technically, it matters how the processor requests data from the memory. If it requests it by saying "I want a 32 bit value" then the memory, which has an array of bytes, must resolve it. If it requests it by saying "I want 4 bytes", then the processor has to resolve it before storing it into the registers.
By convention, the processor resolves this interface. This allows the memory to work with both big and little endian processors because it can present the same interface (a byte array) to both types of processors and just let the processor resolve it anyway it wants it. At the risk of being to simplistic: the processor resolves it in the load/store unit and memory interface unit. The registers never have to think about it because by the time it reaches them, it is an 32 bit value, having already been resolved by the memory interface unit from the byte array it requested from memory.
Upvotes: 6