精華區beta CSSE 關於我們 聯絡資訊
※ 引述《l314 (紅虫)》之銘言: : 請問一下calling convention, : caller save register及callee save register,與下面這些敘述有什麼關聯嗎? : pascal convention 規定:三數傳遞次序由左而右,stack frame 的清理由被呼叫端( : callee)負責。 : c convention 規定:三數傳遞次序由右而左,stack frame 的清理由呼叫端(caller) : 負責。 : 由於 pascal convention 規定 stack frame 的清理由被呼叫端(callee)負責,因此如 : 對同一函式呼叫一千次,其 stack frame cleanup routine只需一份(位於 callee 內, : 由編譯器加入)。 : 由於 c convention 規定 stack frame 的清理由呼叫端(caller)負責,因此對同一個 : 函式呼叫一千次,其 stack frame cleanup routine需 1000 份(位於呼叫點,由編譯器 : 加入)。 : 因此,採用 pascal calling convention,對於降低程式碼大小(並因而增加執行速度) : ,在某些情況下很有幫助。這是為什麼早期 Windows 系統內部幾乎完全採用 pascal : calling convention 的原因。 : 但是 pascall convention 不支援「個數不定之引數」。例如 printf()的引數個數不一 : 定,那就一定得使用 c calling convention。 對不確定參數個數的函式來說, caller才知道該如何呼叫pop()來清除stack, callee就不曉得了, 所以這種情況下, c convention 才能支援 http://www.unixwiz.net/techtips/win32-callconv.html 有比較完整的解說 : 還有下面這句,我也不太懂它的意思.. : If a procedure is called n times, then the portion of the calling sequence in : the various callers is generated n times. However, the portion of the callee : is shared by calls, so it is generated just once. Hence, it is desirable to : put as much of the calling sequence into the callee as possible. : 最後請問calling convention與call by value, call by reference, call by name.. calling convention 應該是指 caller 和 callee 函式間, 參數或回傳值在傳遞過程中在 記憶空間中的存放順序、結束時由誰負責清除之類的規則.. 和call by value等所指的應該是不一樣的東西 : 又有什麼關聯呢? : 請問小弟我是不是什麼核心觀念沒弄清楚,所以才會產生前述的混淆.. : 請板上前輩指點一下..謝謝.. -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.73.164.188 ※ 編輯: Lapha 來自: 203.73.164.188 (06/24 17:15)
l314:謝謝您~~ ^^ 06/25 12:13