Re: Re: Endian'ess.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



  Amith, 
	I would give answer to your qs with the following example code :- 
 
/* ----------------- Test Program ------------------------- */ 
 
#include<stdio.h> 
 
unsigned long temp = 0x12345678; 
 
main() 
{ 
        temp = 0x12345678;	// This statement if for specail purpose... 
} 
 
 
Now compile the program and get an executable [which is sum_test in my case]. 
Now run objdump as follows :- 
 
$ objdump -D sum_test > Output 
 
Open "Output" file and go inside <main>: section. Here u'll a line sayting something 
like this :- 
 
 movl   $0x12345678,0x80493e0 
 
This line says that temp's location is 0x80493e0. So mate ! go to that location 
[search for 0x80493e0 and go there]. At this location you can see :- 
 
080493e0 <temp>: 
80493e0:   78 56                   js     8049438 <_DYNAMIC+0x50> 
80493e2:   34 12                   xor    $0x12,%al 
 
So you get :- 
 
	Location			Data 
	-------------			------- 
	80493e0			78 
	80493e1			56 
	80493e2			34 
	80493e3			12 
 
And this is according to LE definition only. The least significant byte here 0x78 has 
been stored at the lowest address 0x80493e0 and other bytes are also stored as per 
LE definition only. 
 
FYI, I'd mention that the second assignment statement inside main funtion is just to 
know the location of temp and doesn't have any other significance ;-) 
 
Leme know if this helps. 
 
Thanks. 
 
Sumit Sharma, 
IBM, Bangalore. 
On Thu, 08 Jul 2004 Momchil Velikov wrote : 
> >>>>> "amith" == amith  <amith@multitech.co.in> writes: 
>amith> Now, i have a couple of doubts : 
>amith> 1) i read somewhere on the net, that a processor can be set to either 
>amith>    Little endian or Big endian, configurable ? 
> 
>   As people already said, some are fixed endian (e.g. ia32), some are 
>h/w configurable (say with a processor pin), some are runtime 
>configurable (e.g. powerpc). 
> 
>amith> 2) Could someone explain this with respect to the Little Endian 
>amith>    definition given above. 
> 
> 
>amith>   6004             6006 
>amith> _________________ 
>amith> |    5678    |   1234      | 
>amith> |________|________ | 
>amith>  t1.w1          t1.w2 
> 
>the int 0x12345678 occupies four bytes.  With little endian the 
>least-significant bytes are on lower addresses, i.e. the memory layout 
>is 
> 
>  ------------------- 
>| 78 | 56 | 34 | 12 | 
>  ------------------- 
> 
>whereas with big endian the least significant bytes are on higher 
>addresses, i.e. 
> 
>  ------------------- 
>| 12 | 34 | 56 | 78 | 
>  ------------------- 
> 
>   The same applies to two-byte integers, hence with little endian the 
>half integers are 0x5678 and 0x1234 (note that what is on lower 
>addresses is less significant), whereas with big endian they are 
>0x1234 and 0x5678 (because what is on lower addresses is more 
>significant). 
> 
>   And as a side note, it's clear which is The Right Endian(tm): all 
>other things equal with big endian you can read memory dumps (unless 
>you're an Arab or Jewish, where it'd be easier to read little-endian 
>dumps from right to left :D ) 
> 
>~velco 
> 
>-- 
>Kernelnewbies: Help each other learn about the Linux kernel. 
>Archive:       http://mail.nl.linux.org/kernelnewbies/ 
>FAQ:           http://kernelnewbies.org/faq/ 
> 

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux