2017-10-21 83 views
0

我用vs 2015寫了x64 masm程序。錯誤「訪問違規讀取位置」

ExitProcess PROTO 
MessageBoxA PROTO 
.data 
    text db "Winter hat", 0Ah, "Upon my head - ", 0Ah, "My head stays warm,", 0Ah, "But my nose is red!;", 0 
    header db "Task1", 0 

.code 

main proc 

xor rcx, rcx 
mov r9b, 0 
lea rdx, text 
lea r8, header 

call MessageBoxA 

call ExitProcess 

main endp 

end 

不時我得到一個錯誤:

Exception thrown at 0x00007FF9C65261BE (gdi32.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

If there is a handler for this exception, the program may be safely continued.

你能否澄清哪裏可以在我的代碼錯誤?

回答

0

當您調用不帶參數的過程時可能發生此錯誤, 最好使用INVOKE而不是CALL調用它們以獲取正確的錯誤消息。 此外我認爲MessageBoxA需要在棧參數沒有在寄存器中,所以你可以把PARAMS這樣的:

.data 
text db "your message box text", 0 
header db "message box caption",0 

.code 
start: 
push MB_OK 
push addr header 
push addr text 
push 0 
call MessageBox 

OR

invoke MessageBox, 0, addr text, addr header, MB_OK 
相關問題