【问题标题】:ARM Assembly to C codeARM 汇编到 C 代码
【发布时间】:2016-04-29 03:24:04
【问题描述】:

我想弄清楚arm中的这个函数是做什么的,

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

我被告知的唯一一件事是c代码中的函数是

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

我必须在 C 中找到等价物,并且我已经做到了:

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;
    }
  }
}

有人可以帮我找到 C 的等价物,并解释我做错了什么吗?

【问题讨论】:

  • 你怎么知道你做错了什么? (我不否认你做过,只是想了解上下文。)
  • 您可能想看的几件事:(1)您的前两个作业将a[c] 作为RHS,但相应的汇编代码在这些地方有不同的东西; (2) 你有一些看起来像d[]=g 的作业,在方括号内没有任何内容,这是不对的; (3) 您的 C 代码没有反映地址 28 和 2C 的 后索引 寻​​址的效果。

标签: assembly arm


【解决方案1】:

我认为这更像是:

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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    • 2011-07-20
    • 2015-03-03
    • 1970-01-01
    相关资源
    最近更新 更多