zoukankan      html  css  js  c++  java
  • [KeilC51]这几天遇到的问题

    ---恢复内容开始---

    大端与小端:

    1: 51单片机的指令集是大端的。

    example01
    1 ;汇编代码:
    2 lcall  0x3456
    3 ;对应机器码
    4 12 34 56

    2: KeilC51编译器数据结构是大端的。

    example02
     1 void main(void){
     2    long i = 0x12345678;  
     3    return;  
     4 }
     5 
     6 //对应反汇编代码
     7 /*
     8 *  mov A, #0x12
     9 *  mov 0x61, A
    10 *  mov A, #0x34
    11 *  mov 0x62, A
    12 *  mov A, #0x56
    13 *  mov 0x63, A
    14 *  mov A, #0x78
    15 *  mov 0x64, A
    16 *
    17 */

    CPU类型与编译器组织数据结构的大小端有无关系。。 

       昨天下载了N多编译器测试&阅读N多文章。。最后在电脑圈圈http://blog.21ic.com/user1/2198/archives/2007/41293.html的讨论里面看到的:

    你没留意到我贴中的“另外,对于位数大于8位的处理器,例如16位或者32位的处理器,由于寄存器宽度大于一个字节,那么必然存在着一个如果将多个字节安排的问题。”吗? 编译器跟硬件必须要设置一致程序才能正常运行。

     以前我一直以为数据在内存中的大小端是可以由编译器指定的。现在发现错得还不算太无可救药,对8位机来说固然没错(8位机只能1个byte1个byte的操作),但在16位或更高的平台中就不一定了,这时编译器的大小端要与硬件平台相配套了。话说回来,在非8位机编译器要指定数据结构的大小端也不是不可能,这时CPU只支持字节操作才能正常运行。额,我相信没有哪个写编译器的会这么暴殄天物。。

    网络资料备份:

    标  题: x86 gcc能将数据编译成按大端存储不?

    http://ar.newsmth.net/thread-b2fbbe2942a047.html

    Re: Using -mlittle-endian or -mbig-endian options....

    http://gcc.gnu.org/ml/gcc/2007-12/msg00331.html

    On Mon, Dec 10, 2007 at 09:55:24AM +0000, ashish mahamuni wrote:
    > Hi,
    > 
    > I am working on Intel i686 machine
    > I've Hello_World.c file.
    > When I give following command compiler gives error
    > that Invalid Option.
    > 
    > gcc -mlittle-endian Hello_World.c
    > or
    > gcc -mlittle-endian Hello_World.c
    > 
    > I am using 4.2 version of gcc (Latest one I guess).
    > How can I use this options?
    
    The x86 port does not support -mlittle-endian or -mbig-endian options (the -m
    options are machine/port specific).  Note, all x86's are little endian, so you
    don't need the switch in this case.  The -mlittle-endian switch is available on
    ports that support both little endian and big endian, such as the ARM, MIPS,
    POWERPC, etc.
    
    -- 
    Michael Meissner, AMD
    90 Central Street, MS 83-29, Boxborough, MA, 01719, USA
    michael.meissner@amd.com
    
  • 相关阅读:
    python challenge level 2
    python challenge level1
    近期很忙
    python challenge level 3
    链 小实验
    结构体小小应用
    结构体 弄成绩统计比较好
    HTC学习
    WEBFX XTREE学习笔记
    向dataset中添加一行记录,老是忘了,记下来
  • 原文地址:https://www.cnblogs.com/alimy/p/2976716.html
Copyright © 2011-2022 走看看