News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

MASM confusing ...

Started by James Ladd, May 05, 2005, 10:48:23 PM

Previous topic - Next topic

James Ladd

I have seen code like this

    mov [variable], eax


and like this


    mov variable, eax


with variable defined as DWORD 0

Im confused because there appears to be no difference but I thought [] was used to say contents of the thing pointed to by the address in variable ?
Is this correct ?

Also, how so I tell MASM the size of the value im trying to address.
I have code like this

    mov [eax].variable, othervariable


And I  get  error A2070: invalid instruction operands
I thinking this is because im not telling the compiler the size of "variable" ?

thanks

QvasiModo

Quote from: striker on May 05, 2005, 10:48:23 PM
I have seen code like this

    mov [variable], eax


and like this


    mov variable, eax


with variable defined as DWORD 0

Im confused because there appears to be no difference but I thought [] was used to say contents of the thing pointed to by the address in variable ?
Is this correct ?

You are right. But MASM has a special syntax that allows you to reference variables without using the brackets... maybe MS engineers thought it'd be more intuitive, but it causes most newbies to get confused. :snooty:

Quote
Also, how so I tell MASM the size of the value im trying to address.
I have code like this

    mov [eax].variable, othervariable


And I  get  error A2070: invalid instruction operands
I thinking this is because im not telling the compiler the size of "variable" ?

No, it's because there is no assembly instruction that lets you move from memory to memory. The following is illegal:


mov [mem1], [mem2]


So you have to use a spare register, or the stack:


; for example...

mov eax, [mem1]
mov [mem2], eax

; ...or...

push [mem1]
pop [mem2]


Hope that helps! :U

Nilrem

Look for the m2m macro in macros.asm. 8-)

James Ladd

Thanks.
I worked out my issues but I still find the multiple ways to do the same thing rather confusing.
Thanks again.

hutch--

James,

MASM has used named stack variables for a very long time and it is a syntax mistake that MASM tolerates when someone encloses the name with square brackets. Some people get problems with it because they are trying to apply the notation of other assemblers but as normal, you use the syntax of the tool you are working in. NASM for example requires the square brackets.

Square brackets in MASM are generally dereference notation and its lucky that MASM simply ignores the extra bracketing rather than treating it as a pointer to the variable. The error looks like this.


LOCAL var  :DWORD

will be something like [ebp-16]

Writing code like mov [var], edx

is writing

mov [[ebp-16]], edx


Fortunately MASM just ignores it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

James Ladd

I appreciate what you are saying.
I do have a part of me that is annoyed by the "help" Masm is trying to give.
I think it sometimes obfiscates the real assembler that people (like me) should probably know before
using all the extra stuff.

anyways - thanks.

hutch--

James,

When you have a local,


LOCAL var  :DWORD


Write code like,


mov var, edx


It is directly written as,


mov [ebp-16], edx


It is the same mechanism as using name parameters in a procedure. When you remove a stack frame, you replace the names with the corrected stack address. The use of square brackets is not lower level, its just different notation and usually from assemblers that don't store the local name in the same way as MASM.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

pbrennick

Hutch,
Even though I have no trouble programming with the masm assembler.  The following syntax is much more understandable to me

mov  [eax], Variable

would mean to me to store the value in the current address eax represents.

mov eax, variable

would mean change the value eax represents to the value in variable.

NOTE:  Since eax is specified as the destination then it sets the size that variable must conform to, if we want to use another size for variable, then we must say so and also derefernce it such as byte ptr [eax] to allow the assembler to use a byte declared value in variable

If that is what you are trying to say then it is much more understandable the way I am stating it.

Paul