【发布时间】:2014-04-11 17:50:52
【问题描述】:
我需要这个程序来写出一个包含斐波那契数列前 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
【问题讨论】:
-
“我的 fib.bin 文件只有一个条目,它不是数组的开头” 只是为了确保:您正在十六进制编辑器中查看文件,对吗?
标签: assembly masm fibonacci irvine32