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

发布于 2024-10-29 02:21:23 字数 1352 浏览 2 评论 0原文

好吧,我觉得我已经非常接近解决这个问题了,但我对此所做的一切似乎都不起作用。 该程序必须创建 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁〃客ぐ 2024-11-05 02:21:23

刚刚在课堂上做了这个:

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

Just did this one in class:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文