flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > struc(t) relative offset |
Author |
|
RIxRIpt 12 Feb 2015, 18:35
Answered by @revolution
Is it possible to get offset relative to struc(t) base? Here's not working example of my idea: Code: include 'win32a.inc' macro skip_to nbyte { local b b = nbyte - $ ; I need offset inside struc(t) if b > 0 db b dup ? end if } struct myStruct skip_to 8 ;skips to byte #8 (db 8 dup ?) value1 db ? skip_to 16 ;skips to byte #16 (db 7 dup ?) value2 db ? ends s myStruct s2 myStruct db 'x' I've also tried this way, but it says 'incomplete macro.' Code: macro skip_to nbyte { local b b = nbyte - .. if b > 0 db b dup ? end if } macro class name { struc name \{ local .. ..: } macro endc { \} } class myStruct skip_to 8 ;skips to byte #8 (db 8 dup ?) .value1 db ? skip_to 16 ;skips to byte #16 (db 7 dup ?) .value2 db ? endc s myStruct s2 myStruct db 'x' _________________ Привет =3 Admins, please activate my account "RIscRIpt" Last edited by RIxRIpt on 13 Feb 2015, 11:53; edited 1 time in total |
|||
12 Feb 2015, 18:35 |
|
RIxRIpt 13 Feb 2015, 11:18
revolution wrote: Perhaps this is what you are after Yes. revolution wrote: Note that struct/ends are macros defined in win32a.inc and have a few restrictions when trying to do things like alignment. macro\struct.inc if to be more precise . I didn't read the whole macros, I just saw virtual at 0 and thought that `$` would be relative to the beginning of a struct. Is it possible to do define something like following macro? Because I wouldn't like to write `local ..strucBegin`, `..strucBegin:` each time I define a struc. Code: macro class name { struc name \{ __CLASS_BEGINNING = $ } macro endc { \} } Currently I have only one alternative idea, which I wouldn't like to use either: Code: ;define a macro which I will have to write in the beginning of each struc macro STRUC_BEGIN { __STRUC_BEGINNING = $ } macro skip_to nbyte { local b b = nbyte + __STRUC_BEGINNING - $ if b > 0 db b dup ? else if b < 0 display 'skip_to error!', 13, 10 err end if } struc myStruct { STRUC_BEGIN skip_to 8 ;skips to byte #8 (db 8 dup ?) .value1 db ? skip_to 16 ;skips to byte #16 (db 7 dup ?) .value2 db ? } _________________ Привет =3 Admins, please activate my account "RIscRIpt" |
|||
13 Feb 2015, 11:18 |
|
revolution 13 Feb 2015, 11:26
Maybe something like this:
Code: macro class name { struc name \{ local ..strucBegin class@begin equ ..strucBegin ..strucBegin: } endc fix } macro skip_to nbyte { local b b = nbyte + class@begin - $ if b > 0 db b dup ? end if } class myStruct skip_to 8 ;skips to byte #8 (db 8 dup ?) .value1 db ? skip_to 16 ;skips to byte #16 (db 7 dup ?) .value2 db ? endc s myStruct s2 myStruct db s.value1 db s.value2 db s2.value1 db s2.value2 |
|||
13 Feb 2015, 11:26 |
|
RIxRIpt 13 Feb 2015, 11:52
awesome, thank you @revolution !
|
|||
13 Feb 2015, 11:52 |
|
RIxRIpt 16 Feb 2015, 12:46
skip_to worked incorrectly when there was defined a sub-class in the class. I've found a simple fix:
Code: macro classend { restore class@beginning } endc fix classend } |
|||
16 Feb 2015, 12:46 |
|
baldr 20 Feb 2015, 19:13
RIxRIpt,
Is . (dot) not sufficient? rb .+#-$ where # is an offset into struc (implications involved). |
|||
20 Feb 2015, 19:13 |
|
RIxRIpt 20 Feb 2015, 22:02
baldr wrote: RIxRIpt, If I understood you correctly you've suggested to use . (dot) instead of class@beginning, right? Code: macro skip_to nbyte { local b b = nbyte + . - $ if b > 0 db b dup ? end if } I've got an error: undefined symbol 's..strucBegin?0.'. Or have you meant to use rb .+#-$ instead of skip_to macro? Code: class myStruct rb .+8-$ .value1 db ? rb .+16-$ .value2 db ? endc s myStruct I've also got an error: undefined symbol 's'. If you've suggested second variant, I think it's less readable. And you can't define behavior if you are trying to skip `negative` number of bytes (for example a custom error message). I'm not against simplifying the solution, but I'm happy with the current one _________________ Привет =3 Admins, please activate my account "RIscRIpt" |
|||
20 Feb 2015, 22:02 |
|
revolution 21 Feb 2015, 03:30
If you use the dot (.) then you have to define it somewhere:
Code: struc abc { .: ;<--- define the value of dot ;do other stuff here } |
|||
21 Feb 2015, 03:30 |
|
baldr 21 Feb 2015, 09:15
RIxRIpt,
Code: macro class ...& { struc ...& \{ .: } skip_to fix rb .-$+ endc fix } class myClass a, b skip_to 8 .value1 db a skip_to 16 .value2 db b endc s myClass 1, 2 s2 myClass 3, 4 db s.value1 db s.value2 db s2.value1 db s2.value2 |
|||
21 Feb 2015, 09:15 |
|
RIxRIpt 21 Feb 2015, 10:51
baldr,
Well, yes that's a bit simpler solution, thanks. But if you define a class without arguments there will be an error `invalid macro arguments`, so & should be removed for classes without arguments. By the way, I couldn't find any info about & except the change log :\ |
|||
21 Feb 2015, 10:51 |
|
baldr 21 Feb 2015, 14:58
RIxRIpt,
That was just a sketch, you may apply []+common or whatever you want. Changelog entry was sufficient, I think. Tomasz prefers terse but exhaustive definitions as I know. |
|||
21 Feb 2015, 14:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.