博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
汇编语言输出斐波那契数列
阅读量:4170 次
发布时间:2019-05-26

本文共 624 字,大约阅读时间需要 2 分钟。

汇编语言实现斐波那契数列(迭代法)

迭代法实现斐波那契数列(c++)

斐波那契数列的计算通常是通过递归解决的,不过如果将递归转化为迭代,可以有效提高算法效率,代码如下:

//fibonacci_iterationint fib(int n){
int f=1,g=0; while(0

注意,此时算法的复杂度为O(n) ,优于二分递归的O(2^n) .

汇编版本

这里我采用的是vs2015搭配MASM32,以及Kip Irvine的链接库,代码如下:

include Irvine32.inc.dataemp BYTE " ",0.codemain PROC    mov eax,0;g    mov ebx,1;f    mov ecx,25   ;输出前25项    L:     add eax,ebx;g+=f     mov edx,eax     sub edx,ebx     mov ebx,edx;f=g-f     call WriteDec      ;以32位无符号数的形式输出eax     mov edx,OFFSET emp     call WriteString   ;输出空格(即edx对应的字符串)     loop L    exit main ENDP END main

其中的WriteDec以及WriteString都是Irvine32库内的函数,功能如注释所示

copyright:swy

转载地址:http://bzwai.baihongyu.com/

你可能感兴趣的文章
python zip( )函数
查看>>
python 矩阵转置
查看>>
python 使用zip合并相邻的列表项
查看>>
python iter( )函数
查看>>
python callable()函数
查看>>
python 使用zip反转字典
查看>>
Python内置函数chr() unichr() ord()
查看>>
Python列表解析
查看>>
Python 如何生成矩阵
查看>>
Python 迭代器(iterator)
查看>>
Python enumerate类
查看>>
leetcode 151 Reverse Words in a String (python)
查看>>
leetcode 99 Recover Binary Search Tree (python)
查看>>
Python 生成器(generator)
查看>>
leetcode 98 Validate Binary Search Tree (python)
查看>>
python 三元条件判断的3种实现方法
查看>>
leetcode 97 Interleaving String(python)
查看>>
leetcode 92 Reverse Linked List II
查看>>
leetcode 78 Subsets
查看>>
leetcode 90 Subsets II
查看>>