程序集传递函数指针 [英] Assembly pass pointer to function
本文介绍了程序集传递函数指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将DWORD变量作为指针参数发送给函数
I'm trying to sent DWORD variable into function as pointer paramater
variable1 dd 1
...
push [variable1] ; push variable adress
call _InitPoiner
...
_InitPoiner:
;
push ebp
mov ebp, esp
;
lea eax, [ebp+8] ; load address
mov dword [eax], 10 ; move value 10 into that address
pop ebp
ret
...
push [variable1]
push sdigit ; where sdigit db '%d', 0x0D, 0x0A, 0
call [printf]
但是variable1是1,而不是11,为什么?
but variable1 is 1, not 11 , why?
推荐答案
您确定要在完成后弹出变量吗?
You are making sure that you pop your vars when done?
以您的示例为例,我看不到该变量永远是11.在dd
赋值处它从1开始,那么如果您的数学正确,那么它将是10.要通过调试器逐步执行此操作,可以检查lea / mov
组合是否正常工作.无论哪种方式,我都希望1或10,而不是11.
Looking at your example, I see no way that the variable could ever be 11. It starts as 1 at the dd
assignment, then if your math in the lea is correct, it would then be 10. If you were to step this through a debugger, you could check if your lea / mov
combo is working right. Either way, I would expect 1 or 10, not 11.
也许您是要add
而不是mov
?
这篇关于程序集传递函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文