flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > Enhancement proposal: string size prefix in db |
Author |
|
comrade 29 Mar 2013, 08:57
Have you tried this:
Code: db mystring.length - mystring mystring db "FASM is great!!!",0 label mystring.length (don't know if this actually assembles, might be syntactic errors). Basically you define a label at the beginning of the string, and another label at the end of the string. Then you put a db (which will get backfilled) that contains a byte value with a difference between the two labels. In the above example, the beginning label is "mystring" and the end label is "mystring.length". |
|||
29 Mar 2013, 08:57 |
|
DOS386 29 Mar 2013, 09:05
comrade wrote: Have you tried this Sure there are ways to get the length (usable for data >= 256 Byte's), but for my 1000's of short strings (<256 Byte's), I'd prefer a built-in method not polluting and bloating the source too much. |
|||
29 Mar 2013, 09:05 |
|
baldr 29 Mar 2013, 09:22
DOS386,
Here you go: macro for generate fixed string. Quite confusing thread title, though. Preprocessor is a memory-hungry bitch, and macros can irreversibly damage your brain. |
|||
29 Mar 2013, 09:22 |
|
DOS386 29 Mar 2013, 10:04
> Here you go: macro for generate fixed string
> http://board.flatassembler.net/topic.php?t=15147 Code: struc pstring [text*] { common . db .size-1, text .size = $-. } aa2 pstring "abcd",$FF,0,0,"G" aa3 pstring 0,0,0 aa4 pstring $FF ; aa5: pstring $FF ; pstring $FF Thanks ... works ... partially only ... only one string per line, and, even worse, it needs a unique label without doubledot at every single line |
|||
29 Mar 2013, 10:04 |
|
l_inc 29 Mar 2013, 13:03
DOS386
You could use a generalized macro for resolving such situations: Code: ;Allows using structures as macros (i.e. a structure will be unnamed) ;usage: defStrucsAsMacros POINT,LINE ; POINT ; LINE <1,2>,<1,4> macro defStrucsAsMacros [name*] { forward macro name [arg] \{ \common \local ..lbl ..lbl name arg \} } defStrucsAsMacros pstring After this you can use pstring without the unique label requirement. And placing multiple statements on the same line is possible with another simple macro: Code: ;Allows positioning of several instructions on (at) one line ;usage: @1l <CALL FF>,<ADD EAX,T01>,<MOV ECX,S11>,<MOV EBX,M01>,<CALL CP> macro @1l [i] { forward i } _________________ Faith is a superposition of knowledge and fallacy |
|||
29 Mar 2013, 13:03 |
|
l_inc 29 Mar 2013, 13:11
baldr wrote: Preprocessor is a memory-hungry bitch I can't disagree on this. Current memory management even discourages from cleaning up after oneself, as using restore/restruc/purge makes preprocessor consume even more memory rather than releasing it. _________________ Faith is a superposition of knowledge and fallacy |
|||
29 Mar 2013, 13:11 |
|
HaHaAnonymous 29 Mar 2013, 13:29
[ Post removed by author. ]
Last edited by HaHaAnonymous on 28 Feb 2015, 21:14; edited 1 time in total |
|||
29 Mar 2013, 13:29 |
|
DOS386 29 Mar 2013, 13:50
> You could use a generalized macro for resolving such situations
> And placing multiple statements on the same line is possible with another Interesting, so how to use those 2 ? How close can I approach the bottommost code in topmost post? |
|||
29 Mar 2013, 13:50 |
|
l_inc 29 Mar 2013, 14:21
DOS386
Quote: How close can I approach the bottommost code in topmost post? You can approach your syntax as close as you want. I provided a couple of macros from my library, that allow to overcome the problems you've mentioned, but the syntax is a little bit different. Quote: Interesting, so how to use those 2 ? I'm not sure, I understand what you find unclear. The description and usage examples I provided seem to be pretty comprehensive. _________________ Faith is a superposition of knowledge and fallacy |
|||
29 Mar 2013, 14:21 |
|
DOS386 29 Mar 2013, 15:06
Code: org $10 struc pstring [text*] { common . db .size-1, text .size = $-. } macro DSAM [name*] { forward macro name [arg] \{ \common \local ..lbl ..lbl name arg \} } DSAM pstring macro @1l [i] { forward i } bugger: pstring "abcd",$FF,0,0,"G" pstring 0,0,0 @1l < aa4: pstring $FF > , < pstring $EE,$AA > db bugger ; $10 db aa4 ; $1D YES it does work ... upper macro drops the label requirement, lower allows a hacky way to put multiple strings on 1 line :-# |
|||
29 Mar 2013, 15:06 |
|
baldr 31 Mar 2013, 18:49
DOS386,
Perhaps this way is less hacky: Code: struc pstring [text*] { common . db .size-1, text .size = $-. } macro pstrings [arg*] { forward ? equ ? match name:value, arg \{ restore ? ? equ ! name pstring value \} match =?, ? \{ \local ..name ..name pstring arg \} restore ? } pstrings a:"Hello, world!", <b:"Goodbye, world!", 13, 10>, <"That's all folks!", 13, 10> |
|||
31 Mar 2013, 18:49 |
|
DOS386 10 Apr 2013, 13:29
PString example is out: http://board.flatassembler.net/topic.php?t=10872
http://board.flatassembler.net/download.php?id=4673 (macro's NOT used yet ...) Still, I'd prefer a built-in solution from macros, and maybe another layer: Code: db %c db %s,"FASM is (almost) great !!!" db %s,"ROS-ASM is not great !!!" db %s,"MASM is ???" db %d "%c" would count the elements (here 3) until next "%c" (generating next count or "%d" (generating nothing). http://queue.acm.org/detail.cfm?id=2010365 |
|||
10 Apr 2013, 13:29 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.