Assembly 从阵列打印到文件的程序集

Assembly 从阵列打印到文件的程序集,assembly,masm,fibonacci,irvine32,Assembly,Masm,Fibonacci,Irvine32,我需要这个程序写出一个文件,其中计算出斐波那契级数的前47个值。“我的过程”使用提供的库中包含的过程正确显示47个条目,但不会将它们打印到文件中 我相当确定它将数组存储在esi中,但我的fib.bin文件只有一个条目,而不是数组的开头。我很确定我需要做的就是使用esi,但我想不出来,提前谢谢 TITLE Fibonacci Numbers (FibNums.asm) INCLUDE Irvine32.inc .data fileHandle DWORD

我需要这个程序写出一个文件,其中计算出斐波那契级数的前47个值。“我的过程”使用提供的库中包含的过程正确显示47个条目,但不会将它们打印到文件中

我相当确定它将数组存储在esi中,但我的fib.bin文件只有一个条目,而不是数组的开头。我很确定我需要做的就是使用esi,但我想不出来,提前谢谢

TITLE Fibonacci Numbers                     (FibNums.asm)

INCLUDE Irvine32.inc

.data
fileHandle DWORD ?
filename BYTE "fib.bin",0

FIB_COUNT = 47
array DWORD FIB_COUNT DUP(?)

.code
main PROC

    ;Creates the file
    mov  edx,OFFSET filename
    call CreateOutputFile
    mov  fileHandle,eax

    ;Generates the array of values
    mov esi,OFFSET array
    mov ecx,FIB_COUNT
    call generate_fibonacci

    ;Write out to file
    mov eax,fileHandle
    mov edx,OFFSET array
    mov ecx,SIZEOF array
    call WriteToFile

    ;Close the file
    mov eax,fileHandle
    call CloseFile


    exit
main ENDP

;--------------------------------------------------
generate_fibonacci PROC USES eax ebx ecx
;
;Generates fibonacci values and stores in an array
;Receives: ESI points to the array, ECX = count
;Returns: Nothing
;---------------------------------------------------

    mov eax,1
    mov ebx,0

L1: add eax,ebx
    call    WriteDec
    call Crlf

    mov [esi],eax
    xchg    eax,ebx
    loop L1
    ret
generate_fibonacci ENDP

END main

您必须增加esi:

...
L1: add eax,ebx
    call WriteDec
    call Crlf

    mov [esi], eax
    xchg eax, ebx
    add esi, 4          ; move forward 4 Bytes (4*8 bits) = 1 dword (1*32 bits)
    loop L1
...

有趣的解决方案是,只需将类型数组添加到esi,就可以移动它在寄存器中输出答案的位置。现在正在100%工作。

“我的fib.bin文件只有一个条目,而不是数组的开头”只是为了确保:您正在使用十六进制编辑器查看该文件,对吗?哎呀,我在查看了我以前的一个数组程序后发现了它,谢谢您……忘记了这一点感觉有点傻。
L1: add eax,ebx
    call    WriteDec
    call Crlf

    mov [esi],eax
    xchg    eax,ebx
    ***add  esi,TYPE array***
    loop L1