码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-09-16 16:58:03      阅读:495      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!