1. 程式人生 > >匯編實現Fibnacci

匯編實現Fibnacci

sca del 代碼段 環境 代碼 flat none CI rec

這裏使用32位的匯編環境,編譯器為VS2010


.386
.model flat,stdcall
option casemap:none

includelib msvcrt.lib
printf  PROTO C :dword, :VARARG

.data   ;數據段
    num dword 15
    szOut byte ‘FIB(%d)=%d‘,0ah,0

.code ;代碼段開始
factorial proc C n:dword
    cmp n, 2
    jbe exitrecurse
    mov ebx, n          ;EBX=n
    dec ebx
;EBX=n-1 invoke factorial, ebx ;EAX=(n-1)! cmp edx,0 je scan add ecx,eax scan: mov ebx, n sub ebx,2 invoke factorial,ebx; add ecx,eax ;EAX=EAX*n mov edx,0 ret exitrecurse: mov eax, 1 ;n=1時,n!=1 ret factorial endp start:
mov ecx,0 invoke factorial, num invoke printf, offset szOut, num, ecx ret end start; 代碼段結束

匯編實現Fibnacci