News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Assembler time type query..?

Started by Ficko, June 21, 2010, 07:20:11 AM

Previous topic - Next topic

Ficko

Is it possible to get the exact type of a variable not just "is a memory reference"?

I wanna know is "SDWORD", "DWORD" etc. ::)

donkey

Assuming that you are enumerating the labels in a debug build, perhaps, the pdb file format (used with MASM debug builds) may store that information, the tags that are stored can be found in the SymTagEnum enumeration. There are many type related enums but since I have not tried them (they don't directly apply to GoAsm since that assembler uses COFF based labels) I am not sure that they actually specify data width.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

sinsi

Things like sdword/dword are usually dependent on context, how the value is used. Programs like IDA can mostly tell by how it's used, but unless you have the source "it's all dwords".
donkey, they would only show up in a .pdb if they are declared public/externdef wouldn't they?
Light travels faster than sound, that's why some people seem bright until you hear them.

Ficko

Thanks Donkey & sinsi!

I think I didn't express too well what I am looking for. :red

I like to get during assembler time this data.
With ".TYPE" or "OPATTR" you can get only a "hint" but the assembler surely knows the exact type.

I just wondering that there is a "trick" you can substract this information.
Like behind for example "DWORD" is surely an enum value.
If I could get that associated with a variable it would be enough. :bg

sinsi

Well, there are only 16 bits in the return value, and 4 aren't used (11-15) so it's a bit limited.
Is this a macro thing? How are you trying to use it?
Light travels faster than sound, that's why some people seem bright until you hear them.

Ficko

Quote from: sinsi on June 22, 2010, 07:14:28 AM
Well, there are only 16 bits in the return value, and 4 aren't used (11-15) so it's a bit limited.
Is this a macro thing? How are you trying to use it?

Yes is a macro thing.
I know I can't do it purely with "OPATTR" but I thought maybe after I filtered out it is a memory reference maybe there is a way to get some more info out of MASM about it. ::)

I like to know in the macro that the param is a "REAL4/8" "S/DWORD/QWORD".

MichaelW

Quote from: Ficko on June 22, 2010, 06:58:46 AM
but the assembler surely knows the exact type

At least for simple variables I think the assembler only knows the size, so it sees DWORD, SDWORD, and REAL4 as all of the same "type". So for example the assembler will let you use Invoke to pass a DWORD to a procedure where the parameter is declared as a SDWORD, or use a DWORD as an operand for the FLD instruction.

eschew obfuscation

Ficko


At least for simple variables I think the assembler only knows the size...


I am not sure about that since if you declare at the proc - MyPoc proc Param1:SDWORD -
You can use it like - if (Param1 < 0) - will be eq to - if (SDWORD PTR Param1 < 0) -

Looks like the assembler do keeps track on it at least at local level. ::) 

jj2007

Quote from: Ficko on June 22, 2010, 07:23:23 AM
I like to know in the macro that the param is a "REAL4/8" "S/DWORD/QWORD".

Sounds familiar :bg
The MasmBasic Str$() eats all kinds of valid numbers; for example, regs are identified with opattr, then you can check if xmm is part of the text of the arg. Others can be identified by their size:
RealSize = SIZEOF arg   ;; 4 for DWORD, 10 for REAL10
TextSize SIZESTR arg      ;; 2 for ax, al, 3 for eax, 4 and higher for xmm2, xmm(1) etc
But like you, I have not yet found a sound way to distinguish a REAL4 from a DWORD, and a REAL8 from a QWORD, so I work with s: and q: prefixes for the less frequent variants. As you write, the assembler does have that information. Tickling it out is the problem...

Print Str$(ebx) ; simple
Print Str$(MyReal10) ; works for most kinds of arguments
Print "Real4: ", Str$(s:MyR4) ; Real4 variables need the s: prefix in Str$
Print "qWord: ", Str$(q:MyQword) ; qwords need the q: prefix; see also edx::eax in remarks
Print "SSE2: ", Str$("Xmm0=%i", xmm0) ; you can print xmm registers directly

Ficko

Thanks  jj2007! :wink

That's solves some of my problems.

I am wondering that MASM internal macros like - .if .else .endif - are written as "real" macros?

That would mean there is a way to do it just not published by MS. ::) :bg

MichaelW

Now that I test, in the context of the high-level syntax the assembler knows that SBYTE, SWORD, and SDWORD are signed, but this does not necessarily indicate that it knows these type details in other contexts or for other types. I can't see any good reason for Microsoft to provide some of the internally available type information through the OPATTR and similar operators and withhold other information.
eschew obfuscation

jj2007

Here is an excerpt from chapter eight of Randall Hyde's Art of Assembly that suggests a method to distinguish WORD and SWORD:

QuoteThe type operator returns a constant that is the number of bytes of the specified operand. For example, type(word) returns the value two. This revelation, by itself, isn't particularly interesting since the size and sizeof operators also return this value. However, when you use the type operator with the comparison operators (eq, ne, le, lt, gt, and ge), the comparison produces a true result only if the types of the operands are the same. Consider the following definitions:

Integer         typedef word
J               word    ?
K               sword   ?
L               integer ?
M               word    ?

               byte    type (J) eq word        ;value = 0FFh
               byte    type (J) eq sword       ;value = 0
               byte    type (J) eq type (L)    ;value = 0FFh
               byte    type (J) eq type (M)    ;value = 0FFh
               byte    type (L) eq integer     ;value = 0FFh
               byte    type (K) eq dword       ;value = 0

Testbed:

include \masm32\include\masm32rt.inc
include TrueType.inc

.data?
J dword ?
K sdword ?
R4 REAL4 ?

.code
start:
echo
TrueType J
TrueType R4
TrueType K
echo
.err
end start


Output:
J is an unsigned dword
R4 is a real 4
K is a signed dword
Gotcha :toothy
Now the bad news: JWasm fails miserably for this test  :(

qWord

that's great jj! Never thought that this is possible  :U
Quote from: jj2007 on June 22, 2010, 10:09:10 AMNow the bad news: JWasm fails miserably for this test :(
currently no problem for me  - most of my macros wont work with jwasm  ::)

qWord
FPU in a trice: SmplMath
It's that simple!

Ficko

jj2007, that's awesome! :U

I knew it can be done!  :green

dedndave

if you have a string ?
will it return the type (byte) or the sizeof (string length) ?