MASM trying to be too smart, takes name to mean [name]

Started by nixeagle, May 09, 2012, 12:42:32 AM

Previous topic - Next topic

nixeagle

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.

dedndave

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

nixeagle

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:.

hutch--

I think from memory that you can also use,


lea eax, your_label
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

nixeagle

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

dedndave

you certainly want to use LEA for local variables
i think, for globals, MOV ,offset works a little better

raymond

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.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

dedndave

the assembler will tell you if offset does not work   :bg

nixeagle

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.

hutch--

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