JoeYang
JoeYang

Reputation: 9

When writing MASM code, using 'mov memory, register' can result in a memory access violation

First of all, I apologize if my English is not very good, and if there are any parts of my description that are unclear.

I am currently learning how to write MASM and referring to Irvine's textbook. I have written a program that takes an integer input and prints out an integer. However, I'm not sure why the instruction mov var1, eax is causing an error with the message "Exception thrown: 0xC0000005: Access violation - writing to address.".

I don't understand why this error is occurring because the textbook states that "mov mem, reg" should be valid. I would appreciate it if someone could help me with this issue. Thank you.

Here is the code:

INCLUDE Irvine32.inc

INCLUDELIB Irvine32.lib

.data

str1 BYTE "enter a number:",0

.code

main PROC
call Clrscr
var1 DWORD ?     ;Declare the variable var1 as DWORD type.

mov edx,OFFSET str1

call WriteString ;Output string.

call ReadInt     ;Read an integer.



mov var1,eax     ;erroe,Exception thrown: 0xC0000005
call WriteInt    ;Display an integer.

exit

main ENDP

END main

I have tried changing the line var1 DWORD ? to var1 DWORD 0 in an attempt to address the issue, but it didn't resolve the problem. The issue still persists.

Upvotes: 0

Views: 18

Answers (0)

Related Questions