C_and_CPP 板


LINE

以下是書本的句子: 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. 出處: http://tinyurl.com/o6xo4bd C++ primer plus books.google.com 請問 function call instructioninstructionfunction call這三者指同樣東西嗎? 而function是指function definition嗎? 謝謝 --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.182.140.221
※ 文章網址: http://webptt.com/m.aspx?n=bbs/C_and_CPP/M.1404382750.A.356.html
1F:→ tjjh89017:這看起來是組合語言的東西 07/03 19:08
2F:→ 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
3F:→ carylorrk:address of function call instruction push to stack是 07/03 21:30
4F:→ carylorrk:runtime 做的事,不是 compile time 07/03 21:31
5F:→ carylorrk:簡單來說這句就是在說每次執行到 function call 指令時 07/03 21:32
6F:→ carylorrk:會先記下 function return 回來時的位置,也就是當初你 07/03 21:32
7F:→ 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
8F:→ 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
9F:→ MOONRAKER:有創意。 07/03 23:47
10F:→ MOONRAKER:身為一個程式修理員,多找幾本書看也很合理且合邏輯 07/03 23:48
11F:→ 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
12F:→ MOONRAKER:果然是背六法的。 07/04 08:29
13F:→ Killercat:function arguments放的位置並沒有明確定義名稱 07/04 18:32
14F:→ Killercat:甚至有的還是丟到registry做pass的 07/04 18:33
15F:→ Killercat:他唯一的名稱就叫作Function Frame 07/04 18:33
16F:→ Killercat:居泥在他是不是stack...似乎有點搞錯方向了你 07/04 18:34
17F:→ Killercat:這東西我只能跟你說 位置頗微妙 你要先搞懂stack/heap 07/04 18:35
18F:→ Killercat:怎麼長的 比較有這種感覺就是... 07/04 18:35
19F:→ Killercat:另外規格也沒有指名function frame要丟再哪裡 編譯器 07/04 18:36
20F:→ 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
21F:→ witchang:放不放stack要看平台的Call Convention(呼叫慣例)請查網. 07/06 01:29
22F:→ witchang:functionCall ins 一般是跳躍指令,所以跳之前將引數搬到 07/06 01:30
23F:→ witchang:Reg或Stack是編譯器的事情並非Runtime~跳躍指令會紀錄返 07/06 01:32
24F:→ 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







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Tech_Job站內搜尋

TOP