作者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://webptt.com/cn.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