The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: nixeagle on May 09, 2012, 12:42:32 AM

Title: MASM trying to be too smart, takes name to mean [name]
Post by: nixeagle on May 09, 2012, 12:42:32 AM
Alright, I've poked at this for a good 20 minutes in between watching the ballgame. What I have is something that looks like this:


.data
    g_test_baseline dd ?
.code
    mov eax, g_test_baseline


The problem here is MASM is taking my instruction to move the address of g_test_baseline to mean this:

    mov eax, [g_test_baseline]


Which is not what I want ::). How do we tell masm to quit trying to be smart :bg.
Title: Re: MASM trying to be too smart, takes name to mean [name]
Post by: dedndave on May 09, 2012, 01:16:47 AM
normal masm syntax does not use brackets to access the data at a label
if you want the address...
        mov     eax,offset g_test_baseline

now, GoAsm works like you were expecting masm to   :P
Title: Re: MASM trying to be too smart, takes name to mean [name]
Post by: nixeagle on May 09, 2012, 01:19:14 AM
Quote from: dedndave on May 09, 2012, 01:16:47 AM
normal masm syntax does not use brackets to access the data at a label
if you want the address...
        mov     eax,offset g_test_baseline

now, GoAsm works like you were expecting masm to   :P

Yey! As does NASM. Thanks :clap:.
Title: Re: MASM trying to be too smart, takes name to mean [name]
Post by: hutch-- on May 09, 2012, 02:40:31 AM
I think from memory that you can also use,


lea eax, your_label
Title: Re: MASM trying to be too smart, takes name to mean [name]
Post by: nixeagle on May 09, 2012, 02:54:39 AM
Quote from: hutch-- on May 09, 2012, 02:40:31 AM
I think from memory that you can also use,


lea eax, your_label

:8). It let me do that! Thanks :U
Title: Re: MASM trying to be too smart, takes name to mean [name]
Post by: dedndave on May 09, 2012, 04:14:29 AM
you certainly want to use LEA for local variables
i think, for globals, MOV ,offset works a little better
Title: Re: MASM trying to be too smart, takes name to mean [name]
Post by: raymond on May 10, 2012, 04:57:15 PM
When I want the address of a variable, I tend to always use LEA regardless of whether it is local or global. My reasoning is that I never have to double-check if it is one or the other. Using OFFSET would not work for local variables, but LEA works for both.
Title: Re: MASM trying to be too smart, takes name to mean [name]
Post by: dedndave on May 10, 2012, 06:49:28 PM
the assembler will tell you if offset does not work   :bg
Title: Re: MASM trying to be too smart, takes name to mean [name]
Post by: nixeagle on May 10, 2012, 07:36:14 PM
Quote from: dedndave on May 10, 2012, 06:49:28 PM
the assembler will tell you if offset does not work   :bg

I have went to doing it raymond's way since MASM tries to be too smart about memory addressing. I wish there was a way to tell it to treat []'s as correctly indicating programmer intent.
Title: Re: MASM trying to be too smart, takes name to mean [name]
Post by: hutch-- on May 11, 2012, 01:28:21 AM
nix,

MASM only ever requires [] around registers to indicated that the register is a memory operand [esi] etc .... It will generally ignore [] around named variables so that [myvar] and myvar are the same. It is a notation difference between MASM and other assemblers like NASM that use the [] brackets to indicate that the contents are an address. With MASM you have either named memory operands (local or .data or .data?) or a register enclosed in [] brackets to indicate that it is a memory operand.