作者yad50968 (boringday)
看板Grad-ProbAsk
標題[理工] [計組]算盤第五版CH2
時間Mon Jul 27 07:06:12 2015
2.32 [5] <§2.8> Functions can often be implemented by compilers “in-line.”
An in-line function is when the body of the function is copied into the program space,
allowing the overhead of the function call to be eliminated.
Implement an “in-line” version of the the C code in the table in MIPS assembly.
What is the reduction in the total number of MIPS assembly instructions needed to complete the function?
Assume that the C variable n is initialized to 5.
function :
int fib(int n) {
if (n==0)
return 0;
else if (n==1)
return 1;
else
return fib(n-1) + fib(n-2);
}
大多回答是說
遞迴不適合用inline
原因在於程式碼可能過大
但這題n只等於5
假如真的要放inline沒辦法得到答案嗎
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.209.88
※ 文章網址: https://www.ptt.cc/bbs/Grad-ProbAsk/M.1437951974.A.C2B.html
推 amge1524: inline是指非遞迴版本嗎? 07/28 00:19
→ amge1524: 如果是的話不會過大吧 多幾行而已 可以寫的出來 07/28 00:20
→ yad50968: 題目應該是說把遞迴inline進去 07/28 18:49