How to test your code on a machine with big-endian architecture?
Asked Answered
C

3

23

Both ideone.com and codepad.org have Little-Endian architechtures.

I want to test my code on some machine with Big-Endian architechture (for example - Solaris - which I don't have). Is there some easy way that you know about?

Casuist answered 15/5, 2010 at 5:53 Comment(4)
Wouldn't Solaris on an x86 or x86-64 architecture be little-endian too? And I think SPARC is bi-endian to boot.Ley
@JUST MY correct OPINION: I think you are right. It should be. Though I am not sure. lets wait for others to comment.Casuist
Yes, Solaris matches the processor endianness (as does OS X, for that matter). It's big-endian on SPARC and little-endian on x86/x86-64.Adelladella
Possible duplicate of Imitate/emulate a big-endian behavior in C?Surrebuttal
R
10

Googling "big endian online emulator" lead me to PearPC. I assume that if you have the patience you can install Mandrake Linux, get gcc, and go party.

Reentry answered 18/5, 2010 at 23:9 Comment(2)
Isnt power pc bi-endian? Which means in a linux with could be little endian?Selfgratification
@AndréPuel: Well, if someone were to bother porting Linux to ppcle, sure. But what would be the point? This won't let it run anywhere it couldn't already, will it?Hermann
A
27

QEMU supports emulating several big-endian architectures. Note that some architectures support both endiannesses; some (Itanium, ARM) are primarily used as little-endian while others (PowerPC, MIPS) are primarily used as big-endian.

Aurélien Jarno wrote some HOWTOs on installing Debian on an emulated MIPS or SPARC machine which should be a good start.

Adelladella answered 15/5, 2010 at 6:17 Comment(1)
I tried QEMU but only got weird error messages or it just hung up.Boeotia
R
10

Googling "big endian online emulator" lead me to PearPC. I assume that if you have the patience you can install Mandrake Linux, get gcc, and go party.

Reentry answered 18/5, 2010 at 23:9 Comment(2)
Isnt power pc bi-endian? Which means in a linux with could be little endian?Selfgratification
@AndréPuel: Well, if someone were to bother porting Linux to ppcle, sure. But what would be the point? This won't let it run anywhere it couldn't already, will it?Hermann
B
8

If you are using Ubuntu, you can download MIPS cross compiler (or any other big-endian architecture that is supported by QEMU, and has a prebuilt cross compiler), and QEMU-user, then compile your code in static linkage, and just run it.

sudo apt-get install gcc-multilib-mips-linux-gnu gcc-mips-linux-gnu qemu-user

and then

mips-linux-gnu-gcc test.c -o test -static
qemu-mips ./test
Bedim answered 14/8, 2019 at 11:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.