简体   繁体   English

访问违规MASM x86程序集

[英]Access Violation MASM x86 Assembly

I am working on a project and I am currently getting an Access Violation in one of my lines. 我正在开展一个项目,目前我正在接收一个访问冲突。 I was wondering if I could get a second opinion on what is wrong. 我想知道我是否能对错误得到第二意见。 Here is my code (Note, I get the error during runtime, but it does build): 这是我的代码(注意,我在运行时得到错误,但它确实构建):

.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

Is there a rule that I am missing. 是否有我失踪的规则。 I have done my research but I cannot seem to find the answer that fits my situation. 我做了我的研究,但我似乎无法找到适合我情况的答案。

Any help would be great! 任何帮助都会很棒! (Also note that I am not done with it so there might be other mistakes.) (另请注意,我没有完成它,所以可能会有其他错误。)

Thanks! 谢谢!

Your problem is that, wherever fib points to, which is loaded into esi , that memory page is marked as read-only. 你的问题是,无论fib指向何处,加载到esi ,内存页面都标记为只读。

Generally, an access violation is caused by attempting to write to a memory location that is marked read-only in the GDT. 通常,尝试写入GDT中标记为只读的内存位置会导致访问冲突。 A segmentation fault occurs when you attempt to read from a memory location that your process does not have access to at all. 当您尝试从内存位置读取您的进程根本无权访问时,会发生分段错误。

As @Jester points out, you're not paying attention to the high order bits in ECX . 正如@Jester指出的那样,你并没有关注ECX高阶位。 While you set your loop control value in CL , your loop may run far higher than you intend since ECX is unknown. 当您在CL设置循环控制值时,由于ECX未知,您的循环可能会比您想要的更高。 This would quickly put you into read-only territory in your memory. 这会很快让你进入你记忆中的只读区域。

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

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