Assembly 为斐波那契序列生成数字并将其写入文件

Assembly 为斐波那契序列生成数字并将其写入文件,assembly,masm,fibonacci,irvine32,Assembly,Masm,Fibonacci,Irvine32,好吧,我觉得我很快就要解决这个问题了,但我对此所做的一切似乎都不管用。 这个程序必须创建47个fibonacci序列,然后将它们存储在DWORD数组中,然后将其写入文件(fib.bin)。格式有点混乱,但如果你需要任何澄清,我会尽力帮助你 INCLUDE Irvine32.inc .data fileHandle DWORD ? filename BYTE "fib.bin", 0 FIB_COUNT = 47 array DWORD FIB_COUNT DUP(?) .code main

好吧,我觉得我很快就要解决这个问题了,但我对此所做的一切似乎都不管用。 这个程序必须创建47个fibonacci序列,然后将它们存储在DWORD数组中,然后将其写入文件(fib.bin)。格式有点混乱,但如果你需要任何澄清,我会尽力帮助你

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

FIB_COUNT = 47
array DWORD FIB_COUNT DUP(?)

.code
main PROC

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


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


    ; Write the array to a 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 ebp, 0
    mov edx, 1

    mov ebx, edx
    mov ecx, 47             
L1:                         
     mov eax, edx           
     mov ebp, eax           
     mov edx, ebx           
     add ebx, ebp           


;    dec ecx
loop L1
     ret 
generate_fibonacci ENDP

END main

我看到的问题是,它没有返回任何东西,我无法找到我需要它返回的东西。我试过返回不同的寄存器,但都出现了错误

刚刚在课堂上做了这个:

INCLUDE Irvine32.inc
.data
fileHandle DWORD ?
fileName BYTE "myFile.bin", 0
arrSize = 47
myArray DWORD arrSize DUP(?)

.code
main PROC
    call Clrscr

    ;Create the file
    mov edx, OFFSET fileName
    call CreateOutputFile
    mov fileHandle, eax

    ;Call array process
    mov esi, OFFSET myArray
    mov ecx, arrSize
    call GetFib

    ;Write array
    mov eax, fileHandle
    mov edx, OFFSET myArray
    mov ecx, SIZEOF myArray
    call WriteToFile

    ;close
    mov eax, fileHandle
    call CloseFile

    exit
main ENDP

GetFib PROC USES eax ebx ecx
;--------------------------------
;Generates fibonnaci sequence and stores in array
;Recieves: ESI points to the array, ECX is the number of values
;Returns: Nothing
;--------------------------------

    ;Set starting values
    mov eax, 1
    mov ebx, 0
L1:
    ;Add the second number to the first
    add eax, ebx
    call WriteDec
    call CrlF

    ;Move value to array, increment esi, exchange values
    mov [esi], eax
    add esi, TYPE myArray
    xchg eax, ebx
loop L1

ret
GetFib ENDP
END main

它输出到二进制文件,但也会打印到控制台。