首页 > Windows开发 > 详细

win32 实现阶乘 和 斐波那契数列

时间:2016-09-16 16:56:48      阅读:549      评论:0      收藏:0      [点我收藏+]

阶乘:

.486

.model flat, stdcall

include \masm32\include\msvcrt.inc

includelib \masm32\lib\msvcrt.lib

.data    

i dd 2    

f dd 1    

n dd ?    

input db ‘please input a number‘,0    

output db ‘the result is ‘,0    

dataa db ‘%d‘,0

.code

start:    

invoke crt_printf,addr input    

invoke crt_scanf,addr dataa,addr n    

mov eax,f    

mov ebx,i    

mov ecx,n        

cmp ebx,ecx    

jle again    

again:     

        mul ebx

        inc ebx

       cmp ebx,ecx

       jle again

 mov n,eax        

 invoke crt_printf,addr output    

 invoke crt_printf,addr dataa,n    

ret

end start

 

 

 

 

 

 

斐波那契数列:

.486

.model flat,stdcall

include \masm32\include\msvcrt.inc

includelib \masm32\lib\msvcrt.lib

.data

    a dd 0  

    b dd 1

    i dd 1

    t dd ?

    n dd ?

    vac db ‘ ‘,0

    input db ‘please input the number of the sequence:‘,0

    output db ‘the Fibonacci sequence is: ‘,0

    data1 db ‘%d‘,0

.code

start:

    invoke crt_printf,addr input

    invoke crt_scanf,addr data1,addr n

    invoke crt_printf,addr output

    invoke crt_printf,addr data1,a

    invoke crt_printf,addr vac

    invoke crt_printf,addr data1,b

    invoke crt_printf,addr vac

    mov ecx,i

    cmp ecx,n

    jl again

again:

    mov ebx,b

    mov t,ebx

    mov eax,a

    add ebx,eax

    mov b,ebx

    invoke crt_printf,addr data1,b

    invoke crt_printf,addr vac

    mov eax,t     mov a,eax

    inc i

    mov ecx,i

    cmp ecx,n

    jl again

  ret

  end start

 

win32 实现阶乘 和 斐波那契数列

原文:http://www.cnblogs.com/yzychang/p/5876642.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!