Hello masm forum,
the question is simple: What is the difference between using just "dword ptr" and using a source destination "dword ptr ds:"?
example:
; The result is the same right?
mov eax, dword ptr ds:[eax]
mov eax, dword ptr[eax]
yes - the DS "segment" is the default for most cases
the assembler should know that and not instert a "segment override" opcode byte
exceptions:
the EBP and ESP registers use the SS segment
however, if EBP is used with another register, DS is used, like [ebx+ebp]
the ES register is used with EDI during execution of string instructions
the exceptions don't really make much difference in a flat model program
as all segment registers point to the same memory, essentially
this stuff was (is) more pertinent for 16-bit programs
the ASSUME directive may be used to tell the assembler that a segment register points to a specific segment or group
thanks for the long and clear answer.
so what do you recommend in a segment like this & using/compiling as 32 bit.
.686
.model flat, stdcall
Using "ds:" or just "dword ptr"?
mov eax, [eax] is enough - the assembler knows that eax is a dword, and that you mean the data segment.
However, and [eax], 0 will choke, as 0 can be byte, word or dword:
and dword ptr [eax], 0 ; much shorter than mov dword ptr [eax], 0
and word ptr [eax], 0
and byte ptr [eax], 0
mov dword ptr [eax], 0
or dword ptr [eax], -1 ; much shorter than mov dword ptr [eax], -1
add dword ptr [eax], 12345678h
inc byte ptr [eax]
etc etc - if there is any ambiguity re size of dest operand, you need to specify it, otherwise not. Same for structures such as RECT:
mov rc.left, 123 is fine - the assembler knows it's a DWORD
EDIT: Actually, it's a bad habit to specify the size if it's not required, as it is a source of difficult to chase bugs: It overrides the default size.
For example, mov byte ptr rc.left, 123 looks cool and assembles without errors, but what if rc.left had already a value of 2000?
Okay thanks for the info friends :t
You will need the DS: override if you are using absolute addresses
mov dword ptr ds:[00402000h],5 ;OK
mov dword ptr [00402000h],5 ;error A2001: immediate operand not allowed
Of course you don't usually use addresses like that in win32 programming.
Quotethis stuff was (is) more pertinent for 16-bit programs
In 16-bit code, at least for the older versions, ML would insert segment overrides as necessary.
thanks guys, very helpfull :t