News:

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

Main Menu

TYPE problem

Started by TouEnMasm, December 07, 2020, 02:49:46 AM

Previous topic - Next topic

TouEnMasm

TYPE return a DWORD instead of a real when the variable is a function argument or a local.
in this case:


the prototype CreerImage PROTO  largeur:DWORD,hauteur:DWORD            <<<<<<<<<<< here it is   
and               CreerImage PROC    largeur:REAL4,hauteur:REAL4       <<<<<< no error generate here

                   call to the macro here >>> error find a dword





DIVRR MACRO operand:REQ,diviseur:REQ
Local texttype,zreel4,zreel8,zdword,zqword
texttype equ <>
zreel8 textequ <REAL8>
zreel4 textequ <REAL4>
zdword textequ <DWORD>
zqword textequ <QWORD>

if zreel8 EQ TYPE(operand) ;QWORD
texttype equ <zreel8>
movsd xmm0,operand
movsd xmm1,diviseur
divsd xmm0,xmm1
EXITM<xmm0>

elseif zreel4 EQ TYPE(operand) ;DWORD
texttype equ <zreel8>
movss xmm0,operand
movss xmm1,diviseur
divss xmm0,xmm1
EXITM<xmm0>
elseif zdword EQ TYPE(operand)     ;peut etre local TYPE ERROR
ECHO operand DWORD
texttype equ <zreel8>
movss xmm0,operand
movss xmm1,diviseur
divss xmm0,xmm1
EXITM<xmm0>
elseif zqword EQ TYPE(operand)
ECHO QWORD
else

ECHO WARNING  etiquette must be a real
EXITM<eax>
endif

ENDM
Fa is a musical note to play with CL

jj2007

It works perfectly if you use a slightly different syntax: if type(something) eq REAL8 ...

include \masm32\MasmBasic\MasmBasic.inc   ; necessary only for Print Str$(xmm0)

DIVRR MACRO operand:REQ,diviseur:REQ
if type(operand) eq REAL8
movsd xmm0, operand
% echo op operand is R8
if type(diviseur) eq REAL4
% echo dv diviseur is R4
movss xmm1, diviseur
cvtss2sd xmm1, xmm1
elseif type(diviseur) eq REAL8
% echo dv diviseur is R8
movsd xmm1, diviseur
else
% echo dv diviseur  is DWORD
cvtsi2sd xmm1, diviseur
endif
texttype equ <zreel8>
divsd xmm0,xmm1
EXITM<xmm0>

elseif type(operand) eq REAL4
movd xmm0, operand
cvtss2sd xmm0, xmm0
% echo op operand is R8
if type(diviseur) eq REAL4
% echo dv diviseur is R4
movss xmm1, diviseur
cvtss2sd xmm1, xmm1
elseif type(diviseur) eq REAL8
% echo dv diviseur is R8
movsd xmm1, diviseur
else
% echo dv diviseur  is DWORD
cvtsi2sd xmm1, diviseur
endif
texttype equ <zreel8>
divsd xmm0,xmm1
EXITM<xmm0>
else
.err <not yet implemented>
EXITM<eax>
endif

ENDM
.data
MyR8 REAL8 123.456
MyR4 REAL4 3.0

  Init
  Cls

  Print Str$("123.456/3.0=\t%3f\n", f:DIVRR(MyR8, MyR4))
  mov eax, 41
  Print Str$("123.456/41=\t%3f\n", f:DIVRR(MyR8, eax))

  Print Str$("3.0/123.456=\t%3f\n", f:DIVRR(MyR4, MyR8))
  mov eax, 41
  Print Str$("41/123.456=\t%3f\n", f:DIVRR(MyR4, eax))
EndOfCode


The echos:
op MyR8 is R8
dv MyR4 is R4
op MyR8 is R8
dv eax  is DWORD
op MyR4 is R8
dv MyR8 is R8
op MyR4 is R8
dv eax  is DWORD


The output:
123.456/3.0=    41.2
123.456/41=     3.01
3.0/123.456=    0.0243
41/123.456=     0.0732


I attach a more detailed example.

TouEnMasm

You have not read what I say.
Try to use it with local variables or argument functions,not with  variable in data. (.data )
on Local variable ( LOCAL myreal:REAL4)  or  func arg      :    myfunc PROC onereel:REAL8 >>> TYPE return DWORD or QWORD


Fa is a musical note to play with CL

jj2007

You have not read what I attached.

.code
MyTest proc arg8:REAL8, arg4:REAL4
_Local v8:REAL8=123.456789, v4:REAL4=10.0
  ClearLocals
  ; deb 4, "locals", v8, v4, arg8, arg4
  Print Str$("123.456/10.0=\t%7f\n", f:DIVRR(v8, v4))
  Print Str$("123.456/41.0=\t%7f\n", f:DIVRR(arg8, arg4))
  ret
MyTest endp


It works perfectly with args and local variables. Your syntax has certain problems. Study my macro, and you will (hopefully) understand.

TouEnMasm

found,not syntax,Stack fault
Thanks for help

Fa is a musical note to play with CL

jj2007


TouEnMasm


It has been laborious,The stack fault was an error but ...
the prototype CreerImage PROTO largeur:DWORD,hauteur:DWORD            <<<<<<<<<<< here it is   
and proc   CreerImage PROTO largeur:REAL4,hauteur:REAL4       <<<<<< no error generate here

                   call to the macro here >>> error
Fa is a musical note to play with CL