繁体   English   中英

访问违规MASM x86程序集

[英]Access Violation MASM x86 Assembly

我正在开展一个项目,目前我正在接收一个访问冲突。 我想知道我是否能对错误得到第二意见。 这是我的代码(注意,我在运行时得到错误,但它确实构建):

.data
BlueTextOnGray = blue + (lightGray * 16)
DefaultColor = lightGray + (black * 16)
arrayD SDWORD 12345678h,1A4B2000h,3434h,7AB9h

fib BYTE 1,2
  BYTE NUMBER_FIBS_TO_COMPUTE dup(0)

prompt  BYTE    "Enter an ending integer: ",0
error   BYTE    "Invalid stopping point! 



.code

main PROC

    mov eax,BlueTextOnGray
    call    SetTextColor
    call    Clrscr          ; Clear the screen
    call    Crlf            ; New line

    mov edx,OFFSET prompt
    call    WriteString
    call    ReadInt         ; Input integer into EAX
    call    Crlf            ; New line

  lea esi, [fib+2]
  mov cl, NUMBER_FIBS_TO_COMPUTE
@@:
  mov al, [esi-2]
  add al, [esi-1]
  mov [esi], al   ;<------------This is where the error occurs
  inc esi
  loop @B

; here print out the results or examine them with debugger

E1: call    Crlf            ; New line
    call    WaitMsg         ; "Press any key..."
    mov eax,DefaultColor
    call    SetTextColor
    call    Clrscr



exit
main ENDP
END main

是否有我失踪的规则。 我做了我的研究,但我似乎无法找到适合我情况的答案。

任何帮助都会很棒! (另请注意,我没有完成它,所以可能会有其他错误。)

谢谢!

你的问题是,无论fib指向何处,加载到esi ,内存页面都标记为只读。

通常,尝试写入GDT中标记为只读的内存位置会导致访问冲突。 当您尝试从内存位置读取您的进程根本无权访问时,会发生分段错误。

正如@Jester指出的那样,你并没有关注ECX高阶位。 当您在CL设置循环控制值时,由于ECX未知,您的循环可能会比您想要的更高。 这会很快让你进入你记忆中的只读区域。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM