Could you explain this statement (in Protected Mode Memory section) from asmintro.chm of masm32 to me and give some code examples :bg :"You can also get into trouble if you incorrectly dereference a variable in a register and try and read or write to that address as it will be out of the address range that your program has access to." ?
Its reasonably straight forward, make an error with a memory address and you are trying to either read or write to memory that is protected by the operating system. You may only ever read or write memory that you have allocated within your own process so if you make a mistake with something like de-referencing a memory address, the invalid address is not within the memory space that you have allocated in your process and you get a general protection fault or in buzz terms and operating system exception.
The idea is to make sure you properly observe the memory limitations imposed by what you have allocated and not go outside that address range.
I couldn't understand what you mean by this phrase "dereference a variable in a register" :( , did you mean "dereference a variable into a register" or there is some "variable in a register" ?
Could you explain this phrase to me, I know that variable and register are two different concepts?
a process can address up to 2^32Bytes = 4GB, however, only some parts of this range are used and accessable -> Virtual memory (http://en.wikipedia.org/wiki/Virtual_memory)
xor eax,eax
mov eax,DWORD ptr [eax] ; access violation: address = 0
Quote from: bolzano_1989 on October 11, 2011, 05:23:31 PM
I couldn't understand what you mean by this phrase "dereference a variable in a register" :( , did you mean "dereference a variable into a register" or there is some "variable in a register" ?
Could you explain this phrase to me, I know that variable and register are two different concepts?
In C, for example, a variable that contains an address is known as a "pointer". To access the thing that the pointer points to you "dereference" the pointer. To do this with MASM the pointer must be stored in a register. See Indirect Memory Operands (about 1/3 of the way down the page)
here (http://webster.cs.ucr.edu/Page_TechDocs/MASMDoc/ProgrammersGuide/Chap_03.htm).
I think in the CHM the "incorrectly dereference a variable in a register" phrase refers to using a variable that does not contain a pointer, as a pointer.