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 (http://msdn.microsoft.com/en-us/library/afzk3475.aspx).
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 (http://msdn.microsoft.com/en-us/library/kx3dscek.aspx). 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 (http://msdn.microsoft.com/en-us/library/1sab7t6k.aspx), .ERR2 (http://msdn.microsoft.com/en-us/library/7fy7s74d.aspx), .ERRB (http://msdn.microsoft.com/en-us/library/zzwxc7c1.aspx), .ERRDEF (http://msdn.microsoft.com/en-us/library/1xxsw032.aspx), .ERRDIF[]] (http://msdn.microsoft.com/en-us/library/hhceac02.aspx), .ERRE (http://msdn.microsoft.com/en-us/library/k1b00460.aspx), .ERRIDN[] (http://msdn.microsoft.com/en-us/library/3b3dc3s0.aspx), .ERRNB (http://msdn.microsoft.com/en-us/library/w72b6kkk.aspx), .ERRNDEF (http://msdn.microsoft.com/en-us/library/08cssy16.aspx), and, .ERRNZ (http://msdn.microsoft.com/en-us/library/bkz3d0ww.aspx).
Many of the explanations use the term, expression.
For instance: operator PTR (http://msdn.microsoft.com/en-us/library/ek20ye9k.aspx).
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 ?
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.
i think that means it's an optional field, no ?
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.
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) (http://masm32.com/board/index.php?topic=1821.msg18757#msg18757):
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 ?>)?
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.
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 ;-)
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).