flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Reordering structure [fasmg] |
Author |
|
Tomasz Grysztar 02 Aug 2019, 08:38
A tweet I saw today inspired me to play a little with fasmg's macros again and make a variant of its basic "struct" macro that can be used to define structures where the order of fields is not important and the assembler is then free to reorder them for a better alignment, for example:
Code: macro reordstruct? name* local A A = 1 struc (fieldname)? def define name..field fieldname define name..fieldname def if sizeof name.fieldname > 0 & bsf sizeof name.fieldname >= bsf A A = 1 shl (bsf sizeof name.fieldname) end if end struc macro ends? restruc ? purge ends? macro name.builder struc name args@struct& label . : sizeof.name end macro local F while A irpv fieldname, name..field F = sizeof name.fieldname if F = 0 F = 1 end if if F and A & F and (A-1) = 0 match def, name..fieldname macro name.builder name.builder .fieldname def end macro end match end if end irpv A = A shr 1 end while name.builder iterate definition, args@struct match name:value, definition store value at .name else match name==value, definition store value at .name else match value, definition err 'unnamed values not supported' end match end iterate end struc virtual at 0 name name sizeof.name = $ end virtual end macro end macro For example this: Code: reordstruct tester a db 1 b dd 4 c dw 2 d dq 8 e dd 4 ends Code: struct tester d dq 8 b dd 4 e dd 4 c dw 2 a db 1 ends The macro is just an experiment and perhaps does some things suboptimally. But it was an interesting idea to play with. |
|||
02 Aug 2019, 08:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.