生成斐波那契数列的数字并将其写入文件
好吧,我觉得我已经非常接近解决这个问题了,但我对此所做的一切似乎都不起作用。 该程序必须创建 47 个斐波那契数列,然后将它们存储在 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
我看到的问题是它没有返回任何内容,而且我无法找出我需要它返回的内容。我尝试过返回各种寄存器,但所有寄存器都出现错误。
Alright, I feel like I'm very close to solving this but nothing I do to this seems to work.
This program has to create 47 numbers of the fibonacci sequence then store them in an array of DWORDS then write that to a file (fib.bin). The formatting got kind of screwed up but if you need any clarification I will try to help.
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
I the problem I see is that it's not returning anything and I cannot find out what I need it to return. I've tried it returning various registers but all of them come out with an error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚在课堂上做了这个:
Just did this one in class: