我想調用一個沒有參數的函數。我知道函數的地址在EAX寄存器中。爲什麼不是這個代碼這樣做:什麼推動相同的寄存器兩次做?
push EAX
push EAX
ret
而這一次調用該函數:
push next_a
push EAX
ret
next_a:
next_a
是我想調用的函數。但我知道這個函數的地址位於EAX
第一個:推動EAX兩次的是什麼?
我想調用一個沒有參數的函數。我知道函數的地址在EAX寄存器中。爲什麼不是這個代碼這樣做:什麼推動相同的寄存器兩次做?
push EAX
push EAX
ret
而這一次調用該函數:
push next_a
push EAX
ret
next_a:
next_a
是我想調用的函數。但我知道這個函數的地址位於EAX
第一個:推動EAX兩次的是什麼?
只要按照發生的事情。我們來調用函數foo
。
push eax ; address of foo on the stack
push eax ; address of foo on the stack again
ret ; picks off the top item from the stack, goes to foo
foo:
; body of function
ret ; picks off the top item from stack, which is still foo
; so invokes itself again
第二個例子:
push next_a ; address of next_a on the stack
push eax ; address of foo on the stack
ret ; picks off the top item from the stack, goes to foo
foo:
; body of function
ret ; picks off the top item from stack, which is next_a
next_a:
; execution continues here
因此,這兩個版本做呼叫foo
第一。 無論如何,如果你真的只想打電話foo
(XY問題),然後使用call eax
並完成它。
next_a是我想要調用的函數。
真的嗎?如果eax=next_a
那麼這兩段代碼完全相同。
由於某種原因,該課程的教授說,第一個例子不是調用這個函數,我試圖找出它爲什麼不能很好地工作...... –
@TalShani:嗯,它跳轉到函數,但它不是真的一個'call',因爲它不會推送與'call'相同的返回地址。 –
謝謝!你知道它是什麼推動,而不是返回地址? –
你能發表更多的代碼嗎?什麼是「next_a」?點擊您問題下方的「修改」,並添加更多代碼。 –
這是我想打電話的功能。但我知道這個函數的地址位於EAX ... –
這是我從考試中得到的一個問題。我知道簡單的只是使用呼叫;但教授說第一個例子不工作,我試圖找出爲什麼 –