部件;有没有人知道如何将多个参数纳入函数? (linux,-m32,x86)

时间:2013-05-05 16:10:14

标签: 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

1 个答案:

答案 0 :(得分:4)

您可以在首次需要时获取参数,而不是将所有参数放入函数开头的寄存器中。我不知道该函数应该做什么,但作为一个带有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
...