flat assembler
Message board for the users of flat assembler.
Index
> Main > Array of strings,how to implement? |
Author |
|
shutdownall 12 Feb 2013, 20:11
I wouldn't say that in your example it is an array - it's more a table.
In an array all elements have the same (maximum) size. The table created from Tomasz saves space due to a defined structure. So the first byte is the length of the following token in bytes, followed by an address of the preprocessor-directive handler. So if there is a token found and to be processed it is checked with a simple string compare and if found the handler is called. And there is some more restriction, all items have to be in alphabetical order. |
|||
12 Feb 2013, 20:11 |
|
uart777 12 Feb 2013, 21:52
Text array macros...
Code: ; TEXTS t[]='abc', 'xyz', '123' ; TEXTS t[](4)='ann', 'kim', 'sue' ; create array of literal 'text' + addresses ; example: TEXTA colors, 'Black', 'White' ; access: let ecx=[index], eax=[colors+ecx*4] macro TEXTA name, [t] { ?nta=0 common label name dword forward local l dd l ?nta=?nta+1 forward l db t, 0 name#.$=?nta } ; same but align each to size macro TEXTAA name, size, [t] { common ?nta=0 label name dword forward local l dd l ?nta=?nta+1 forward l db t, 0 times (size-($-l)) db 0 ; align common name#.$=?nta } macro TEXTS [p] { common define ?s 0 match name[](size)==t, p \{ TEXTAA name, size, t define ?s 1 \} match =0 name[]==t, ?s p \{ TEXTA name, t define ?s 1 \} if ?s eq 0 'Syntax error' end if } |
|||
12 Feb 2013, 21:52 |
|
Bob++ 13 Feb 2013, 00:57
shutdownall wrote: I wouldn't say that in your example it is an array - it's more a table. Thanks! I get it now. The Tomasz don't use pointers in anywhere really,right? ie,esp pointing to a array of integers,that are memory address as compilers(C/C++) generate? I am newbie in assembly. May be wrong. A code example is: Code: mov [ebp- 12],DWORD PTR [STR0] mov [ebp- 8], DWORD PTR [STR1] mov [ebp -4], DWORD PTR [STR2] This is not fasm compilable,is just an example. gcc compilers generate somethings like this when working with strings. STR0,STR1,STR2 are labels,like this: Code: STR0: .string "etc" in Fasm,I belive that it is equivalent to: Code: str0: db "etc" Also,why all items have to be in alphabetical order? because your search algorithm? well,how is it called really? I thought Tomasz use hash in somewhere.. Sorry for too many questions. uart777, Thank you too. Woow,the macros in fasm are very powerful. I will learn more about macros in fasm to understand you code and back here. Last edited by Bob++ on 13 Feb 2013, 01:05; edited 1 time in total |
|||
13 Feb 2013, 00:57 |
|
HaHaAnonymous 13 Feb 2013, 01:04
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:32; edited 1 time in total |
|||
13 Feb 2013, 01:04 |
|
Bob++ 13 Feb 2013, 01:05
HaHaAnonymous wrote:
Sure. Thanks. |
|||
13 Feb 2013, 01:05 |
|
shutdownall 13 Feb 2013, 01:37
Bob++ wrote:
The alphabetical order is just to use an easy search algorithm I think. Tomasz uses hash tables for dynamic symbols (labels) but not for static symbols placed in TABLES.INC. |
|||
13 Feb 2013, 01:37 |
|
edfed 13 Feb 2013, 13:58
an array of anything is just:
Code: array_of_anything: .size dd @f-$-4 ;size in bytes .elements: dd element1 dd element2 dd element3 dd element4 dd element1 ;you can point multiple times to the same element dd element4 ... @@: element1 db "this is a string",0 element2 db "this is another string",0 element4 db "this string is another element",0 element3 db 0;and this string is empty if is relativelly easy to implement the methods to exploit theses kind of lists. |
|||
13 Feb 2013, 13:58 |
|
shutdownall 13 Feb 2013, 20:42
Well it's not really on area of the data - just an array of pointers.
For me an array is something you defined in BASIC with DIM which holds real data. DIM A$(100,50) or DIM B(16) or DIM XY(10,10,10,10) a four dimensional array ... |
|||
13 Feb 2013, 20:42 |
|
revolution 14 Feb 2013, 02:30
shutdownall wrote: Well it's not really on area of the data - just an array of pointers. |
|||
14 Feb 2013, 02:30 |
|
shutdownall 14 Feb 2013, 17:27
Yes you are right but you are talking about an array of pointers which is not really an array of data. It's more a directory.
How would you define a two or three dimensional array and how can the members easily accessed ? |
|||
14 Feb 2013, 17:27 |
|
Bob++ 17 Feb 2013, 03:19
edfed wrote: an array of anything is just: Remove .size,.elements and assume this code. Is array_of_anything's address same as element1? if not,to where is the label pointing really? |
|||
17 Feb 2013, 03:19 |
|
AsmGuru62 17 Feb 2013, 12:27
@Bob++: so you need an array, which can dynamically change?
Like add some elements and remove some as needed? I would use the private heap for this - WinAPI provides Heapxxx functions for this purpose. Also the # of heaps created for a process is limited only by memory left within a process 2Gb room. |
|||
17 Feb 2013, 12:27 |
|
Bob++ 21 Feb 2013, 01:27
AsmGuru62 wrote: @Bob++: so you need an array, which can dynamically change? No,it's static.I did the question because I was thinking in a different search-algorithm. I was confusing with label address.. Thaks for your answer! |
|||
21 Feb 2013, 01:27 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.