flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Bug in address generation

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 413
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 05 Sep 2009, 08:39
this be compiled wrong
add [r15+rsp+0],al
add [r15d+esp+0],al

but this is OK
add [rsp+r15+0],al
add [esp+r15d+0],al
Post 05 Sep 2009, 08:39
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 05 Sep 2009, 09:28
What your problem seems to be is that you expect ESP or RSP to be scaled by *1, but you can't encode that according to Intel Instruction Set Manual 2A (page 40) and FASM helps you out be enconding the other value as scale and adding ESP/RSP to it.

Next time, please:
1) FASM version (1.68.xx stable or 1.69.xx)
2) What would the "OK"-binary look like and what was the result

If its only the order in which you want it to be assembled, you can't stamp this as a bug. If it doesn't do algorithmically the same as you would expect, then it would be eligible for a bug.
Post 05 Sep 2009, 09:28
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20356
Location: In your JS exploiting you and your system
revolution 05 Sep 2009, 09:58
CandyMan wrote:
this be compiled wrong
add [r15+rsp+0],al
add [r15d+esp+0],al

but this is OK
add [rsp+r15+0],al
add [esp+r15d+0],al
Addition is commutative so the generated code will perform the same function without error. As Madis731 points out, the x86 instruction set does not support encoding rsp as a scaled register so fasm will switch registers so that you don't have to manually recode your source just to "force" fasm to assemble it. See this thread to see where this change was first implemented.
Post 05 Sep 2009, 09:58
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 413
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 05 Sep 2009, 14:56
After the exchange of registers he can happen, that the rex prefix will be wrong.
Post 05 Sep 2009, 14:56
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20356
Location: In your JS exploiting you and your system
revolution 05 Sep 2009, 15:01
CandyMan wrote:
After the exchange of registers he can happen, that the rex prefix will be wrong.
Oh, okay, good spotting with that.
Post 05 Sep 2009, 15:01
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20356
Location: In your JS exploiting you and your system
revolution 06 Sep 2009, 14:50
Code:
use64

add [r15+rsp],al    ;41 00 04 3c
add [rsp+r15],al        ;42 00 04 3c

add [r15d+esp],al   ;67 41 00 04 3c
add [esp+r15d],al    ;67 42 00 04 3c    
Can a mod please mark this topic as sticky.
Post 06 Sep 2009, 14:50
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 07 Sep 2009, 08:45
Fixed in 1.69.04.
Post 07 Sep 2009, 08:45
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.