ASM不在堆栈上加载参数

发布于 2025-01-30 18:32:45 字数 721 浏览 2 评论 0原文

我有一个可以使用两个整数作为参数的函数,但是每当我访问堆栈时,不在那里,我无法使用它们,因此我将随机内存值作为输出。据我了解,要调用一个函数,除了它的代码上,我不需要其他任何东西。这是Inline Intel ASM X86

#include <stdio.h>
int getNum1(int a);
int main()
{
    int num1=0, num2 = 8;
    __asm {
        // push ebp
        // mov ebp,esp
        
        push num1
        push num2
        
        call getNum1

        add esp,8
        // pop ebp

        mov num1,eax
    }
    printf("%d", num1);
    return 0;
}

//this is only supossed to return the value of a, but i get random stuff
int getNum1(int a, int b)
{
    __asm {
        push ebp
        mov ebp,esp
        push ebx


        mov ebx,[ebp+12]
        mov eax,ebx


        pop ebx
        pop ebp
    }
}

I have a function that is supossed to use two integers as parameters, but whenever I access to the stack, the aren't there and I cannot use them, so I get random memory values as output. As I understand, to call a function I don't need anything else apart from what its on my code. This is inline intel asm x86

#include <stdio.h>
int getNum1(int a);
int main()
{
    int num1=0, num2 = 8;
    __asm {
        // push ebp
        // mov ebp,esp
        
        push num1
        push num2
        
        call getNum1

        add esp,8
        // pop ebp

        mov num1,eax
    }
    printf("%d", num1);
    return 0;
}

//this is only supossed to return the value of a, but i get random stuff
int getNum1(int a, int b)
{
    __asm {
        push ebp
        mov ebp,esp
        push ebx


        mov ebx,[ebp+12]
        mov eax,ebx


        pop ebx
        pop ebp
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文