0

我正在使用 M68000 芯片,所以伪代码很好。我可以很容易地编写这个程序,但是我在实现对这个算法使用堆栈(推送、调用、弹出)时遇到了麻烦,我在这里待了几个小时,仍然找不到方法。请有人提供斐波那契的详细伪代码。

4

1 回答 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 回答