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