我正在使用 M68000 芯片,所以伪代码很好。我可以很容易地编写这个程序,但是我在实现对这个算法使用堆栈(推送、调用、弹出)时遇到了麻烦,我在这里待了几个小时,仍然找不到方法。请有人提供斐波那契的详细伪代码。
问问题
2364 次
1 回答
0
这是 C 中的一个实现。应该可以直接转换为 ASM。
#include<stdio.h>
int main()
{
int n, first = 0, second = 1, next, c;
printf("Enter the number of terms\n");
scanf("%d",&n);
printf("First %d terms of Fibonacci series are :-\n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d\n",next);
}
return 0;
}
有足够的M68000
寄存器来执行此操作,push
但如果您必须将此指令用于家庭作业,那么您可以在else
交换变量的子句中使用它,从而限制您使用最少的寄存器。循环也可以这样说。
于 2013-12-10T11:07:00.980 回答