flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [Help]:String table macro

Author
Thread Post new topic Reply to topic
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Not an expert in macros. I tried way back to understand vid's tutorial but couldn't or maybe the macros didn't understand me.

Anyway, I want to create a string table such that each string's label is s+ its index. I tried the following but alas. So in the end my table will consist of s#index db value,0 don't laugh

Code:
macro string_table [value]
{
      local index
    forward
      index = index+1
    common
      s#index: db value,0

}
string_table 'one','two','three'
;
; s1 db 'one',0
; s2 db 'two',0
; s3 db 'three',0

    


And while you are at it don't just give me the code you have to explain also why index is not being resolved to any number

Some one help me with this.
Post 25 Dec 2013, 18:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
You might be interested in this topic:

http://board.flatassembler.net/topic.php?t=12012

'index' is not a text equate so it is always concatenated as 'index' during preprocessing. The value of index is not converted to ASCII by the macro since it is an assembly time variable.
Post 25 Dec 2013, 18:20
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
typedef,

Be careful when you mix assembly & preprocessor.
Post 25 Dec 2013, 19:10
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
baldr wrote:
typedef,

Be careful when you mix assembly & preprocessor.


I wouldn't know because I have limited knowledge of FASM macros.

Most of the macro examples are just mangled together without proper 'vocab' list.

At least this one by vid is somewhat fair: http://bos.asmhackers.net/docs/FASM%20tutorial/preproc.html

Anyway, someone just fix my macro and I'll study it...and I will call it a day. Smile
Post 25 Dec 2013, 19:20
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
typedef wrote:
Anyway, someone just fix my macro and I'll study it...and I will call it a day.
Why so lazy?

Anyhow a macro is already written for you in the link I posted above. Just use it instead of your broken one. Fixing your broken macro would require too much effort.
Post 25 Dec 2013, 19:26
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
revolution wrote:
typedef wrote:
Anyway, someone just fix my macro and I'll study it...and I will call it a day.
Why so lazy?

Anyhow a macro is already written for you in the link I posted above. Just use it instead of your broken one. Fixing your broken macro would require too much effort.


Hahaha now look who's being lazy Very Happy Very Happy

I hate using people's code when I can get an understanding of what the code does and come up with my own ideas.

To say the least, you are giving me a fish instead of a fishing pole. If you mend this code rev, I'll buy you something.

Your linked example doesn't seem to create what I want or maybe it's just too cryptic. I want to define strings where their labels are defined by the macro itself but at the same time I know which string is which.

instead of having to write this

Code:
s1 db 'string_one',0
s2 db 'string_two',0
...
s10000 db 'string_10k',0
    



I want to do this
Code:
string_table 'string_one','string_two',\...
                  ,'string_10k'
    


I don't want anything else in between them. Just that format and when I want to use them
Code:
invoke MessageBoxW,0,s106,0,0
    
Post 25 Dec 2013, 19:59
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
Anybody have good name for iteration number inside irps (apart of %)?
Post 25 Dec 2013, 20:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17278
Location: In your JS exploiting you and your system
revolution
typedef wrote:
Hahaha now look who's being lazy
I'm only lazy when it comes to helping people that are lazy.
Post 25 Dec 2013, 20:16
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
It's okay. I'll type the same thing 10,000 times while crying blood. Very Happy

Merry Christmas or Happy Evolution day.

Wish me luck.
Post 25 Dec 2013, 21:04
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
I like the following method used by baldr and others to perform calculations with the preprocessor:
Code:
struc equ! expr { 
  rept 1 value:expr \{ 
    restore . 
    . equ value 
  \} 
}    
...just changing a couple lines of the original macro - basically, rewriting it:
Code:
macro string_table [value]
{
    common
      local index
      index equ 0
    forward 
      index equ! index+1
      match A,index \{
        s\#A: db value,0
      \}
}    
Why doesn't your macro work? : Index doesn't get resolved because the preprocessor doesn't evaluate expressions (except in REPT, afaik). Additionally, you've put the DB in a common block - which means only one string gets defined. {I could go on...there are more reasons.}

Why is the MATCH needed? : The concatenation doesn't resolve index to it's value (page 97 of the manual explains symbolic replacement).

Sometimes your posts are so lazy that you just seem like a troll. Happy Holidays anyhow. Very Happy

_________________
¯\(°_o)/¯ unlicense.org
Post 26 Dec 2013, 08:06
View user's profile Send private message Visit poster's website Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
You need an array of pointers to texts/strings? To access like this? mov eax, [s+ecx*4] ; ?
Code:
macro texta name, [t] {
 common       ; begin...
  name:       ; create label
 forward      ; first... 
  local l     ; create array of pointers
  dd l        ; to text addresses
 forward      ; then...
  l db t, 0   ; create array of strings
}    
Code:
; create:

texta fruits,\
 'Apple', 'Banana', 'Cherry', 'Grape'

; access in code:

mov ecx, 2                ; index='Cherry'
mov eax, [fruits+ecx*4]   ; eax=address of text    

To prefix the index with "s" doesn't make sense: s0, s1, s2, etc. In that case, why not just use the index? For descriptive IDs, try this:
Code:
; create text array with IDs and length (.$)

macro texti name, [t] {
 common
  name:       ; begin
  ?n=0        ; index=0
 forward      ; create array of pointers
  local l
  dd l
 forward
  define ?s 0
  match a==b, t \{
   l db b, 0
   a=?n
   ?n=?n+1
   define ?s 1
  \}
  if ?s eq 0
   'Syntax error'
  end if
 common
  name#.$=?n
}    
Code:
; create:

texti fruits,\
 ID.APPLE='Apple', ID.BANANA='Banana',\
 ID.CHERRY='Cherry', ID.GRAPE='Grape'

; access is the same:

mov ecx, ID.CHERRY        ; index=2
mov eax, [fruits+ecx*4]   ; eax=address of text    
Remember that each index is a pointer so [] is needed to get its value which is an address: [p].
Quote:
explain also why index is not being resolved to any number
"local name" generates a temporary unique name that can be used in any context; example, to create numeric constant or equate.
Code:
local index
; ...
index=1     ; numeric constant
index equ 1 ; or equate (but not both)    
Quote:
Not an expert in macros... I have limited knowledge of FASM macros
Well, you're not claiming to be a master or ancient guru and telling everyone "Don't use macros" ("Because I can't understand them"). Some users here are notorious for making false statements on subjects that they have NO knowledge of and they won't stop spreading ignorance and trying to prevent people from learning. We should always try to help beginners who want to learn and not let the gurus give them excuses for not learning.
Post 26 Dec 2013, 11:45
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 598
Roman
Be cool do like this:
Code:
texti fruits,\ 
 ID.APPLE='Apple',AppleProc, ID.BANANA='Banana',BananaProc,\
    


And then do:
Code:
RunProc fruits,ID.APPLE
RunProc fruits,ID.BANANA
    


Or cool create parallel threads !
Code:
RunThread fruits,ID.APPLE
RunThread fruits,ID.BANANA
    
Post 13 Jan 2014, 13:26
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.

Powered by rwasa.