Click here to Skip to main content
15,898,134 members
Articles / Mobile Apps / Windows Mobile

Endian Conversion in ARM and x86 Assembly

Rate me:
Please Sign up or sign in to vote.
3.18/5 (5 votes)
30 Sep 2008CPOL5 min read 48.5K   179   18  
How to solve Endian conversion in multiplatform application
    AREA code,CODE
   
cq_ntohl    FUNCTION
    EXPORT cq_ntohl
   
    stmdb sp!,{r1}

    ; subroutine body
    eor r1, r0, r0, ROR #16
    bic r1, r1, #0xFF, 16
    mov r0, r0, ror #8
    eor r0, r0, r1, lsr #8

    ldmia sp!,{r1}
    mov            pc, lr
   
    ENDFUNC
   
cq_ntohl_array    FUNCTION
    EXPORT cq_ntohl_array
   
    stmdb sp!,{r0, r1, r2, r3}

    ; subroutine body
next
    ldr r2, [r0]
    eor r3, r2, r2, ROR #16
    bic r3, r3, #0xFF0000
    mov r2, r2, ror #8
    eor r2, r2, r3, lsr #8
    str r2, [r0], #4
    subs    r1, r1, #1
    bne next

    ldmia sp!,{r0, r1, r2, r3}
    mov            pc, lr
   
    ENDFUNC
   
cq_ntohs    FUNCTION
    EXPORT cq_ntohs
   
    stmdb sp!,{r1}

    ; subroutine body
    mov r1, r0, lsl #8
    orr r0, r1, r0, lsr #8

    ldmia sp!,{r1}
    mov            pc, lr
   
    ENDFUNC
    
cq_ntohs_array    FUNCTION
    EXPORT cq_ntohs_array
   
    stmdb sp!,{r0, r1, r2, r3}

    ; subroutine body
next2
    ldrh r2, [r0]
    mov r3, r2, lsl #8
    orr r2, r3, r2, lsr #8
    strh r2, [r0], #2
    subs    r1, r1, #1
    bne next2

    ldmia sp!,{r0, r1, r2, r3}
    mov            pc, lr
   
    ENDFUNC
    
    END

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) mapbar
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions