my_STRUCT STRUCT
mem1 dd 0
mem2 dd 0
my_STRUC ENDS

...

assume ebx: ptr my_STRUC
mov .mem1, eax
assume ebx: nothing
;This works fine

assume ebx: ptr ANYTHING HERE
mov .mem1, eax
assume ebx: nothing
;This also works!!!!???
Posted on 2002-10-14 04:44:22 by Vaxon
If "ANYTHING HERE" is a structure or union and it has mem1 member it will work, if not it will not work, i guess. Post exact code for testing.
Posted on 2002-10-14 04:58:48 by Four-F
ANYTHING is ANYTHING.
It's not another structure or union name. It can be just nothing.
Try it yourself.
Posted on 2002-10-14 05:47:07 by Vaxon
Assume is a high level tool added to masm. Assume does nothing just that it converts the values of the struct to the apporiate directory.

Eg.
assume ebx: ptr my_STRUC

mov [ebx].mem1, eax
assume ebx: nothing


is the same as



mov DWORD PTR [ebx],eax


By right for the second example it should fail as you asked the assembler to assume it as it is some other struct and not my_STRUCT. I do not know how to reason for this behaviour though, maybe something wrong with the coding of masm.
Posted on 2002-10-14 06:47:49 by roticv
So this quote from the 'Device IO control interface' of the Iczelion's VxD tutorial is wrong, isn't it?

assume esi:ptr DIOCParams
.if .dwIoControlCode==DIOC_Open
xor eax,eax
.endif
ret
Posted on 2002-10-14 08:20:48 by Vaxon
So this quote from the 'Device IO control interface' of the Iczelion's VxD tutorial is wrong, isn't it?

assume esi:ptr DIOCParams
.if .dwIoControlCode==DIOC_Open
xor eax,eax
.endif
ret


No! It's absolutely correct indeed, as i can see.
Because of DIOCParams structure has dwIoControlCode member.

ANYTHING is ANYTHING.
It's not another structure or union name. It can be just nothing.
Try it yourself.


It can't be nothing and it can't be something without mem1 member.
I've just got:
error A2006: undefined symbol : mem1

Can't figure it out. What's the problem? :confused:
Posted on 2002-10-14 08:43:28 by Four-F
Although masm doesn't complain about the validity of the "ptr WHATEVER", it does complain about the use of eax within the code. This is most likely due to the fact that masm uses a multi pass system for parsing the code, so in one pass it may tokenise the word WHATEVER, but not try reconcile this until a later pass (in which it does not check for un-connected tokens, which arguably is a failing).

When it comes to replace the token with the appropriate data, it cannot because it is a null entry, and will always (at least should always) fail. If you can prove this is not the case with actual code, then it is a bug, and should be reported to Microsoft. Although due to the severity (or lack thereof) I doubt it will be fixed particularly quickly.

Of course this is purely conjecture on my part, and it would not hold up under cross examination in a court of law...

Mirno
Posted on 2002-10-14 09:24:24 by Mirno
I may not do VXD programming but the code is correct.

assume esi:ptr DIOCParams 

.if [esi].dwIoControlCode==DIOC_Open
xor eax,eax
.endif
ret


is acutally expanded by the assembler to something like



cmp DWORD PTR [esi + (offsetofdwIoControlCode)],DIOC_Open
jne _1
xor eax,eax
_1:
ret


Sorry not to give you the acutal details, for i cannot find dwIoControlCode in any on my include files.
Posted on 2002-10-14 09:25:49 by roticv
I have noticed that this only happens when I compile VxD's.
If I use
ASSUME ebx: PTR my_STRUC
mov .member2, eax

sometimes it doesn't seem to work right. I mean it writes to an unpredictable memory location.
I even deleted the ASSUME line and still it compiled and linked with no error or warning messages.
But if I do like this:
mov .my_STRUC.member2, eax
it seems to work fine.
Don't know why it is.
When I compile vxd's I use some additional commandline switches: -Cx -DMASM6 -DBLD_COFF -DIS_32
I don't use them for exe or dll files compilation.
Maybe that makes the problem?
Anyways thanks, guys for helping.
Posted on 2002-10-15 02:32:18 by Vaxon
That's funny... usually if you do not ask the assembler to assume, it will not assume that the register is any variable. This could also be set with the assume register:nothing.



assume ebx:PTR my_STRUT
mov [ebx].Member2,eax


is the same as



mov DWORD PTR[ebx+4],eax


Using mov .my_STRUC.member2, eax is the same as above exepct that you do not use assume :grin:

lolx.. i think i found out the mistake with your code. Your my_STRUCT is defined wrongly. Should be



my_STRUCT STRUCT
mem1 dd ?
mem2 dd ?
my_STRUCT ends


and not


my_STRUCT STRUCT
mem1 dd 0
mem2 dd 0
my_STRUCT ends
Posted on 2002-10-15 02:52:27 by roticv
Why can't I use default values for my structure other than '?' ?
By the way, I declare structures in the .inc file. Hope nothing wrong with that?
Posted on 2002-10-15 03:14:50 by Vaxon
I think i am in the wrong.

Chapter 5 of the MASM did state that
When you declare a structure or union type, you create a template for data. The template states the sizes and, optionally, the initial values in the structure or union, but allocates no memory.

The STRUCT keyword marks the beginning of a type declaration for a structure. (STRUCT and STRUC are synonyms.) The format for STRUCT and UNION type declarations is:

name {STRUCT | UNION} [] [[,NONUNIQUE ]]
fielddeclarations
name ENDS


The fielddeclarations is a series of one or more variable declarations. You can declare default initial values individually or with the DUP operator. (See ?Defining Structure and Union Variables,? following.) ?Referencing Structures, Unions, and Fields,? later in this chapter, explains the NONUNIQUE keyword. You can nest structures and unions, as explained in ?Nested Structures and Unions,? also later in this chapter.

Posted on 2002-10-16 08:12:20 by roticv
Well, It seems to work fine without ASSUME now.
Will use mov .my_STRUC.member2, eax from now on.
Do not know what the problem was...
Well, so far so good...
Thank you for helping...
Posted on 2002-10-17 02:32:17 by Vaxon