读书人

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

发布时间: 2013-10-03 17:28:15 作者: rapoo

汇编语言的简单入门--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 elementadd edi,[esi]add esi,step                    ;point to next elementmov [esi],edimov eax,[esi]            ;move an integercall writeintcall writestringsub esi,step;point to last elementloop L1call waitmsgexitmain ENDPEND main


读书人网 >汇编语言

热点推荐