2011-04-01 86 views
-1

好吧,我覺得我非常接近解決這個問題,但是我對此做的任何事情似乎都無法解決。 該程序必須創建47個斐波那契數列,然後將它們存儲在DWORDS數組中,然後將其寫入文件(fib.bin)。格式化有些搞砸了,但如果你需要澄清,我會盡力幫忙。生成Fibonacci序列的數字,並將它們寫入文件

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 

我看到的問題是它沒有返回任何東西,我也找不到我需要返回的東西。我試過它返回各種寄存器,但他們都出來了一個錯誤。

回答

0

只是做這一個類:

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 
+0

它輸出二進制文件,但它也將打印到控制檯。 – David 2011-04-01 02:53:13

相關問題