Re: [問題] 關於 gcc 的 inline asm
※ 引述《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
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
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):