[理工] [計組]算盤第五版CH2

作者: yad50968 (woow)   2015-07-27 07:06:12
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沒辦法得到答案嗎
謝謝
作者: amge1524 (台灣加油)   2015-07-28 00:19:00
inline是指非遞迴版本嗎?如果是的話不會過大吧 多幾行而已 可以寫的出來
作者: yad50968 (woow)   2015-07-28 18:49:00
題目應該是說把遞迴inline進去

Links booklink

Contact Us: admin [ a t ] ucptt.com