News:

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

memory addressing mode

Started by xxxx, February 14, 2005, 01:58:16 AM

Previous topic - Next topic

xxxx


     suppose :

     ORG 0000H
     SUM    DW    ?

     MOV AX,'A'

    what's the difference between:


    MOV [SUM],AX
     
        and

    MOV SUM,AX

?

i ran it in debug and both did the same thing which is fill sum with 'A' at 0000H.



MichaelW

With MASM there is no difference. The encoding will be exactly the same for both statements.

.model small
.stack
.data
    sum dw ?
.code
.startup
    mov   ax,'A'
    mov   [sum],ax
    mov   sum,ax
.exit
end


...
0B43:0017 B84100        MOV     AX,0041
0B43:001A A30400        MOV     [0004],AX
0B43:001D A30400        MOV     [0004],AX
...

eschew obfuscation

xxxx

what is the difference between:


lea ax,[200]

   and

mov ax,[200]

?


thanks

tenkey

With MASM, no difference.

With older versions of MASM, if you wanted to load data from the default data segment, you added the DS: prefix.

mov ax,[ds:200]
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

MichaelW

For the first instruction MASM will return:

error A2070: invalid instruction operands

And MASM will encode the second as a mov ax,200. You can use a segment override to make MASM encode the first instruction as DEBUG would without the segment override, as tenkey stated and as shown below. But note that this is not an effective use of the LEA instruction because at run time it would produce exactly the same result as the smaller and potentially faster mov ax,200. And the same thing applies for the lea ax,sum and mov ax,offset sum shown below -- the move ax, offset sum is smaller and potentially faster. LEA is best used for calculating the effective (offset) address of indirect memory operands, as demonstrated in the last two instructions, or for performing fast calculations (on certain processors).

.model small
.stack
.data
    sum dw ?
.code
.startup   
    lea   ax,ds:[200h]
    lea   ax, sum
    mov   ax,offset sum
    lea   ax,[bp-4]
    lea   ax,[bx+si+sum+2]
.exit
end


0B4B:0017 8D060002      LEA     AX,[0200]
0B4B:001B 8D060E00      LEA     AX,[000E]
0B4B:001F B80E00        MOV     AX,000E
-u
0B4B:0022 8D46FC        LEA     AX,[BP-04]
0B4B:0025 8D801000      LEA     AX,[BX+SI+0010]

eschew obfuscation