|
发表于 2012-2-28 23:04:49
|
显示全部楼层
关于大小端的问题,我同意4楼的意见。就CPU指令来讲肯定是分大小端的,除非全部指令都是8位的。对于8位机来说,多字节的数据类型是由编译器来处理的,所以编译器就存在了大小端的问题。
如果我们将0x1234abcd写入到以0x0000开始的内存中,则结果为
大端 小端
0x0000 0x12 0xcd
0x0001 0x34 0xab
0x0002 0xab 0x34
0x0003 0xcd 0x12
下面Keil C51编译出的代码来看,Keil 是大端的
68: a.w = 0x1234;
69:
C:0x15AC 752812 MOV 0x28,#0x12
C:0x15AF 752934 MOV 0x29,#0x34
从C51定时器的寄存器地址来看,我认为C51 CPU本身应该是小端的,以下摘自Keil 的帮助文档:
the 8052 uses addresses 0xCC and 0xCD for the low and high bytes of timer/counter 2 respectively.
Access to 16-bit SFRs using sfr16 is possible only when the low byte immediately precedes the high byte (little endian) and when the low byte is written last. The low byte is used as the address in the sfr16 declaration. For example:
sfr16 T2 = 0xCC; /* Timer 2: T2L 0CCh, T2H 0CDh */
sfr16 RCAP2 = 0xCA; /* RCAP2L 0CAh, RCAP2H 0CBh */ |
|