flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Reverse equ?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Apr 2009, 21:56
foo equ 'bar'
db foo

and

foo equ 'b','a','r'
db foo

and

reverse db 'bar'

compile.. but

foo equ reverse 'bar'
db foo

and

foo equ reverse 'b','a','r'
db foo

and

foo reverse equ 'bar'
db foo

and

foo reverse equ 'b','a','r'
db foo


do not. X_x
Please save me (again), great FASM lords! Embarassed
Post 01 Apr 2009, 21:56
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20530
Location: In your JS exploiting you and your system
revolution 01 Apr 2009, 22:15
equ is textual replacement.
Post 01 Apr 2009, 22:15
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 01 Apr 2009, 22:19
If I understand correctly, what you are trying to do, you can try something like this:
Code:
struc revdb [data]
{ common
  . db data
  repeat ($-.)/2
   load b1 byte from .+%-1
   load b2 byte from $-%
   store byte b1 at $-%
   store byte b2 at .+%-1
  end repeat }

example revdb 'bar'    
Post 01 Apr 2009, 22:19
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: 20530
Location: In your JS exploiting you and your system
revolution 01 Apr 2009, 22:22
Oh, you mean you want to reverse the byte stream? Was that your question? Sorry, looks like my question parser is not working very well Embarassed
Post 01 Apr 2009, 22:22
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Apr 2009, 22:23
Tomasz Grysztar wrote:
If I understand correctly, what you are trying to do, you can try something like this:
Code:
struc revdb [data]
{ common
  . db data
  repeat ($-.)/2
   load b1 byte from .+%-1
   load b2 byte from $-%
   store byte b1 at $-%
   store byte b2 at .+%-1
  end repeat }

example revdb 'bar'    
Thanks.. it would be easier to just do "reverse db 'bar'" though.

I need to know how to reverse string in equate. So it will be like I put "foo equ 'rab'"..
Post 01 Apr 2009, 22:23
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20530
Location: In your JS exploiting you and your system
revolution 01 Apr 2009, 22:26
Azu wrote:
I need to know how to reverse string in equate. So it will be like I put "foo equ 'rab'"..
Okay, that is the type of direct question I can understand. The preprocessor handles equ's and it is not possible to do tricks like that with the preprocessor.
Post 01 Apr 2009, 22:26
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Apr 2009, 22:34
revolution wrote:
Azu wrote:
I need to know how to reverse string in equate. So it will be like I put "foo equ 'rab'"..
Okay, that is the type of direct question I can understand. The preprocessor handles equ's and it is not possible to do tricks like that with the preprocessor.
Thanks.
I'm guessing it is done basically the same way adding ror and rol was?
What file should I look in to find the equ code so I can make a revequ?


Last edited by Azu on 01 Apr 2009, 22:36; edited 1 time in total
Post 01 Apr 2009, 22:34
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20530
Location: In your JS exploiting you and your system
revolution 01 Apr 2009, 22:36
PREPROCE.INC
Post 01 Apr 2009, 22:36
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Apr 2009, 22:37
Thank you again ^.^
Post 01 Apr 2009, 22:37
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20530
Location: In your JS exploiting you and your system
revolution 01 Apr 2009, 22:40
I'm not sure what you refer to when you say "the same way adding ror and rol was" but it looks to me like those would be assembler-stage operators? Whereas equ is preprocessor-stage so maybe not the same thing.
Post 01 Apr 2009, 22:40
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 01 Apr 2009, 23:02
Meant in preprocessor (I think that's what you call it.. whatever it is that shl and shr are done in). You know like so you can do "mov [port],80 ror 8" for defining ports for winsock. You helped me add them to FASM before.



Edit: Whoops that was LocoDelAssembly sorry. Confused
Post 01 Apr 2009, 23:02
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Apr 2009, 00:25
Ugh the PREPROCE.INC code looks a lot harder to add to. Please isn't there some way to do it in a macro or something instead?

Or if can't reverse in equ then at least some way to pass to my struct that that one should be reversed?

Something like

Code:
Blah equ 1
moo    equ 'ooooom'

struc edb[data]{     common
      .len dd .lenn
       if reverse
          . reverse db data
   else
                . db data
   endif
       .lenn=$-.

woof   edb Blah,reverse moo,"hello",5    
????


FASM source is scary to me I don't want to mess with it again Sad
Post 02 Apr 2009, 00:25
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Apr 2009, 00:44
Code:
struc edb [data] {

forward
  done equ
  match =reverse op, data \{
  done equ 1
  ; Tomasz's code
  . db op
  repeat ($-.)/2
   load b1 byte from .+%-1
   load b2 byte from $-%
   store byte b1 at $-%
   store byte b2 at .+%-1
  end repeat
\}
  match , done\{
  . db data
  \}
}    

Or something near (I haven't tested it)
Post 02 Apr 2009, 00:44
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Apr 2009, 02:14
LocoDelAssembly wrote:
Code:
struc edb [data] {

forward
  done equ
  match =reverse op, data \{
  done equ 1
  ; Tomasz's code
  . db op
  repeat ($-.)/2
   load b1 byte from .+%-1
   load b2 byte from $-%
   store byte b1 at $-%
   store byte b2 at .+%-1
  end repeat
\}
  match , done\{
  . db data
  \}
}    

Or something near (I haven't tested it)


Thank you!

But no matter how much I change it it always fails to compile, with either "symbol already defined" or "extra character on line".. and I've tried literally EVERYTHING I could think of so far.. Crying or Very sad

Starting to think maybe it would be easier to change FASM itself for this afterall..
Post 02 Apr 2009, 02:14
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Apr 2009, 02:40
Oh right sorry, the symbol is defined several times (at least once for each parameter).

This (I hope) will work OK:
Code:
struc edb [data] {
common
  label . byte
forward
  local l
  done equ

  match =reverse op, data \{
    done equ 1
    ; Tomasz's code
    l db op
    repeat ($-l)/2
      load b1 byte from l+%-1
      load b2 byte from $-%
      store byte b1 at $-%
      store byte b2 at l+%-1
    end repeat
  \}

  match , done \{
    db data
  \}
}    
Post 02 Apr 2009, 02:40
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Apr 2009, 03:04
Sweet thanks. I hate to keep bugging you, but.. no matter how I try it, it doesn't compile, or gives the wrong data.. help please.. :/

Code:
struc edb [data] {
common
.lenn dd .len
  label . byte
forward
  local l
  done equ

  match =reverse op, data \{
    done equ 1
    ; Tomasz's code
    l db op
    repeat ($-l)/2
      load b1 byte from l+%-1
      load b2 byte from $-%
      store byte b1 at $-%
      store byte b2 at l+%-1
    end repeat
  \}

  match , done \{
    db data
  \}
  
.len = $-.  
}    


Code:
struc edb [data] {
common
  label . byte
forward
  local l
  done equ

  match =reverse op, data \{
    done equ 1
    ; Tomasz's code
dd ..temp2-l
    l db op
..temp2:
.len = $-.
    repeat ($-l)/2
      load b1 byte from l+%-1
      load b2 byte from $-%
      store byte b1 at $-%
      store byte b2 at l+%-1
    end repeat
  \}

  match , done \{
common
..temp1:
    db data
.len = $-..temp1
  \}
           
}    


Code:
struc edb [data] {
common
  label . byte
forward
  local l
  done equ

  match =reverse op, data \{
    done equ 1
    ; Tomasz's code
dd ..temp2-l
    l db op
..temp2:
    repeat ($-l)/2
      load b1 byte from l+%-1
      load b2 byte from $-%
      store byte b1 at $-%
      store byte b2 at l+%-1
    end repeat
  \}

  match , done \{
dd blah2b-blah2a
blah2a:
    db data
blah2b:
  \}
     
.len = $-.  
}    


Code:
struc edb [data] {
common
  label .lenn dword
  label . byte
forward
  local l
  done equ

  match =reverse op, data \{
    done equ 1
    ; Tomasz's code
dd .len
    l db op
    repeat ($-l)/2
      load b1 byte from l+%-1
      load b2 byte from $-%
      store byte b1 at $-%
      store byte b2 at l+%-1
    end repeat
.len = $-.
  \}

  match , done \{
dd .len
    db data
.len = $-.
  \}
      

}    
Code:
struc edb [data] {
common
  label .lenn dword
  label . byte
forward
  local l
  done equ

  match =reverse op, data \{
    done equ 1
    ; Tomasz's code
dd .len
@@:
    l db op
    repeat ($-l)/2
      load b1 byte from l+%-1
      load b2 byte from $-%
      store byte b1 at $-%
      store byte b2 at l+%-1
    end repeat
.len equ $-@b
  \}

  match , done \{
dd .len
@@:
    db data
.len equ $-@b
  \}
      

}    


Nothing works....
Post 02 Apr 2009, 03:04
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20530
Location: In your JS exploiting you and your system
revolution 02 Apr 2009, 03:08
Works fine for me. How are you trying to use it?
Code:
struc edb [data] {
common
  label . byte
forward
  local l
  done equ

  match =reverse op, data \{
    done equ 1
    ; Tomasz's code
    l db op
    repeat ($-l)/2
      load b1 byte from l+%-1
      load b2 byte from $-%
      store byte b1 at $-%
      store byte b2 at l+%-1
    end repeat
  \}

  match , done \{
    db data
  \}
}

x_norm edb 'abcd'
x_reverse edb reverse 'abcd'    
Post 02 Apr 2009, 03:08
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Apr 2009, 03:26
All the examples I posted fail to compile, or crash on startup due to putting in the wrong length E.G. 0 Sad


Your example won't compile because you deleted the .len definition.. so there are "undefined symbol X.len" errors.. and it would crash anyways, since you also took the part that embeds the length.. basically you removed everything except the db..
Post 02 Apr 2009, 03:26
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Apr 2009, 03:28
revolution, he added this to my code:
Code:
       
.len = $-.     

That is located under the forward block so it fails because it is defined several times which is OK for assembly-time variables but very bad for forward referencing (he also added a size field at the common block).

Fix:Just add a second common block after the forward block, i.e. replace the last line with:
Code:
common
.len = $-.    
Post 02 Apr 2009, 03:28
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu 02 Apr 2009, 03:32
Ah, got it working perfect now. Thank you. I forgot about the "common". Shouldn't have been in such a hurry lol sorry. Embarassed
Post 02 Apr 2009, 03:32
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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.