Author Topic: type of variable  (Read 420 times)

jj2007

  • Member
  • *****
  • Posts: 11317
  • Assembler is fun ;-)
    • MasmBasic
Re: type of variable
« Reply #30 on: April 05, 2021, 11:46:32 PM »
A little demo, using the FpuPush macro (28 matches for if type()... eq):

Code: [Select]
include \masm32\include\masm32rt.inc
.686
.xmm

include FpuPush.asm   ; (attached)

.data
MyQW QWORD 123467890123467890
MyDW DWORD 111
MyR4 REAL4 333.333
MyR8 REAL8 444.444
MyR10 REAL10 555.555
result REAL8 ?
.code
start:
cls
FpuPush MyQW
fstp result
print real8$(result), " is MyQW", 13, 10

FpuPush MyDW
fstp result
print real8$(result), " is MyDW", 13, 10

FpuPush MyR4
fstp result
print real8$(result), " is MyR4", 13, 10

FpuPush MyR8
fstp result
print real8$(result), " is MyQW", 13, 10

FpuPush MyR10
fstp result
print real8$(result), " is MyR10", 13, 10

movlps xmm0, MyQW
FpuPush xmm0
fstp result
print real8$(result), " is xmm0 (as QWORD)", 13, 10

movlps xmm0, MyR8
FpuPush f:xmm0
fstp result
print real8$(result), " is xmm0 (as REAL8)", 13, 10, 10

inkey "bye"
  exit

end start

Output:
Code: [Select]
123467890123467890.000000 is MyQW
111.000000 is MyDW
333.333008 is MyR4
444.444000 is MyQW
555.555000 is MyR10
123467890123467890.000000 is xmm0 (as QWORD)
444.444000 is xmm0 (as REAL8)

Of course, Str$(any number) does the three steps silently under the hood.

TouEnMasm

  • Member
  • *****
  • Posts: 1615
    • EditMasm
Re: type of variable
« Reply #31 on: April 06, 2021, 07:24:57 AM »

This one can be interesting
Quote
?Type macro typ:req
   LOCAL typtxt
   typtxt equ <>
   for arg,<BYTE,SBYTE,WORD,SWORD,FWORD,DWORD,SDWORD,QWORD,SQWORD,OWORD,REAL4,REAL8,REAL10,TBYTE>
       %if (type (typ)) eq arg
         typtxt equ arg
         exitm <>
      endif
    endm
   exitm typtxt
endm


Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 11317
  • Assembler is fun ;-)
    • MasmBasic
Re: type of variable
« Reply #32 on: April 06, 2021, 08:17:53 AM »
Looks good, Yves :thumbsup:

A variant, using a numerical output:

Code: [Select]
include \masm32\include\masm32rt.inc ; pure Masm32 SDK

?Type macro typ:req
   LOCAL tct
   tct=0
   for arg,<BYTE,SBYTE,WORD,SWORD,FWORD,DWORD,SDWORD,QWORD,SQWORD,OWORD,REAL4,REAL8,REAL10,TBYTE>
tct=tct+1
       %if (type (typ)) eq arg
         exitm <>
      endif
    endm
   exitm %tct
endm

.data
MyDW DWORD 123
MyQW QWORD 456
MySQW SQWORD -123
MyR4 REAL4 123.456

.code
start:
  % echo DW=?Type(MyDW)
  % echo R4=?Type(MyR4)
  % echo QW=?Type(MyQW)
  % echo SQW=?Type(MySQW)
  exit
.err
end start

Output window:
Code: [Select]
DW=6
R4=11
QW=8
SQW=9

TouEnMasm

  • Member
  • *****
  • Posts: 1615
    • EditMasm
Re: type of variable
« Reply #33 on: April 06, 2021, 11:19:55 PM »

The Macro is the principle.
It can be see in action here http://masm32.com/board/index.php?topic=8885.msg97287#msg97287
GLU use a bunch of dword,qword,real4,REAL8 who need to be identify correctly and not mixed,failed is the punishment if a dword is not translated to a real4,REAL8.
C do that automatically,not masm except with the use of TYPE.
The form more simple to use is below.
Quote
CONVERTIR MACRO etiquette:REQ,taille:REQ
         IF QWORD EQ TYPE(etiquette) ;si l'argument "etiquette" est du type QWORD
                  ECHO QWORD
         ENDIF
ENDM
Fa is a musical note to play with CL

jj2007

  • Member
  • *****
  • Posts: 11317
  • Assembler is fun ;-)
    • MasmBasic
Re: type of variable
« Reply #34 on: Today at 12:18:55 PM »
Windows Data Types:
Quote
LONGLONG    

A 64-bit signed integer. The range is -9223372036854775808 through 9223372036854775807 decimal.

This type is declared in WinNT.h as follows:
Table 4
C++

#if !defined(_M_IX86)
 typedef __int64 LONGLONG;
#else
 typedef double LONGLONG;
#endif

Quote
DWORD    A 32-bit unsigned integer. The range is 0 through 4294967295 decimal.
This type is declared in IntSafe.h as follows:
typedef unsigned long DWORD;
...
LPDWORD    

A pointer to a DWORD.

This type is declared in WinDef.h as follows:

typedef DWORD *LPDWORD;

So a DWORD is a 32-bit unsigned integer, agreed. And a pointer to a DWORD is also a 32-bit integer, even in x64??
And how do we read the star: a 32-bit integer that is a pointer to a pointer to a DWORD??

Are they completely crazy?

Quote
LPCSTR    

A pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts.

This type is declared in WinNT.h as follows:

typedef __nullterminated CONST CHAR *LPCSTR;

Beautiful :tongue:

Another goodie - can you see the difference?
Quote
#ifdef _WIN64
 typedef HALF_PTR *PHALF_PTR;
#else
 typedef HALF_PTR *PHALF_PTR;
#endif

 :rolleyes:
Quote
#if defined(_WIN64)
    #define POINTER_32 __ptr32
#else
    #define POINTER_32
#endif