当前位置: 代码迷 >> 汇编语言 >> 编译语言的简单入门-for operating array
  详细解决方案

编译语言的简单入门-for operating array

热度:282   发布时间:2016-05-02 04:48:57.0
汇编语言的简单入门--for operating array

根据函数

F(0)=0;F(1) = 1;F(n) = F(n-2) + F(n-1);

 

TITLE Save an array and dispalyINCLUDE Irvine32.inc.dataarray DWORD 12 DUP (?)   ; define a array for saving Fibonacci numbersstep = type arrayprompt byte "The first twelve fibonacci numbers are ",0prompt1 DWORD "  ",0		.codemain PROCmov esi,OFFSET array                ;edi = address of array                    mov ecx,lengthof array              ;initialize loop conuter                                       mov edx,offset prompt               ;place the zero-ended string's offset in EDXcall writestring					;output the promptmov edx,offset prompt1				;place the zero-ended string's offset in EDXmov edi,0                           ;assign 0 to the first elementmov [esi],edimov eax,[esi]                       ;mov the first element to eax for outpingcall writeintcall writestringmov edi,1							;assign 1 to the first element              mov [esi + 4],edimov eax,[esi + 4]					;mov the second element to eax for outpingcall writeintcall writestringsub ecx,2                           ;because we have output two element in array so we just need to the remain of element . L1:			mov edi,0                       ;every time we use this register,we need to clear it.	add edi,[esi]	add esi,step                    ;point to next element				add edi,[esi]	add esi,step                    ;point to next element		mov [esi],edi	mov eax,[esi]		            ;move an integer		call writeint	call writestring	sub esi,step					;point to last element	loop L1		call waitmsgexitmain ENDPEND main


 

  相关解决方案