flat assembler
Message board for the users of flat assembler.

Index > Main > String array

Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 12 Jan 2010, 18:13
How can i do an array of strings and get each item by it index?

I tried this:
Code:
 arrayTxt db 'release',0,'doc',0,'rc',0,'src',0    

But I dont know how to get each item. (I don't know nor if its a correct array)

_________________
Sorry if bad english.
Post 12 Jan 2010, 18:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20513
Location: In your JS exploiting you and your system
revolution 12 Jan 2010, 18:16
Code:
string_ordinals dd s1,s2,s3,s4,s5,0

s1 db 'New Project',0
s2 db 'release',0
s3 db 'doc',0
s4 db 'rc',0
s5 db 'src',0    
Post 12 Jan 2010, 18:16
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 12 Jan 2010, 18:20
But I need get each item in a loop, how can I do using that?
Post 12 Jan 2010, 18:20
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 12 Jan 2010, 18:21
nvm.. i think i understand.
string_ordinals its 'dd', a pointer, right?
Post 12 Jan 2010, 18:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20513
Location: In your JS exploiting you and your system
revolution 12 Jan 2010, 18:23
Yes, an array of pointers.
Post 12 Jan 2010, 18:23
View user's profile Send private message Visit poster's website Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 12 Jan 2010, 18:30
Code:
LEN = $ - string_ordinals     

returns the array lenght?
Post 12 Jan 2010, 18:30
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 12 Jan 2010, 18:36
Teehee,

Not exactly. Depends on where you've placed it. Wink
Code:
string_pointers dd s1, s2, s3
.byte_count = $ - string_pointers
.count = .byte_count/4    
Post 12 Jan 2010, 18:36
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 12 Jan 2010, 18:41
Code:
  arrayNewProject dd tvTxtRelease,tvTxtDoc,tvTxtRc,tvTxtSrc,0

  tvTxtRelease  db 'release',0
  tvTxtDoc      db 'doc',0
  tvTxtRc       db 'rc',0
  tvTxtSrc      db 'src',0

   .bytes_count =  $-arrayNewProject
  COUNT =.bytes_count /4        

COUNT = 12 (=9 if /5)
its wrong Sad
Post 12 Jan 2010, 18:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20513
Location: In your JS exploiting you and your system
revolution 12 Jan 2010, 18:59
You put it in the wrong place!
Code:
  arrayNewProject dd tvTxtRelease,tvTxtDoc,tvTxtRc,tvTxtSrc,0

   .bytes_count =  $-arrayNewProject-4
  COUNT =.bytes_count /4    

  tvTxtRelease  db 'release',0
  tvTxtDoc      db 'doc',0
  tvTxtRc       db 'rc',0
  tvTxtSrc      db 'src',0    
Post 12 Jan 2010, 18:59
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 12 Jan 2010, 19:00
Teehee,

That's exactly what I wrote about: COUNT calculation should immediately follow arrayNewProject's definition.

I made it in two steps to emphasize that $-label is number of bytes between label and current location, and you need number of dwords, right? By the way, terminating 0 will be taken into account as well.

You may find useful to read FASM manual about local labels (those that start with dot).
Post 12 Jan 2010, 19:00
View user's profile Send private message Reply with quote
Teehee



Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 12 Jan 2010, 19:04
Wooot!
now it works Very Happy
Code:
  arrayNewProject dd tvTxtRelease,tvTxtDoc,tvTxtRc,tvTxtSrc,0
  COUNT = ($ - arrayNewProject - 4) /4

  tvTxtRelease  db 'release',0
  tvTxtDoc      db 'doc',0
  tvTxtRc       db 'rc',0
  tvTxtSrc      db 'src',0      

Thanks guys.
Post 12 Jan 2010, 19:04
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 12 Jan 2010, 20:00
*ahem* why not just scan through the string until you find the specific ID you're looking for? i,e if ID is 5, it means you skip the first 5 strings (starts from 0).

Code:
arrayTxt db 'release',0,'doc',0,'rc',0,'src',0


[...]

; ecx = ID
mov esi, arrayTxt
test ecx, ecx
jz .first

@@:
  lodsb
  test al, al
  jnz @b
dec ecx
jnz @b

.first:
; esi points at the string now    

_________________
Previously known as The_Grey_Beast
Post 12 Jan 2010, 20:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20513
Location: In your JS exploiting you and your system
revolution 12 Jan 2010, 20:06
Borsuc wrote:
*ahem* why not just scan through the string until you find the specific ID you're looking for?
I guess that would be okay for small lists of strings. But it depends upon what it is really being used for, if Teehee needs it for 1000000 strings then it could be rather slow.
Post 12 Jan 2010, 20:06
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 12 Jan 2010, 20:34
Fair enough. Alternatively for such a huge list I think building the list with the above method is better, avoids a huge executable (but putting the value of 'esi' in the current ordinal and looping again).

_________________
Previously known as The_Grey_Beast
Post 12 Jan 2010, 20:34
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 14 Jan 2010, 01:44
version by revolution have an interresting faculty.
it can be used with the algo from Borsuc.

funny!

but you can speed up searches if, for example, you do alpahbetical string lists, Alist, Blist, Clist etc...


and maybe, if seeking for command interpretation is needed, another stuff is possible...

a tree.

but it will use a lot of memory.
but it will be very fast (depend on the leng of the word to interpret.



Code:

list:
.a: dd fork,@f-$-4,.aa,.ab,.ac,.ad....; fork is a pointer that means the item is a fork.
@@:
.b: dd fork,@f-$-4,.ba,.bb,.bc,.bd,0,.bf ; 0 means there are no pointers for 'be'
@@:
...
.ad: dd fork,@f-$-4,.ada,.adb,.adc,.add...
...
.bb dd 0 ;means there are no command for this entry.

.add dd addition ;means the function for this entry is addition...
    


then, imagine, the result for edit command, or the support for commands up to 10 chars.
it is a good thing if: you have enough memory to do that.
Post 14 Jan 2010, 01:44
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.