Sub_CS 板


LINE

※ [本文转录自 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 instructioninstructionfunction 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



※ 发信站: 批踢踢实业坊(ptt.cc)
※ 转录者: NoTeXactLy (175.180.193.173), 07/12/2014 03:01:48







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灯, 水草

请输入看板名称,例如:Boy-Girl站内搜寻

TOP