Exception x86:对数组的地址使用偏移运算符时发生访问写入冲突

Exception x86:对数组的地址使用偏移运算符时发生访问写入冲突,exception,assembly,x86,Exception,Assembly,X86,我在Project2.exe中的0x0044369D处引发异常:0xC0000005:访问冲突写入位置0x00000099。根据我目前的研究,我的印象是,这与从行mov[eax],ecx 我在moveax,offset arrayfib中使用了offset操作符,我认为应该可以解决这个问题。我似乎不知道是什么导致了这个问题 .model flat, stdcall .stack 4096 INCLUDE Irvine32.inc ExitProcess PROTO, dwExitCode: D

我在Project2.exe中的0x0044369D处引发异常:0xC0000005:访问冲突写入位置0x00000099。根据我目前的研究,我的印象是,这与从行
mov[eax],ecx

我在
moveax,offset arrayfib
中使用了offset操作符,我认为应该可以解决这个问题。我似乎不知道是什么导致了这个问题

.model flat, stdcall 
.stack 4096
INCLUDE Irvine32.inc
ExitProcess PROTO, dwExitCode: DWORD

.data
arrayfib DWORD 35 DUP (99h)


.code 
main PROC   
    mov eax, OFFSET arrayfib    ;address of fibonacci number array 
    mov bx, 30                  ;number of Fibonacci numbers to generate
    call fibSequence            ;call to Fibonacci sequence procedure 
    mov edx, OFFSET arrayfib    ;passes information to call DumpMem
    mov ecx, LENGTHOF arrayfib
    mov ebx, TYPE arrayfib 
    call DumpMem

    INVOKE ExitProcess, 0 
main ENDP
;----------------------------------------------------------------------------------
;fibSequence
;Calculates the fibonacci numbers to the n'th fibonacci number 
;Receives: eax = address of the Fibonacci number array
;bx = number of Fibonacci numbers to generate
;ecx = used for Fibonacci calculation (i-2)
;edx = used for Fibonacci calculation (i-1)
;returns: [eax+4i] = each value of fibonacci sequence in array, scaled for doubleword
;---------------------------------------------------------------------------------

fibSequence PROC                    
    mov ecx, 0                  ;initialize the registers with Fib(0) and Fib(1)
    mov edx, 1      
    mov [eax], edx              ;store first Fibonacci number in the array 
                                ;since a Fibonacci number has been generated, decrement the counter
                                ;test for completion, proceed
    mov eax, [eax+4]

fibLoop: 
    sub bx, 1
    jz quit                     ;if bx = 0, jump to exit
    add ecx, edx
    push ecx                    ;save fib# for next iteration before it is destroyed
    mov [eax], ecx              ;stores new fibonacci number in the next address of array 
    push edx                    ;save other fib# before it is destroyed
    mov ecx, edx
    mov edx, [eax]
    mov eax, [eax+4]            ;increments accounting for doubleword 
    pop edx
    pop ecx 
quit: 
    exit
fibSequence ENDP
END main


此外,如果有任何其他建议,我将很高兴听到他们。我对这一切都是新手,希望尽可能多地学习

您的问题是
mov-eax,[eax+4]
。这是来自记忆的负荷。您可能希望
添加eax,而不是4
。PS:学习使用调试器。或者你可以使用
leaeax,[eax+4]
,这与
addeax,4
@Jester相同。我知道如何使用调试器,但我相信VS2019中有一个bug,它说“每次我尝试使用调试器时都会进行无法编译的编辑…”。这是另一个问题。它在每次遇到断点时都会这样做:/n但是,它起作用了。感谢您捕获我的愚蠢错误调试错误听起来像您正在编辑,而您仍在调试(编辑并继续)。您需要停止调试,然后重新编译。您的问题是
mov-eax[eax+4]
。这是来自记忆的负荷。您可能希望
添加eax,而不是4
。PS:学习使用调试器。或者你可以使用
leaeax,[eax+4]
,这与
addeax,4
@Jester相同。我知道如何使用调试器,但我相信VS2019中有一个bug,它说“每次我尝试使用调试器时都会进行无法编译的编辑…”。这是另一个问题。它在每次遇到断点时都会这样做:/n但是,它起作用了。感谢您捕获我的愚蠢错误调试错误听起来像您正在编辑,而您仍在调试(编辑并继续)。您需要停止调试,然后重新编译。