→ tjjh89017:這看起來是組合語言的東西 07/03 19:08
→ tjjh89017:function call inst => asm: call some_func 07/03 19:09
對
只是這剛好是C++的課文
想請教c++的function call in calling function與called function兩者
從instruction的角度看上文提到的address是甚麼樣子?
如果main()裡面有個func_one()
function call是func_one()
calling function是main()
called function是
整個func_one()的definition
func_one()
{
...
}
當compilation之後
memory address of the function call instruction會被放到
main()的func_one()之後
這是上述課文的意思嗎?
謝謝
※ 編輯: NoTeXactLy (175.182.140.221), 07/03/2014 21:04:27
※ 編輯: NoTeXactLy (175.182.140.221), 07/03/2014 21:05:41
→ carylorrk:address of function call instruction push to stack是 07/03 21:30
→ carylorrk:runtime 做的事,不是 compile time 07/03 21:31
→ carylorrk:簡單來說這句就是在說每次執行到 function call 指令時 07/03 21:32
→ carylorrk:會先記下 function return 回來時的位置,也就是當初你 07/03 21:32
→ carylorrk:call function 跳走的下一條指令 07/03 21:33
但是課文中
只有copies function arguments to the stack
而
the program stores the memory address of the instruction immediately
following the function call
這句話並沒有to the stack
※ 編輯: NoTeXactLy (175.182.140.221), 07/03/2014 22:39:54
→ azureblaze:因為不見得要放stack 雖然一般都放stack 07/03 23:05
假設當
function call instruction的位址是69-75
function(整個definition)的位址是108-132
另外beginning of the function(整個definition)的位址是108
那麼會存76到133的意思嗎?
或是存76到stack但不會是133?
謝謝
※ 編輯: NoTeXactLy (175.182.140.221), 07/03/2014 23:25:41
※ 編輯: NoTeXactLy (175.182.140.221), 07/03/2014 23:27:56
※ 編輯: NoTeXactLy (175.182.140.221), 07/03/2014 23:39:56
※ 編輯: NoTeXactLy (175.182.140.221), 07/03/2014 23:46:53
→ MOONRAKER:有創意。 07/03 23:47
→ MOONRAKER:身為一個程式修理員,多找幾本書看也很合理且合邏輯 07/03 23:48
→ MOONRAKER:書上沒說to stack就咬死一定沒to stack,又不是背六法。 07/03 23:49
to stack當然可以
我也沒說一定沒to stack
您說的咬死比較有創意
謝謝
※ 編輯: NoTeXactLy (175.182.140.221), 07/04/2014 00:14:14
※ 編輯: NoTeXactLy (175.182.140.221), 07/04/2014 00:16:28
→ MOONRAKER:果然是背六法的。 07/04 08:29
→ Killercat:function arguments放的位置並沒有明確定義名稱 07/04 18:32
→ Killercat:甚至有的還是丟到registry做pass的 07/04 18:33
→ Killercat:他唯一的名稱就叫作Function Frame 07/04 18:33
→ Killercat:居泥在他是不是stack...似乎有點搞錯方向了你 07/04 18:34
→ Killercat:這東西我只能跟你說 位置頗微妙 你要先搞懂stack/heap 07/04 18:35
→ Killercat:怎麼長的 比較有這種感覺就是... 07/04 18:35
→ Killercat:另外規格也沒有指名function frame要丟再哪裡 編譯器 07/04 18:36
→ Killercat:可以自己決定的 07/04 18:36
您誤解了
我對於function arguments放在何處並沒有疑問
所以也不"拘泥"function arguments是否放在stack
若您沒仔細閱讀英文句子
我可以很肯定是您搞錯方向
我的疑問在文章的前兩列
When a program reaches the function call instruction, the program stores the
memory address of the instruction immediately following the function call,
copies function arguments to the stack(a block of memory reserved for that
purpose), jumps to the memory location that marks the beginning of the
function, executes the instructon whose address it saved.
也就是
When a program reaches the function call instruction, the program stores the
memory address of the instruction immediately following the function call,
第三列
copies function arguments to the stack
並非我的疑問所在
且此處的to the stack並非針對前兩列
最後謝謝carylorrk板友正確理解我的疑問並寄信解釋
※ 編輯: NoTeXactLy (112.105.249.5), 07/04/2014 18:55:26
※ 編輯: NoTeXactLy (175.182.114.79), 07/04/2014 23:52:35
→ witchang:放不放stack要看平台的Call Convention(呼叫慣例)請查網. 07/06 01:29
→ witchang:functionCall ins 一般是跳躍指令,所以跳之前將引數搬到 07/06 01:30
→ witchang:Reg或Stack是編譯器的事情並非Runtime~跳躍指令會紀錄返 07/06 01:32
→ witchang:回位置到rpc,return的asm會從rpc調回回去後執行的位址~ 07/06 01:33
謝謝witchang的專業解答
也感謝另一位版友tjjh89017寄信畫圖解釋
※ 編輯: NoTeXactLy (175.180.193.173), 07/06/2014 22:33:25
※ NoTeXactLy:轉錄至看板 Sub_CS 07/12 03:01