Reverse Engineering challenge #7.

Tags: ARM MIPS ARM64 X64 ASM L1 .

What does this code do? This is one of the simplest exercises I made, but still this code can be served as useful library function and is certainly used in many modern real-world applications.

Optimizing GCC 4.8.2:

   0:                movzx  edx,BYTE PTR [rdi]
   3:                mov    rax,rdi
   6:                mov    rcx,rdi
   9:                test   dl,dl
   b:                je     29 
   d:                nop    DWORD PTR [rax]
  10:                lea    esi,[rdx-0x41]
  13:                cmp    sil,0x19
  17:                ja     1e 
  19:                add    edx,0x20
  1c:                mov    BYTE PTR [rcx],dl
  1e:                add    rcx,0x1
  22:                movzx  edx,BYTE PTR [rcx]
  25:                test   dl,dl
  27:                jne    10 
  29:                repz ret

Optimizing GCC 4.9.3 for ARM64:

0:           ldrb    w1, [x0]
4:           mov     x3, x0
8:           cbz     w1, 2c 
c:           sub     w2, w1, #0x41
10:          add     w1, w1, #0x20
14:          uxtb    w2, w2
18:          cmp     w2, #0x19
1c:          b.hi    24 
20:          strb    w1, [x3]
24:          ldrb    w1, [x3,#1]!
28:          cbnz    w1, c 
2c:          ret

(ARM) Optimizing Keil 5.05 (ARM mode):

        MOV      r1,r0
        LDRB     r2,[r1,#0]
        CMP      r2,#0
        BXEQ     lr
        SUB      r3,r2,#0x41
        CMP      r3,#0x19
        ADDLS    r2,r2,#0x20
        STRBLS   r2,[r1,#0]
        ADD      r1,r1,#1
        B        |L0.4|

(ARM) Optimizing Keil 5.05 (Thumb mode):

        MOVS     r1,r0
        B        |L0.18|
        MOVS     r3,r2
        SUBS     r3,r3,#0x41
        CMP      r3,#0x19
        BHI      |L0.16|
        ADDS     r2,r2,#0x20
        STRB     r2,[r1,#0]
        ADDS     r1,r1,#1
        LDRB     r2,[r1,#0]
        CMP      r2,#0
        BNE      |L0.4|
        BX       lr

Optimizing GCC 4.4.5 for MIPS:

        lb      $5,0($4)
        beq     $5,$0,$L9
        move    $2,$4

        move    $3,$4
        andi    $5,$5,0x00ff
        addiu   $6,$5,-65
        andi    $6,$6,0x00ff
        sltu    $6,$6,26
        beq     $6,$0,$L3
        addiu   $5,$5,32
        sb      $5,0($3)
        addiu   $3,$3,1
        lb      $5,0($3)
        bne     $5,$0,$L8
        andi    $5,$5,0x00ff
        j       $31

More challenges:; about solutions: