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

阶乘:

.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

 

转载于:https://www.cnblogs.com/yzychang/p/5876642.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值