[理工] [计组]算盘第五版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