asmintro.chm, incorrectly dereference a variable in a register + read or write

Started by bolzano_1989, October 11, 2011, 04:44:20 PM

Previous topic - Next topic

bolzano_1989

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." ?

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

bolzano_1989

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?

qWord

a process can address up to 2^32Bytes = 4GB, however, only some parts of this range are used and accessable -> Virtual memory
xor eax,eax
mov eax,DWORD ptr [eax] ; access violation: address = 0
FPU in a trice: SmplMath
It's that simple!

MichaelW

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.

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.


eschew obfuscation