小编Ngu*_*Nam的帖子

这两条指令在以下函数中做了什么?

所以我几乎是 IA32 汇编语言的菜鸟。我尝试将此 C 函数编译为 IA32 程序集 ( -mpreferred-stack-boundary=2):

__attribute__((cdecl))
int odd_sum(int a[], int n, int sum) {
  if (n == 0) return sum;
  else if ((a[n-1] % 2) == 0)
    return odd_sum(a, n-1, sum);
  else return odd_sum(a, n-1, sum + a[n-1]);
}
Run Code Online (Sandbox Code Playgroud)

海湾合作委员会输出这个:

    .file   "test.c"
    .text
    .globl  _odd_sum
    .def    _odd_sum;   .scl    2;  .type   32; .endef
_odd_sum:
LFB0:
    .cfi_startproc
    pushl   %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    subl    $12, %esp
    cmpl    $0, 12(%ebp)
    jne L2 …
Run Code Online (Sandbox Code Playgroud)

c x86 assembly

2
推荐指数
1
解决办法
91
查看次数

标签 统计

assembly ×1

c ×1

x86 ×1