flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [sug]Allow ESP/RSP to be stated as second register

Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17664
Location: In your JS exploiting you and your system
revolution
Sorry if this has been discussed before on this board, I have vague recollection of it appearing somewhere but I can't find it.

Anyhow, this has been bugging me for the last few days. Consider the following code:
Code:
use32
mov al,[esp+esi]        ;Okay
mov al,[esi+esp]        ;Error: invalid address
    

I know that this is currently a deliberate decision to disallow ESP as the second register but it has been causing me many problems.

The reason is that when variables are declared inside virtual blocks or with EQU's the original register name can become unknown to the programmer. eg.
Code:
virtual at esp
.var db ?
end virtual
reg2 equ esi
... ;lots of intervening space or different included file
mov al,[.var+reg2]      ;Okay
mov al,[reg2+.var]      ;Error: invalid address
    

Sometimes when using macros/included files/EQU's together there can be mutually exclusive situations where manually switching the registers cannot solve the problem.

As a support reason for such a change to FASM to be made I notice that the base/index switching is already happening in 16bit code:
Code:
use16
mov al,[bx+si]  ;Okay
mov al,[si+bx]  ;Okay
    


For the meantime to help both me and my colleagues to solve this difficulty I have effected the following addition to X86_64.INC (06-May-2006):
Code:
        call    store_instruction_code  ;current line 6113
;************** insert this ****************
        cmp     bl,44h                  ;ESP?
        je      try_swap_base_and_index
        cmp     bl,84h                  ;RSP?
        jne     index_not_stack_pointer
      try_swap_base_and_index:
        cmp     cl,1                    ;swapping is not allowed if scale<>1
        jne     index_not_stack_pointer
        xchg    bl,bh                   ;Make ESP/RSP the base
      index_not_stack_pointer:
;*************** end of insert *************
        cmp     bl,44h                  ;previously line 6114, now 6125
    

This simple change has made my life so much easier, I would like to suggest that this idea become part of the future FASM line to enhance the usability. Lets make something that is already very good into something even better Smile
Post 25 May 2006, 15:05
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
yup, other order may be needed in some macros
Post 25 May 2006, 15:48
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17664
Location: In your JS exploiting you and your system
revolution
I was all set to apply my patch again with the new June-1 version but got a happy surprise, the patch is now included. Thanks for that Smile)
Post 02 Jun 2006, 02:55
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.