flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
baldr
Bob++,
By fixed you've meant Turbo Pascal-style string (i.e. db length, "literal")? There are several ways, one of them is to use store directive: Code: struc pstring [literal=255 dup 0] { common . db 0, literal store $-.-1 at . } aa pstring "aa" ; yields aa db 2, "aa" bbb pstring "bbb" ; yields bbb db 3, "bbb" |
|||
![]() |
|
Bob++
Yes,Turbo Pascal-style string. I will test it. @baldr, Thank you so much
![]() |
|||
![]() |
|
revolution
Rather than using store a local label can be used also.
Code: struc pstring [text] { common local .length . db .length,text .length = $-.-1 } |
|||
![]() |
|
baldr
Even local directive is not necessary, given that struc-macro label should be unique, and using standard processing of symbols starting with dot (within struc-macro body):
Code: struc pstring [text*] { common . db .size-1, text .size = $-. } |
|||
![]() |
|
revolution
And if you want to point directly to the string and have the length at an offset of -1:
Code: struc pstring [text*] { common db .size . db text .size = $-. } Edited out the subtraction of 1 as suggested below Last edited by revolution on 22 Feb 2013, 16:06; edited 1 time in total |
|||
![]() |
|
l_inc
revolution wrote:
I'd avoid subtracting 1 in this case. |
|||
![]() |
|
revolution
l_inc wrote:
|
|||
![]() |
|
baldr
It can be generalized, too:
Code: struc counted [def*] { common local element_size, count match directive value, def \{ virtual at 0 directive ? element_size = $ end virtual . directive count, value count = ($-.)/element_size-1 \} } pstring fix counted db pwstring fix counted du ![]() OTOH, one can write struc utf32 macro and use pdwstring fix counted utf32. |
|||
![]() |
|
l_inc
baldr
Quote: Though not too much — only db/du accept string literals. I sometimes generalize for db/display . But it doesn't make much sense here. Btw. generalizing definition of count is a little strange. More consistent would be using same type for the count across all specializations of your generalization. ![]() Quote: one can write struc utf32 macro and use pdwstring fix counted utf32 I'm not sure about how many would agree with me, but my simple rule is that "fixing is bad. Never fix unless it's unavoidable". Thus I'd rewrite the example like this: Code: struc pstring [args] { common . counted db args } |
|||
![]() |
|
Bob++
Thanks very much for the all answers.
![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.