Big-endian arithmetic on ARM

  • Replies:0
Mar Kim
  • Forum posts: 1

Feb 19, 2017, 7:50:11 PM via Website

I observe that "ARMv6 and above" is biendian. I would like to operate in big-endian mode so as to process some big-endian data in my app, but my attempts to do so have failed. I am looking at the setend assembly instruction. (Can't post a link to the doc, as I am a new user on this forum.)

Lacking experience, I naively put a __asm__("setend be") instruction in my C code and then called the function that envelopes this instruction from a Java class.

JNIEXPORT void JNICALL Java_mypackage_myclass_setend(JNIEnv *env, jclass type) {
    log("pre setend");
    __asm__("setend be");
    log("post setend");
}

The result is a crash with the following output on my adb log:

02-19 10:18:37.857 21939-21939/mypackage D/my-c-code: pre setend
02-19 10:18:37.857 21939-21939/mypackage A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xc5a6d3f2 in tid 21939 (vis.mypackage)

                                                               [ 02-19 10:18:37.857   154:  154 W/         ]
                                                               debuggerd: handling request: pid=21939 uid=10097 gid=10097 tid=21939

Can anyone tell me if I can achieve my goal of doing big-endian arithmetic on my Pixel C? I'd rather not manually change the order of bytes in my input stream. I am trying to process realtime audio, which comes in as an array of shorts (big-endian bytes, little-endian bits).

Reply