flat assembler
Message board for the users of flat assembler.

Index > Main > lea: bug or feature?

Author
Thread Post new topic Reply to topic
Dunduk



Joined: 08 Sep 2003
Posts: 38
Location: Russia
Dunduk
Hi all
Piece of code:
Code:
  .code
    ...
    mov  edi,var1
    lea  esi,[edi+var2-var1]
    ...
   .data
     var1 dd ?
     var2 dd ?
    

Fasm compiles it OK.
But this:
Code:
    lea  esi,[edi-var1+var2]
    

and even this:
Code:
    lea  esi,[edi-var2]
    

generates error "invalid use of symbol"... What's wrong?
Post 18 Oct 2004, 06:37
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
Works for me, I don't know where the problem is?
I have to see the full code...
Post 18 Oct 2004, 07:02
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Joshua



Joined: 12 Jul 2003
Posts: 56
Location: Belgium
Joshua
This has to do with relocations, search the board for a more complete answer.
A workarouns is this:
Code:
virtual
    dd var2
    load var2.offset dword from $-4
end virtual
lea esi,[edi-var2.offset]
    
Post 18 Oct 2004, 07:40
View user's profile Send private message Reply with quote
Dunduk



Joined: 08 Sep 2003
Posts: 38
Location: Russia
Dunduk
Yes, this is solution, but code:
Code:
    lea  esi,[edi+var2]
    

works fine without any "virtual" tricks. What's the difference between these two cases?
Post 18 Oct 2004, 08:04
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
var2 - var 1 is positive value.
var1 - var2 is negative.
AFAIR, Windows can't relocate negative offsets. For detailed explanation look here: http://board.flatassembler.net/topic.php?t=37

Regards.
Post 18 Oct 2004, 08:39
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Dunduk



Joined: 08 Sep 2003
Posts: 38
Location: Russia
Dunduk
Thanks for answer JohnFound. I've tried to find answer on forum but failed. Thanks for the link too.
Post 18 Oct 2004, 08:50
View user's profile Send private message Reply with quote
Dunduk



Joined: 08 Sep 2003
Posts: 38
Location: Russia
Dunduk
That's me again.
I've thought a little and found that (var1-var2) is negative number, but not offset. And
Code:
    lea  esi,[edi-number]    

is legal instruction... What the difference between (-var1+var2) and (var2-var1)?
Post 18 Oct 2004, 09:30
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.