News:

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

A MOV question

Started by bolzano_1989, October 06, 2011, 04:50:35 AM

Previous topic - Next topic

bolzano_1989

In the following tutorial:
http://www.friedspace.com/assembly/moving.php
, could you tell me the differences and the effects of the differences between the following statements?
MOV [myvar1],CH
MOV myvar1,CH

NoCforMe

Um, one has square brackets and the other one doesn't?

Really, that's the answer. There's no functional difference between the two statements.

The brackets come in handy when you need to index variables or do other fancy stuff:



MOV AX, [BX + Table + 10]


bolzano_1989

I think they're not the same.

Rockphorr

Quote from: bolzano_1989 on October 06, 2011, 04:50:35 AM
In the following tutorial:
http://www.friedspace.com/assembly/moving.php
, could you tell me the differences and the effects of the differences between the following statements?
MOV [myvar1],CH
MOV myvar1,CH


in masm it is the same

but
mov DX,2
and
mov DX,[2]
is diferent - couse first source data is  imm, and second source data is mem.
Strike while the iron is hot - Бей утюгом, пока он горячий

Rockphorr

in mov instruction the target always is address or register name
but source also may be immediate (imm) opperand.
by default masm compiler assumes that is imm if it is digit, when it is register that is awesome.

feel diference betveen masm and fasm


masm                                                                                      fasm
memory_label                                                                           [memory_label]
[memory_label]  <-bracets is not req here                                    [memory_label]
offset(memory_label)                                                                 memory_label
Strike while the iron is hot - Бей утюгом, пока он горячий

NoCforMe

Quote from: bolzano_1989 on October 06, 2011, 05:59:18 AM
I think they're not the same.

They are.

From the MASM Programmer's Guide (Microsoft):

QuoteThe index operator can contain any direct memory operand. The following statements are equivalent:



mov ax, var
mov ax, [var]



Some programmers prefer to enclose the operand in brackets to show that the contents, not the address, are used.


bolzano_1989

Thank you, Rockphorr and NoCforMe for pointing out some differences between MASM and FASM, I'm reading more.

dedndave

this may vary from one assembler to another   :U
some may even require the braces

FORTRANS

Quote from: dedndave on October 06, 2011, 02:41:03 PM
this may vary from one assembler to another   :U
some may even require the braces

Hi,

   Yes, NASM, (The Netwide Assemble)r (and FASM?) do require
them.

Regards,

Steve N.


    MASM                  NASM

MOV AL,Label          MOV AL,[Label]
MOV AL,[Label]        MOV AL,[Label]
MOV EAX OFFSET Label  MOV EAX,label

dedndave

NASM refers to the address of the label if they are not there
so, there can be a difference   :bg