小编Yi-*_*ezi的帖子

在推入/弹出其他寄存器的同时访问相对于 EBP 的堆栈中的函数参数?

我正在编写一个汇编程序和一个 C 程序;C 程序将调用一个用汇编编写的函数。环境是 Ubuntu 18.04LTS x64。

它是为 32 位 x86 设计的,将由 NASM 编译,但无法传递正确的参数。

为了简化问题,我只是改变了我的函数来获得ab的总和。

extern int FindPattern(int a,int b);

int result;
result=FindPattern(1,1);
printf("%d\n",result);
Run Code Online (Sandbox Code Playgroud)
global FindPattern
 section .text
FindPattern:
    push    ebp
    push    esi
    push    edi
    push    ebx
    push    edx
    push    ecx
    
    mov     ebp,esp
    mov     esi,[ebp+8]     ; a
    mov     edi,[ebp+12]    ; b
    mov     eax,0
    add     eax,esi
    add     eax,edi         ; return a+b
    
    pop     ecx
    pop     edx
    pop     ebx
    pop     edi               
    pop     esi
    pop     ebp
    ret          
Run Code Online (Sandbox Code Playgroud)

该函数只是将a和 …

c x86 assembly nasm calling-convention

3
推荐指数
1
解决办法
50
查看次数

标签 统计

assembly ×1

c ×1

calling-convention ×1

nasm ×1

x86 ×1