flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > how to separate strings and pointers

Author
Thread Post new topic Reply to topic
qeos



Joined: 15 Jan 2008
Posts: 15
qeos
Documentation is an example of a table of addresses to strings:
Code:
    macro strtbl name,[string]
     {
      common
        label name dword
      forward
        local label
        dd label
      forward
        label db string,0
     }    


But when adding a few data, they mixed the pointers and lines. Like:

Code:
<ptr1><str1><ptr2><str2>...<ptrN><strN>
    


How to separate the lines and pointers of the data? How do I make that would get data in the form of:

Code:
<ptr1><ptr2>...<ptrN><str1><str2>...<strN>
    
Post 01 Jun 2010, 19:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17622
Location: In your JS exploiting you and your system
revolution
Code:
strtbl Table1,\
    'String1',\
    'String2',\
    'String3',\
    'String4'    
Post 01 Jun 2010, 19:54
View user's profile Send private message Visit poster's website Reply with quote
qeos



Joined: 15 Jan 2008
Posts: 15
qeos
2revolution this is no what I need

I wrote this:
Code:
.dvars equ
.dstrs equ db 0

macro cdata name, [string]{
 local z
     .dvars equ .dvars,name dd z
 .dstrs equ .dstrs,z db string
}

macro ddata{
    match names,.dvars \{
         irp inames,names \\{
                 inames
              \\}
  \}
    match names,.dstrs \{
         irp inames,names \\{
                 inames, 0
           \\}
  \}
}


cdata data01, 'str1'
cdata data02, 'str2'

rb 0x100-$
DataS:
ddata
    


It's a bit ugly, but it works

Thanks to Tomasz Grysztar for his programm. They show preprocessed datas as:
Quote:
data01 dd z?0000000
data02 dd z?0000001

db 0,0
z?0000000 db 'str1',0
z?0000001 db 'str2',0
Post 01 Jun 2010, 20:17
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

2revolution this is no what I need

It is worth mentioning however that the macro you extracted from the documentation puts the data as you requested in your first post and not as you reported how it works.

From your new code I assume you want to provide a symbol for each pointer? In that case you could use this:
Code:
    macro strtbl name, [label,string]
     {
      forward
        dd label
      forward
        label db string,0
     }    


Usage example:
Code:
strtbl DataS,\
alpha, 'alpha',\
someName, 'delta'    
Post 01 Jun 2010, 21:35
View user's profile Send private message Reply with quote
qeos



Joined: 15 Jan 2008
Posts: 15
qeos
LocoDelAssembly wrote:
It is worth mentioning however that the macro you extracted from the documentation puts the data as you requested in your first post and not as you reported how it works.

I have bad english.. sorry..

LocoDelAssembly wrote:

Usage example:
Code:
strtbl DataS,\
alpha, 'alpha',\
someName, 'delta'    

Your code puts the data in local places, and my code makes it possible to declare variables at different locations.. and then assemble all in one place ..
Post 01 Jun 2010, 21:45
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
qeos wrote:
Thanks to Tomasz Grysztar for his programm.
I've managed to compile it for current codebase.


Description: FASMPRE for 1.69.14 2010-05-10 build
Download
Filename: fasmpre.asm.rar
Filesize: 1.76 KB
Downloaded: 46 Time(s)

Post 02 Jun 2010, 07:02
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Thanks baldr Very Happy - seriously, I tried to compile it before reading your reply and failed Laughing
Post 02 Jun 2010, 09:12
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
cod3b453,

That small utility saves me several hundred times: unless Tomasz will make FASM write .fas even if assembly is failed, we have to stick with it. Due to reworked .Inc structure it contains unused code, though. Wink
Post 02 Jun 2010, 09:30
View user's profile Send private message Reply with quote
qeos



Joined: 15 Jan 2008
Posts: 15
qeos
I has new way to define strings and collect they at the end of binary. But I get new trouble with macro and I dont know how it made..

I has this macro:
Code:
.d_str_data equ
macro idata_s name, [var]{
 local pdata
 .d_str_data equ .d_str_data name db var,
}
macro ddata{
     common .d_str_data equ .d_str_data db ''
  match names,.d_str_data \{
            irp inames,names \\{
                 inames, 0
           \\}
  \}
}
    

And used code:
Code:
idata_s Strings_init_heap_0,<'Found '>
idata_s Strings_init_heap_1,<' Mb of memory', db 10, db 13>

ddata
    

and I get code (by fasmpre):
Code:
Strings_init_heap_0 db 'Found ',0
Strings_init_heap_1 db ' Mb of memory',0
db 10,0
db 13,0
db '',0
    

It is a little not that that is necessary for me, since it is necessary for me in such kind:
Code:
Strings_init_heap_0 db 'Found ',0
Strings_init_heap_1 db ' Mb of memory',10,13,0    

Whether there is any way for use of a divider a comma, but something else?
or how still it is possible to collect all line variables in one place?
Post 09 Mar 2011, 04:16
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
prefer

crlf equ 10,13
Post 09 Mar 2011, 04:34
View user's profile Send private message Visit poster's website Reply with quote
qeos



Joined: 15 Jan 2008
Posts: 15
qeos
yep! thanx, it works!
Post 09 Mar 2011, 17:34
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
but in asm, one important thing is the separation of declaration and referencing.

it is not a limitation, but a very good feature that lets you declare a lot of strings in some data section, and only reference those you need.
and more...
create a dictionary, and reference the words you need in other parts of the code.

it is some asm basics.

what can be good in this idea of referencing strings is a macro to generate an equate file, containing all references for the strings inside the compiled string file.

then, for this kind of file:

Code:
string db "string",0
hello db "hello",0
world db "world",0
assembler db "assembler",0

    


obtain a equate file like this:

Code:
string equ 0
hello equ 7
world equ 13
assembler equ 19
    

and then, be able to just reference everystrings from the dictionary that is supposed to be loaded somewhere in ram. a sort of text library, something more like the real definition of what is a library...a group of texts.
Post 09 Mar 2011, 18:19
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.