Ryan
Ryan

Reputation: 31

ARM Assembly to C code

I am trying to figure out what this function in arm does,

00000000 <ibisFunction>:
  0: e1510002 cmp r1, r2
  4: e92d0030 push {r4, r5}
  8: aa000009 bge 34 <ibisFunction+0x34>
  c: e080c102 add r12, r0, r2, lsl #2
  10: e0803101 add r3, r0, r1, lsl #2
  14: e59c4000 ldr r4, [r12]
  18: e5935000 ldr r5, [r3]
  1c: e2811001 add r1, r1, #1
  20: e2422001 sub r2, r2, #1
  24: e1510002 cmp r1, r2
  28: e40c5004 str r5, [r12], #-4
  2c: e4834004 str r4, [r3], #4
  30: bafffff7 blt 14 <ibisFunction+0x14>
  34: e8bd0030 pop {r4, r5}
  38: e12fff1e bx lr

the only thing I have been told is that the function in c code is

int* ibisFunction(int *a, int b, int c)

I have to find the equivalent in C and I have gotten as far as:

int* ibisFunction(int *a, int b, int c){
  if (b<c){
    d=a[c];
    e=a[c];
    while (b<c){
      f=g;
      g=e;
      b++;
      c--;
      d[]=g;
      e[]=f;
    }
  }
}

Can someone please help me find the C equivalent, and explain what I did wrong?

Upvotes: 2

Views: 1318

Answers (1)

Dric512
Dric512

Reputation: 3729

I think this is more something like:

uint32_t ibisFunction(uint32_t *a, int b, int c){
  while (b < c) { // r1, r2
    d = a[c];     // r4, using r12 as address
    e = a[b];     // r5, using r3 as address
    a[--c] = e;   // STR r5 to r12 - 4
    a[++b] = d;   // STR r4 to r3 + 4
  }
  return a;
}

Upvotes: 1

Related Questions