News:

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

Main Menu

Stuff I Don't Know About MASM Programming

Started by Zen, May 08, 2014, 04:31:34 AM

Previous topic - Next topic

Zen

Yes,...my ignorance knows no bounds. It's embarrassing,...really,...:icon_eek:
I was GOOGLING for some MASM directive that I was unfamiliar with,...and, I discovered,...
MSDN's Microsoft Macro Assembler Reference.

Anyway,  I was reading through the various sub-sections: Directives Reference, Operators Reference, Symbols Reference, and, I was absolutely amazed. There was ALOT of information there that I was totally unaware of,...and, have never used in my own code.
...Maybe, this is why I'm such an inept Assembly Language programmer,...
Finally, I'm getting to the point: much of the documentation for the various code directives and operators is incredibly vague. A typical example, from the Directives Reference: ASSUME. Explanation: Enables error checking for register values. Then the documentation shows several examples. I know that this is a very useful mechanism, and, yet, the format of the code examples just confuses me.
For instance: ASSUME segregister:name [[, segregister:name]]...
What are the double brackets? And, is this the required format?   

The question I really want to ask you geniuses is: Is there a cluster of code examples (located, say, in my masm32\examples directory) that demonstrates how this type of code directive is used in reality ?

The various directives in the conditional Error section is an excellent example of what I'm referring to. .ERR, .ERR2, .ERRB, .ERRDEF, .ERRDIF[]], .ERRE, .ERRIDN[], .ERRNB, .ERRNDEF, and, .ERRNZ.

Many of the explanations use the term, expression.
For instance: operator PTR.
The first operator forces the expression to be treated as having the specified type. The second operator specifies a pointer to type.
Example: type PTR expression
               [[distance]] PTR type


Just what is an expression ?

FORTRANS

Hi,

Quote from: Zen on May 08, 2014, 04:31:34 AM
For instance: ASSUME segregister:name [[, segregister:name]]...
What are the double brackets? And, is this the required format?   

The question I really want to ask you geniuses is: Is there a cluster of code examples (located, say, in my masm32\examples directory) that demonstrates how this type of code directive is used in reality ?

   To me the doubled brackets look like a typo.  Anyway, it is unlikely
that you will find a MASM32 example, as ASSUME was to provide
segment register information to MASM.  To support 16-bit
segmented addressing.

HTH,

Steve N.

dedndave

i think that means it's an optional field, no ?

qWord

Quote from: dedndave on May 08, 2014, 06:12:59 AM
i think that means it's an optional field, no ?
yes, the double brackets denotes something optional.

The ASSUME directive is of course also (and often) used in 32 and 64 bit programs. e.g. to assign a pointer-type to a register.
An expression could be any label/symbol, register, memory operand, type ID, constant expression and so on. In the MASM's programmers guide you can find the BNF grammar that (probably) shows all possibilities.
MREAL macros - when you need floating point arithmetic while assembling!

Zen

QWORD,   
Thanks for the info.
...By the way, I'm writing a test application to access some information from  WMI, and, I found this macro in one of your COM examples (IImagCtx.zip):

METHOD macro name,args:VARARG
LOCAL _type1,_type2

_type1 TYPEDEF proto args
_type2 TYPEDEF ptr _type1
EXITM <name _type2 ?>
endm


I've used it to invoke COM interface methods from a virtual table, dozens of times. It seems to work great,...and, yet, I DON'T REALLY UNDERSTAND WHAT IT'S DOING.
Could you explain, please (especially the line, <name _type2 ?>)?

qWord

That macro function returns a declaration statement for structure members. e.g.:

foo struct
    member_name TYPE_ID ?  ; <= this line is what the macro does return
foo ends

TYPE_ID is the type of a function pointer.
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Quote from: qWord on May 10, 2014, 10:50:47 AM
    member_name TYPE_ID ?  ; <= this line is what the macro does return

"this line is what the macro inserts into the code" might be more precise. "returning" macros are those of the print str$(number) family

Of course, qWord is our macro guru and knows the difference perfectly - this is for  clarification, since we are in the Campus ;-)

Zen

QWORD and JOCHEN,   
Thanks for the clarification. I know the macro works correctly, because I've used it in defining member functions in a number of structures, and, then calling the interface method. For instance:   

IWbemLocator STRUCT

METHOD(QueryInterface, _this:PVOID, riid:ptr GUID, ppvObj:ptr LPVOID)
METHOD(AddRef, _this:PVOID)
METHOD(Release, _this:PVOID)
        METHOD(ConnectServer, _this:PVOID, strNetworkResource:DWORD, strUser:DWORD, strPassword:DWORD, strLocale:DWORD, lSecurityFlags:LONG, strAuthority:DWORD, pCtx:DWORD, ppNamespace:LPVOID)    ;       

IWbemLocator ENDS


...And, then I have called the ConnectServer method (and the Release method on the interface) liked this (imitating QWORD's technique):   


mov esi, dwptrWbemLocator
mov esi,[esi] ; ptr IWbemLocator vtbl   

invoke [esi].IWbemLocator.ConnectServer, dwptrWbemLocator, bstrNameSpace, 0, 0, 0, 0, 0, 0, ADDR ptrIWbemServices   


bstrNameSpace is a BSTR returned from SysAllocString (for the string, "root\cimv2", 0, which was converted to a wide character string with MultiByteToWideChar).
...I get the correct HRESULT for this: WBEM_S_NO_ERROR.   
I also had to define a IWbemServices struct. These definitions are taken from the C-style Virtual Table defined in: wbemcli.h (which I found with a GOOGLE search).