The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: redskull on October 16, 2009, 12:18:03 PM

Title: Direct Operands
Post by: redskull on October 16, 2009, 12:18:03 PM
Hey everyone-

Is there anyway to get MASM to assemble a direct, numerical memory offset?  For example:

EAX, DWORD PTR [00402000h]

always assembles as the immediete:

B8 00204000 - MOV EAX, 00402000

The only way to get MASM to do it is via the indirect access.  I know it would have little real-world use, but to assemble a memory move as an immediete move, and not at least give a warning or something seems backwards.

-r
Title: Re: Direct Operands
Post by: dedndave on October 16, 2009, 12:33:37 PM
well - there are a couple ways that i have used
one is to create a label

        org     402000h
SomeDword LABEL DWORD
.
.
.
        mov     eax,SomeDword

another way is to hard-code it

        db      0B8h      ;mov eax,[aaaaaaaa]
        dd      402000h   ;address
Title: Re: Direct Operands
Post by: japheth on October 16, 2009, 01:22:38 PM

> another way is to hard-code it

>        db      0B8h      ;mov eax,[aaaaaaaa]
>        dd      402000h   ;address

Very ugly!

The correct thing is to use a segment register prefix:

    mov EAX, DWORD PTR ds:[00402000h]

Title: Re: Direct Operands
Post by: redskull on October 16, 2009, 02:22:51 PM
Quote from: japheth on October 16, 2009, 01:22:38 PM
The correct thing is to use a segment register prefix:

    mov EAX, DWORD PTR ds:[00402000h]

Bingo, much obliged.  More and more I find some of the logic behind MASM syntax completely bizarre.

thanks again

-r
Title: Re: Direct Operands
Post by: dedndave on October 16, 2009, 02:23:24 PM
ahhhhh - so THAT's the secret - lol
damnasm.exe

although "DWORD PTR" should not be required - "eax," forces that

        mov     eax,ds:[402000h]