Re: [問題] 關於 gcc 的 inline asm

看板C_and_CPP作者 (有趣生活)時間12年前 (2012/07/08 18:07), 編輯推噓3(300)
留言3則, 2人參與, 最新討論串2/2 (看更多)
※ 引述《BombCat (炸彈貓)》之銘言: : 定位有點尷尬的問題,簡單的題目原本打算練習inline asm : 在自己的ubuntu 12.04運作沒問題 : 但在zerojudge和ideone上都會出現SIGSEGV (segmentation fault?) : 不知道錯哪裡,想請問前輩code那裡有問題? : 題目:http://zerojudge.tw/ShowProblem?problemid=a053 : Code:http://ideone.com/a4Ho1#ul_inouterr 看起來是忘記在函式返回之後清理 stack 以 x86 C calling convention 來說,是由 caller 來做清理動作 原始程式在 "call scanf" 和 "call printf" 之前 都是 push 兩個 4-byte operand 進 stack 也就是讓 esp 暫存器減少 4*2 = 8 所以在 "call scanf" 和 "call printf" 之後,把 esp 加回來就可以了 修改結果 Code:http://ideone.com/z8L3D 可參考 wiki (還有其他種類,如 Win32 程式則常用 stdcall): http://en.wikipedia.org/wiki/X86_calling_conventions#cdecl -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.160.221.103

07/09 02:19, , 1F
U大好厲害,這個問題一直困擾我好久了終於知道哪裡做錯了
07/09 02:19, 1F

07/09 02:25, , 2F
再推一次
07/09 02:25, 2F

07/09 16:32, , 3F
推!
07/09 16:32, 3F
文章代碼(AID): #1F-Llr-E (C_and_CPP)
文章代碼(AID): #1F-Llr-E (C_and_CPP)