flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macro add float and int problem.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 11 Oct 2022, 17:52
Fasmw 1.73
I try this macro but result wrong.
Code:
macro app a,b {
   ee equ add
   e2 equ eax
   if  a#_type = 2
      display 'yes'
      mov eax,[a]
   else
      display 'no;'
      cvtsi2ss xmm1,[a]
      ee equ addss
      e2 equ xmm1
   end if
   vv equ ebx
   if  b#_type = 2
      display '2yes;'
      ;mov ebx,[b]
      vv equ [b]
   else
      display '2no;'
      cvtsi2ss xmm2,[b]
      vv equ xmm2
   end if
   ee e2,vv

}    

p1 dd 10.0
p1_type = 4
p2 dd 2
p2_type = 2

app p1,p2
    

I expected addss xmm1,[b]
But IDA Pro show addss xmm1,xmm2
Post 11 Oct 2022, 17:52
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1071
Location: Russia
macomics 11 Oct 2022, 17:58
Code:
ee eq addss
e2 equ xmm1    

Code:
vv equ xmm2    

Code:
ee e2,vv ; addss xmm1, xmm2    

You got what you wrote yourself. The macro works correctly.
Post 11 Oct 2022, 17:58
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 11 Oct 2022, 18:08
But why ?
if b#_type = 2 ;i expect this
display '2yes;'
;mov ebx,[b]
vv equ [b]
else ;else must work if b#_type not 2
display '2no;'
cvtsi2ss xmm2,[b]
vv equ xmm2 ;but get this ! Why ?
end if
Post 11 Oct 2022, 18:08
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1071
Location: Russia
macomics 11 Oct 2022, 18:11
Because if is handled by an assembler, and equ is handled by a preprocessor. First, everything related to the preprocessor is calculated, and then the assembler starts working. Macro substitution is also handled by the preprocessor.


Last edited by macomics on 11 Oct 2022, 18:13; edited 1 time in total
Post 11 Oct 2022, 18:11
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 11 Oct 2022, 18:12
And how fix this ?
Post 11 Oct 2022, 18:12
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1071
Location: Russia
macomics 11 Oct 2022, 18:14
Try using match
Post 11 Oct 2022, 18:14
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 11 Oct 2022, 18:16
Quote:
using match

I'm in shoke Smile

I do more simple
Code:
macro app a,b {
   if  a#_type = 2
       cvtsi2ss xmm0,[a]
   else
      movss xmm0,[a]
   end if
   if  b#_type = 2
       cvtsi2ss xmm1,[b]
   else
      movss xmm1,[b]
   end if
   addss xmm0,xmm1
}     
Post 11 Oct 2022, 18:16
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 11 Oct 2022, 18:44
How do somthing like this ? Fasm get me error
Code:
if  a#_type = b#_type = 4
       display 'rt;'
   end if
    


Its right variant ?
Code:
if  a#_type = b#_type & a#_type = 4 
display 'rt;'
end if    
Post 11 Oct 2022, 18:44
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1071
Location: Russia
macomics 11 Oct 2022, 19:03
Code:
if a#_type = 4 & b#_type = 4
  display "Hello",13,10
end if    
Post 11 Oct 2022, 19:03
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 11 Oct 2022, 19:07
Thanks. Work
Code:
macro app a,b,c {
   if  a#_type = 4 & b#_type = 4
       movss xmm0,[a]
       addss xmm0,[b]
   end if

   if  a#_type = 2 & b#_type = 2
       mov eax,[a]
       add eax,[b]
   end if

    if  a#_type = 4 & b#_type = 2
       cvtsi2ss xmm0,[b]
       addss xmm0,[a]
   end if
if  a#_type = 2 & b#_type =  4
       cvtsi2ss xmm0,[a]
       addss xmm0,[b]
   end if

   if    c#_type = 4
   movss [c],xmm0
   else
        cvtss2si eax,xmm0
       mov [c],eax
   end if

}                 
    
Post 11 Oct 2022, 19:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.