我正在做一个项目,目前我在我的一条线路中遇到了访问冲突。我想知道我是否能就什么问题得到第二种意见。下面是我的代码(注意,我在运行时得到了错误,但它确实构建了):
.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有没有一条规定我错过了。我已经做了我的研究,但我似乎找不到适合我情况的答案。
任何帮助都会很好!(还请注意,我还没有完成它,所以可能会有其他错误。)
谢谢!
发布于 2016-11-22 11:21:59
您的问题是,无论fib指向哪个位置(它被加载到esi中),该内存页都被标记为只读。
通常,访问冲突是由于试图写入在GDT中标记为只读的内存位置而引起的。当您试图从进程根本无法访问的内存位置读取时,会发生分段错误。
正如@Jester所指出的,您没有注意到ECX中的高阶位。虽然您在CL中设置了循环控制值,但由于ECX是未知的,您的循环可能运行得远远高于您的意愿。这很快就会让你进入记忆中的只读领域。
https://stackoverflow.com/questions/40732670
复制相似问题