Fw: [問題] funtion、address、instruction的關係
※ [本文轉錄自 C_and_CPP 看板 #1JjIuUDM ]
作者: NoTeXactLy (NoTeXactLy) 看板: C_and_CPP
標題: [問題] funtion、address、instruction的關係
時間: Thu Jul 3 18:19:06 2014
以下是書本的句子:
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 instruction、instruction、function call這三者指同樣東西嗎?
而function是指function definition嗎?
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 175.182.140.221
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1404382750.A.356.html
→
07/03 19:08, , 1F
07/03 19:08, 1F
→
07/03 19:09, , 2F
07/03 19:09, 2F
對
只是這剛好是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
→
07/03 21:30, , 3F
07/03 21:30, 3F
→
07/03 21:31, , 4F
07/03 21:31, 4F
→
07/03 21:32, , 5F
07/03 21:32, 5F
→
07/03 21:32, , 6F
07/03 21:32, 6F
→
07/03 21:33, , 7F
07/03 21:33, 7F
但是課文中
只有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
→
07/03 23:05, , 8F
07/03 23:05, 8F
假設當
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
→
07/03 23:47, , 9F
07/03 23:47, 9F
→
07/03 23:48, , 10F
07/03 23:48, 10F
→
07/03 23:49, , 11F
07/03 23:49, 11F
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
→
07/04 08:29, , 12F
07/04 08:29, 12F
→
07/04 18:32, , 13F
07/04 18:32, 13F
→
07/04 18:33, , 14F
07/04 18:33, 14F
→
07/04 18:33, , 15F
07/04 18:33, 15F
→
07/04 18:34, , 16F
07/04 18:34, 16F
→
07/04 18:35, , 17F
07/04 18:35, 17F
→
07/04 18:35, , 18F
07/04 18:35, 18F
→
07/04 18:36, , 19F
07/04 18:36, 19F
→
07/04 18:36, , 20F
07/04 18:36, 20F
您誤解了
我對於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
→
07/06 01:29, , 21F
07/06 01:29, 21F
→
07/06 01:30, , 22F
07/06 01:30, 22F
→
07/06 01:32, , 23F
07/06 01:32, 23F
→
07/06 01:33, , 24F
07/06 01:33, 24F
謝謝witchang的專業解答
也感謝另一位版友tjjh89017寄信畫圖解釋
※ 編輯: NoTeXactLy (175.180.193.173), 07/06/2014 22:33:25
※ 發信站: 批踢踢實業坊(ptt.cc)
※ 轉錄者: NoTeXactLy (175.180.193.173), 07/12/2014 03:01:48
Sub_CS 近期熱門文章
PTT數位生活區 即時熱門文章