集会;有谁知道如何将多个参数带入函数中? (Linux、-m32、x86)

标签 assembly arguments

创建一个应该接受多个参数的函数,可能最多十个参数。但是当我看到我的寄存器前面没有足够的空间时,我陷入了困境。有人知道该怎么做吗?

                    .globl myfunction    
 myfunction:

          pushl     %ebp                    # start of
          movl      %esp, %ebp              # function

          movl      8(%ebp), %ecx           # first argument
          movl      12(%ebp), %edx          # second argument
          movl      16(%ebp), %eax          # this gonna fill all the space

最佳答案

您可以在第一次需要参数时获取参数,而不是将所有参数放入函数开头的寄存器中。我不知道该函数应该做什么,但作为一个有 4 个参数的示例,您只想将所有参数添加在一起,它看起来像这样:

.globl myfunction    
myfunction:
      pushl     %ebp                    # start of
      movl      %esp, %ebp              # function

      movl      8(%ebp), %eax           # first argument
      movl      12(%ebp), %edx          # second argument
      addl      (%edx), %eax            # adding second argument to first

      movl      16(%ebp), %edx          # third argument
      addl      (%edx), %eax            # adding third argument

      movl      20(%ebp), %edx          # forth argument
      addl      (%edx), %eax            # adding forth argument
      ...

希望这有帮助。

针对您的评论,我认为您可以执行以下操作:

movl %ebp, %ecx
addl $8, %ecx       # ecx does now point to the first argument

movl (%ecx), %eax  # copies the first argument to eax
addl $4, %ecx       # moves to the next argument

movl (%ecx), %eax  # copies the second argument to eax
addl $4, %ecx       # moves to the next argument

movl (%ecx), %eax  # copies the third argument to eax
...

关于集会;有谁知道如何将多个参数带入函数中? (Linux、-m32、x86),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386474/

相关文章:

C++ 类类型作为参数

c++ - C++ 构造函数中前导下划线的含义是什么?

Python 对象初始化错误。还是我误解了对象的工作原理?

c++ - 在内联汇编中使用函数范围的标签

math - 快速反范数函数

assembly - Intel x86 汇编语法中寄存器上的括号

linux - 在64位系统上组装32位二进制文​​件(GNU工具链)

assembly - x86 汇编语言高位和低位

python - 为什么此代码仅适用于 Something() 中的 *args?

c 控制台应用程序自动完成动态参数