Ok, am I being really stupid here or am I just too tired? I am trying to access some memory located in a pointer. All I want to do is set the first address based at this pointer to 0 and the next to 1. Here's what I have:

mov ,0
mov ,1

But this just adds one and two to the value address of lpPrimeArray and so references a completely different part of memory. The only way I could do it was like this:

mov ecx,lpPrimeArray
mov BYTE PTR ,0
mov BYTE PTR ,1

But I have a feeling there is a better way. Is there anywhere I can read up on all the addressing modes of masm32?
Posted on 2004-12-09 19:21:36 by DeX

Should work the way you did it, at least it works in GoAsm that way. For example...

TestVar1 dd 0

TestVar2 dd 0

mov [TestVar1+4], 100

TestVar2 is equal to 100
Posted on 2004-12-09 21:18:33 by donkey
There is no better way.

A pointer stored in memory cannot be used as part of an address "calculation". Processor limitation.

You can load pointers into registers and adjust them to "walk" through memory, as is typically done with characters in strings.

mov edx,lpArray  ; load pointer

mov eax,[ecx] ; load dword into EAX
add edx,4 ; adjust pointer to point to next dword
mov [edx],ebx ; store EBX in 2nd dword

There is a brief description of addressing modes at http://www.win32asmcommunity.net/phpwiki?AddressingModes
Posted on 2004-12-09 22:00:03 by tenkey
A pointer stored in memory cannot be used as part of an address "calculation". Processor limitation.

I thought he was talking about a label, I misread his post... sorry
Posted on 2004-12-09 22:06:29 by donkey
for the record, lea should be used to load the pointer address, and _not_ masm32's 'mov', which boils down to mov offset, and offset is just a static macro that calculates the offset.
Posted on 2004-12-09 23:49:15 by Drocon
Maybe i am reading things the wrong way. I thought mov was a assember standard Intel type instrution that took only one clock per, while lea takes many more clocks to get the job done while leaving much scrible scrabble in mem. It take more than one clock to make a macro tick i thought.

*A bucking macro* WHAT ! ! !

If what you say is true i now wonder is that the only way (LEA) which i think would be a FAT type macro? The things you learn here is really amasing... Im not saying you are wrong. Im just in a state of shock by the way you put it... right or wrong Thanks, thats whats this joint is all about.

PS: While i am writing this the cursor v line in the edit box is flashing like crazy. Blink blink blink ... stop ... Blink blink blink ... is that phpbb ... i know for sure its not my installed Windows...
Posted on 2004-12-10 11:21:16 by cmax
About my PS:

Maybe this place is still under attact. I will change my pass word next round FOR SURE as Hiroshimator ask us to.
Posted on 2004-12-10 11:32:29 by cmax
Well, now the whole addressing issue is getting confused.

"Loading a register" means putting a value in a register. You have potentially three sources for that value: registers, memory, and the instruction itself. And if the OS allows it, you can also get values from an input port.

With MOV and a memory address (plain label or some addressing mode), the value source is memory. The instruction specifies where in memory to get the value.

With MOV and the "OFFSET label", or an LEA instruction, the value source is the instruction itself. That means the instruction provides the value without any memory accesses (after the instruction has been fetched.)

The value may be application data, or it may be an address (same as pointer.)

And because addresses can be values, they can be stored in memory or registers, and processed as if they were ordinary data.

You need to make a distinction between the address as just a value, and its use to get other values.
Posted on 2004-12-10 17:22:04 by tenkey
There has indeed been some unusual comments in this thread about what is a normal mode of memory address. tenkey is absolutely right about what you can and cannot put in a register and the 2nd example is the correct one.

mov ecx,lpPrimeArray
mov BYTE PTR [ecx+1],0
mov BYTE PTR [ecx+2],1

With MASM when you use the keyword OFFSET, you are talking about a location in the actualy physical EXE file that is an OFFSET, (literally calculated from another address point).

The mnemonic,

mov reg, OFFSET variable

is actually

mov reg, immediate

and the assembler puts the actual immediate value of the OFFSET within the opcode. The great advantage of this technique is that the address is calculated at assembly time and the result is a normal mnemonic, not a macro.

You use LEA (load effective address) for tasks like getting the address of a LOCAL variable and loading it into a register as this value CANNOT be known at assembly time.

The basic distinction that needs to be understood is between an ADDRESS and what VALUE is AT that ADDRESS. The difference is WHERE the information is to WHAT the information is.

If you said "Fred is at 32 Elm Street" you have supplied the ADDRESS and where Fred is and this is the same logic as an ADDRESS in memory. Where it is versus WHAT is at that address.

Just to add to the range of what can be done in the normal addressing modes, you can in fact use an IMMEDIATE value as the BASE ADDRESS and it is very useful for coding algos using a table as it saves you using a register to do it.


hutch at movsd dot com
Posted on 2004-12-11 02:44:23 by hutch--