分类:
2010-10-28 16:00:00
Little endian把低字节存放在内存的低位;而big endian将低字节存放在内存的高位. Intel系列的是采用的little endian的格式存放数据,而motorola系列(powerPPC)的CPU采用的是big endian.
为了更好的理解,以下的程序分别运行在x86和ppc的cpu上, 用gdb显示数据的存放方式。
|
1. X86下的gdb显示
(gdb) p &a
$1 = (long long int *) 0x7fffde588c88
(gdb) x /2x 0x7fffde588c88
0x7fffde588c88: 0x55667788 0x11223344
(gdb) p /x *(char *)0x7fffde588c88 =====è低位地址存放低位数0x88
$3 = 0x88
(gdb) p /x *(char *)0x7fffde588c89
$4 = 0x77
(gdb) p /x *(char *)0x7fffde588c90
$5 = 0x0
(gdb) p /x *(char *)0x7fffde588c8a
$6 = 0x66
(gdb) p /x *(char *)0x7fffde588c8b
$7 = 0x55
(gdb) p /x *(char *)0x7fffde588c8c
$8 = 0x44
(gdb) p /x *(char *)0x7fffde588c8d
$9 = 0x33
(gdb) p /x *(char *)0x7fffde588c8e
$10 = 0x22
(gdb) p /x *(char *)0x7fffde588c8f
$11 = 0x11
2. PPC下的gdb显示
(gdb) p &a
$1 = (long long int *) 0x7ff93af8
(gdb) p /x *(char *)0x7ff93af8 =========è低位地址存放高位数0x11
$3 = 0x11
(gdb) p /x *(char *)0x7ff93af9
$4 = 0x22
(gdb) p /x *(char *)0x7ff93afa
$5 = 0x33
(gdb) p /x *(char *)0x7ff93afb
$6 = 0x44
(gdb) p /x *(char *)0x7ff93afc
$7 = 0x55
(gdb) p /x *(char *)0x7ff93afd
$8 = 0x66
(gdb) p /x *(char *)0x7ff93afe
$9 = 0x77
(gdb) p /x *(char *)0x7ff93aff
$10 = 0x88
(gdb)