c - 将汇编语言翻译成 C

标签 c assembly x86 reverse-engineering

我现在正在复习期中练习。这个问题给出了一段汇编代码(IA32)并指示编写它的 C 等价物。只是想确保我做的正确。谢谢!

给出的汇编程序:

.global _someOperation
_someOperation:
    pushl %ebp
    movl %esp, %ebp
    movl 8(%ebp), %ebx
    movl 12(%ebp), %edx
    decl %edx
    xorl %esi, %esi
    movl (%ebx, %esi, 4), %eax
continue:
    incl %esi
    cmpl (%ebx, %esi, 4), %eax
    jl thelabel
    movl (%ebx, %esi, 4), %eax
thelabel:
    cmp %esi, %edx
    jne continue
    movl %ebp, %esp
    popl %ebp
    ret

这是我写的代码:

void someOperation(int *num, int count)  //Given
{
    int k; //Given
    count--;
    int i = 0;
    k = num[i];
    i++;
    while(count != i)
    {
        if(k >= num[i]
            k = num[i];
        i++;
    }
    return (k);
 }

最佳答案

看起来很接近我,虽然在 ASM 中增量只在循环的开始,并且第一次通过时不检查条件。考虑改用 DO...WHILE。

编辑:另外,您的作业是错误的。 MOV 指令从第二个参数复制到第一个参数。您在 C 代码中采用了相反的方式。

关于c - 将汇编语言翻译成 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26964119/

相关文章:

c++ - 错误 LNK1181 : cannot open input file when compiling as . LIB

assembly - 请解释一下下面代码中的x86汇编语言指令lds si,[bp+0]

windows - x86 程序参数位置

assembly - x86 - 通过 RETF 从 32 位切换到 64 位

c - 在给定汇编代码的情况下查找丢失的 C 代码?

这个奇怪的函数可以直接计算吗?

c - 如何消除相当大的对话框上的闪烁?

macos - 为什么这段汇编代码会抛出段错误?

c - 从 C 访问内联汇编器中定义的数组

c++ - 如何在有和没有 std::vector 的情况下正确使用 jpeg_mem_dest