Intel彙編寫的斐波那契數

includelib kernel32.lib  
includelib user32.lib  
includelib Irvine32.lib 

.386

.model flat,stdcall

.stack 4096
ExitProcess PROTO, dwExitCode:DWORD 
DumpRegs PROTO

.data

first DWORD 1;初始化第一個數爲1
two	DWORD 1;初始化第二個數爲1

dest  DWORD 12 dup (0);輸出前12個斐波那契數

.code
main PROC
	 mov edx, offset dest	; edx是 dest 的偏移地址 
	  
	 mov esi, 0;				; esi 用來做 dest 的索引
	 mov ecx, 10;			  ; 循環10次,因爲前兩個已經給出來啦
	 
	 mov eax, first;			; eax 存放結果;
	 mov DWORD ptr [edx], eax;
	 
	 mov eax, two;
	 mov DWORD ptr [edx+4], eax;
	 
	 
start:
	 push ecx;
	 
	 mov ecx, DWORD ptr [edx + esi * 4];
	 
	 inc esi;
	 mov eax, DWORD ptr [edx + esi * 4];
	 
	 add eax, ecx;
	 
	 inc esi;
	 mov DWORD ptr [edx + esi * 4], eax;
	 call DumpRegs;
	 dec esi;
	 
	 pop ecx;
	 loop start;
	 
	
	 
    INVOKE ExitProcess, 0

main ENDP
END main


發佈了212 篇原創文章 · 獲贊 71 · 訪問量 22萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章