从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:
unsigned long *x = 0x1000;
*x = 0x12345678;
:
0x1000: 12
0x1001: 34
0x1002: 56
0x1003: 78
大端小端并不是编译器说了算,是CPU架构说了算.8位机一样有16位操作数,你看16位操作数是大端还是小端.比如
ljmp 0x1234
看它的机器码是怎么写的,就清楚了:
02 12 34
如果我们将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 */
一周热门 更多>