Does my AMD-based machine use little endian or big endian?

前端 未结 7 1010
鱼传尺愫
鱼传尺愫 2020-12-05 02:54

I\'m going though a computers system course and I\'m trying to establish, for sure, if my AMD based computer is a little endian machine? I believe it is because it

相关标签:
7条回答
  • 2020-12-05 02:56
    /* by Linas Samusas  */
    
    #ifndef _bitorder 
    #define _bitorder 0x0008
    
    #if (_bitorder > 8)
    #define BE
    #else
    #define LE
    #endif
    

    and use this

    #ifdef LE
    #define Function_Convert_to_be_16(value)  real_function_to_be_16(value)
    #define Function_Convert_to_be_32(value)  real_function_to_be_32(value)
    #define Function_Convert_to_be_64(value)  real_function_to_be_64(value)
    #else
    #define Function_Convert_to_be_16
    #define Function_Convert_to_be_32
    #define Function_Convert_to_be_64
    #endif
    

    if LE

    unsigned long number1 = Function_Convert_to_be_16(number2);
    

    *macro will call real function and it will convert to BE

    if BE

    unsigned long number1 = Function_Convert_to_be_16(number2);
    

    *macro will be defined as word not a function and your number will be between brackets

    0 讨论(0)
  • 2020-12-05 02:57

    In answer to your final question, the answer is no. Linux is capable of running on big endian machines like e.g., the older generation PowerMacs.

    0 讨论(0)
  • 2020-12-05 03:07

    All x86 and x86-64 machines (which is just an extension to x86) are little-endian.

    You can confirm it with something like this:

    #include <stdio.h>
    int main() {
        int a = 0x12345678;
        unsigned char *c = (unsigned char*)(&a);
        if (*c == 0x78) {
           printf("little-endian\n");
        } else {
           printf("big-endian\n");
        }
        return 0;
    }
    
    0 讨论(0)
  • 2020-12-05 03:12

    Assuming you have Python installed, you can run this one-liner, which will print "little" on little-endian machines and "big" on big-endian ones:

    python -c "import struct; print 'little' if ord(struct.pack('L', 1)[0]) else 'big'"
    
    0 讨论(0)
  • 2020-12-05 03:12

    You have to download a version of Ubuntu designed for big endian machines. I know only of the PowerPC versions. I'm sure you can find some place which has a more generic big-endian implementation.

    0 讨论(0)
  • 2020-12-05 03:19

    "Intel-compatible" isn't very precise.

    Intel used to make big-endian processors, notably the StrongARM and XScale. These do not use the IA32 ISA, commonly known as x86.

    Further back in history, Intel also made the little-endian i860 and i960, which are also not x86-compatible.

    Further back in history, the prececessors of the x86 (8080, 8008, etc.) are not x86-compatible either. Being 8-bit processors, endianness doesn't really matter...

    Nowadays, Intel still makes the Itanium (IA64), which is bi-endian: normal operation is big-endian, but the processor can also run in little-endian mode. It does happen to be able to run x86 code in little-endian mode, but the native ISA is not IA32.

    To my knowledge, all of AMD's processors have been x86-compatible, with some extensions like x86_64, and thus are necessarily little-endian.

    Ubuntu is available for x86 (little-endian) and x86_64 (little-endian), with less complete ports for ia64 (big-endian), ARM(el) (little-endian), PA-RISC (big-endian, though the processor supports both), PowerPC (big-endian), and SPARC (big-endian). I don't believe there is an ARM(eb) (big-endian) port.

    0 讨论(0)
提交回复
热议问题