News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Assume ds: adds ss: prefix

Started by jj2007, January 04, 2013, 08:18:46 AM

Previous topic - Next topic

jj2007

Output:
5        bytes for normal
6        bytes for ds


Why is the same instruction one byte longer (Olly says it's ss:) just by declaring assume ds:nothing?

include \masm32\include\masm32rt.inc

CodeSize MACRO algo, mode
  pushad
  mov eax, offset &algo&_end
  sub eax, offset &algo&_start
  print str$(eax), 9, " bytes for &algo&", 13, 10
  popad
ENDM

.code
MyDwords        dd 0h, 11111111h, 22222222h, 33333333h, 44444444h
start:

normal_start:
        mov eax, MyDwords[DWORD*3]
normal_end:
        print hex$(eax), 13, 10

        ASSUME DS:NOTHING

ds_start:
        mov eax, MyDwords[DWORD*3]        ; why does it now add the ss: prefix??
ds_end:
        print hex$(eax), 13, 10, 10
        CodeSize normal
        CodeSize ds
        inkey chr$(0)
        exit

end start


qWord

maybe because you tell MASM that DS (implicitly encoded) does not contain a valid segment selector thus it use the next best (non-code) segment register, which seems to be SS?

EDIT: compare: assume DS:@data
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Thanks, that makes sense :t

dsexplicit_start:
   mov eax, ds:MyDwords[DWORD*3]   ; 5 bytes, no prefix!
dsexplicit_end:


MichaelW

I'm not sure exactly how the switch from 16-bit code to 32-bit code and the FLAT memory model affected this, but for most instructions that access data, and where the instruction does not reference (E)BP, DS is the default segment register. If the assembler knows that the default is not usable, then it stands to reason that it would substitute some other segment register. For the 16-bit Microsoft memory models the normal startup code set SS=DS (both pointing to DGROUP), so SS provided an alternative route to access the data segment (or default data segment for the memory models that supported more than one data segment) when DS was pointed elsewhere.
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

the assembler has a default ASSUME for 4 segment registers (probably FS as well, for flat model)
QuotePrior to the .MODEL statement (or in its absence), the assembler sets
the ASSUME statement for DS, ES, and SS to the current segment.

it may be modified for models other than flat, but we don't really care about those   :P
the point is, the default ASSUME for DS is DGROUP in the flat model

when you used ASSUME DS:NOTHING, it no longer knows where DS is pointing,
so it uses a register that can access DGROUP, according to the assumptions

anytime you use a DS segment override in the source, and the default segment
for that addressing mode is DS, the assembler uses no segment override
this behaviour is independent of ASSUME

for older assembler versions (older than 6.1 i think), there are no default assumptions
when i used 5.10, i even had to tell it where CS was pointing   :P

MichaelW

I think it has a default assume for 5 segment registers including FS, and none for GS.
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

i think you're right for flat model
but, the quote above is from the masm 6.1 programmers reference - and they didn't mention it in that paragraph
it seems that CS is also included (we don't have to set it like 5.10)
and FS is assumed to be ERROR, i think

japheth

> the point is, the default ASSUME for DS is DGROUP in the flat model

No. DGROUP doesn't exist in flat memory models ( and COFF doesn't know groups ). The default is


assume ds:flat


> when i used 5.10, i even had to tell it where CS was pointing   :P

Yes. That's also not that ludicrous as it may seem. There are - admittedly rare - situations where code is to be executed with a "wrong" CS. That means: calls and jumps are ok because relative addressing is used there, but you can't use CS to address a constant in the code.


dedndave

i am only going by what the manual says - lol
but i must admit, the manual leaves a lot of "room for discovery"   :P
especially when it comes to the flat model vs the older MZ models
they could have put a nice table in there to clarify some of this