flat assembler
Message board for the users of flat assembler.

Index > Main > How work relativeto ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 16 Jun 2025, 12:08
fasmw 1.73
i found this code
Code:
if a relativeto b & a > b
  db a - b
end if    


Not understand clear what do relativeto b & a > b
Post 16 Jun 2025, 12:08
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 16 Jun 2025, 12:10
I do this
Code:
a = 30
  b = 4
if a relativeto b & a > b
  mov al, a - b.  ;I get mov al,30-4
end if  
    


But we can do simple if a > b
Why need a relativeto ?
Post 16 Jun 2025, 12:10
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1169
Location: Russia
macomics 16 Jun 2025, 13:54
Code:
macro movzz a,b {
  display 'movzz a, b'
  if b relativeto ebx
    display 9, 'ebx'
  end if
  if b relativeto edi
    display 9, 'edi'
  end if
  display 13,10
}
label a1 dword at ebx + 5
label a2 dword at edi + 7
virtual at ebx + 6
  a3 dd ?
end virtual
virtual at edi + 8
  a4 dd ?
end virtual
label a5 dword at ebx + edi * 4 + 5
label a6 dword at edi + ebx * 4 + 7
virtual at ebx + esi * 4 + 6
  a7 dd ?
end virtual
virtual at edi + ebp * 4 + 8
  a8 dd ?
end virtual
movzz eax, a1
movzz ecx, a2
movzz edx, a3
movzz eax, a4
movzz eax, a5
movzz ecx, a6
movzz edx, a7
movzz eax, a8    
Post 16 Jun 2025, 13:54
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 18 Jun 2025, 08:39
Thanks.
relativeto not work with xmm registers.
Post 18 Jun 2025, 08:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 18 Jun 2025, 09:02
xmm registers can't be used for addressing. So relaiveto wouldn't make sense with them.
Code:
mov eax,[xmm0] ; ???
virtual at xmmo ; ???    
Post 18 Jun 2025, 09:02
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 18 Jun 2025, 21:43
xmm registers can store address!
one xmm register can store four addresses.
Code:
mov eax,mylabel
movd xmm0,eax

if b relativeto xmm
    movd ebx,xmm0
  end if



    
Post 18 Jun 2025, 21:43
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1169
Location: Russia
macomics 18 Jun 2025, 22:30
Roman wrote:
xmm registers can store address!

The storage option has nothing to do with it. relativeto checks the set from the addressing block (expressions in [] or rex+modr/m+sib fields)
Post 18 Jun 2025, 22:30
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8434
Location: Kraków, Poland
Tomasz Grysztar 19 Jun 2025, 10:50
The XMM registers can, in fact, occur in a [] address, like in this example straight from the manual:
Code:
    vgatherqps xmm0,[xmm2],xmm3        ; gather two floats    
For this reason, XMM registers are among the terms that RELATIVETO is able to distinguish:
Code:
label a at xmm0+3
assert a relativeto xmm0    
However, an issue that you likely encountered is that fasm 1 has different lexemes for a register operand and for the same register name used in an address expression. While the second argument to RELATIVETO is always assumed to be an address expression and is forcibly parsed as such, the first one is not (at the time when fasm's parser sees RELATIVETO, the register symbol has already been parsed). But there is a way to ensure that the argument is parsed as an address expression, just prefix it with "+":
Code:
;assert xmm0 relativeto xmm0            ; fails
assert +xmm0 relativeto xmm0    
You may need to add a plus symbol before the name of argument in your macro, then.

In case of fasm2, such distinction no longer exists. All registers are defined as linear polynomial terms (with ELEMENT), so even when you use a plain register argument to a simple instruction, it is parsed as an expression (what makes "add eax,ebx+0" accepted syntax, while in fasm 1 it was not).
Post 19 Jun 2025, 10:50
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 19 Jun 2025, 11:51
Thanks.
I knew it Smile

work fine
Code:
label myrq at +xmm3
        if myrq relativeto xmm3
        display 're'         ;I get 're'
        end if     
Post 19 Jun 2025, 11:51
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20689
Location: In your JS exploiting you and your system
revolution 19 Jun 2025, 11:56
Sorry for the misinformation from me, and thank to Tomasz for setting the record straight.
Post 19 Jun 2025, 11:56
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1969
Roman 19 Jun 2025, 17:17
relativeto what symbols using ?
I mean symbols -,+,&,:,#
Post 19 Jun 2025, 17:17
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.