flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
donn 11 Jul 2018, 05:50
Nevermind, this was addressed here:
https://board.flatassembler.net/topic.php?p=195977 Not sure if this applies yet, but will read through it. |
|||
![]() |
|
ProMiNick 11 Jul 2018, 07:09
Code: macro bins vals& { irps val,vals \{ match a,val\#b \\{ ;if a>$FFFFFFFFFFFFFFFFFFFF ; display "fasm supports 129bit",13,10 ; display "for internaly calcs,",13,10 ; display "but not for data definition",13,10 ; ddq a ;.err ; but ddq a same as .err ,no ddq in fasm1 ;else if a>$FFFFFFFFFFFFFFFF ; even more if a >$FFFFFFFFFFFFFFFF compilation will crash in comparison moment display "definition dt present,",13,10 ; so these wil never be shown display "but not operate binary,",13,10 dt a ;.err ; but dt a same as .err, where a is not in float numeric format else if a>$FFFFFFFF dq a else if a>$FFFF dd a else if a>$FF dw a else db a end if \\} \} } Code: mov r8, [rax] bins \ 10000000_0000_0000_0000_00000000_0000_0000_0000_0000_0000_0000_0000_0000_0000 1 cmp r8, rax Is this helps? for hexes: Code: macro $ vals& { irps val,vals \{ match a,$\#val \\{ ;if a>$FFFFFFFFFFFFFFFFFFFF ; display "fasm supports 129bit",13,10 ; display "for internaly calcs,",13,10 ; display "but not for data definition",13,10 ; ddq a ;.err ; but ddq a same as .err ,no ddq in fasm1 ;else if a>$FFFFFFFFFFFFFFFF display "definition dt present,",13,10 display "but not operate binary,",13,10 dt a ;.err ; but dt a same as .err else if a>$FFFFFFFF dq a else if a>$FFFF dd a else if a>$FF dw a else db a end if \\} \} } Code: $ 5a 4d that one $ macro I liked myself (it looks organicaly in code and not crashing my eyes like bins does) |
|||
![]() |
|
donn 11 Jul 2018, 17:30
Cool, that's perfect!
fasm 1.71.39 was showing Code:
Error: reserved word used as symbol
on the _ but space worked fine. fasm 1.73.04 had no error with _. I like the $ and multiline support with \ Code: mov r8, [rax] $ \ 10111111 01111111 \ 01000000 11100000 cmp r8, rax |
|||
![]() |
|
donn 27 Dec 2021, 18:48
Followup questions...
1. Converting to fasmg 2. Stripping dq and commas , from data definitions: i.e. changing: Code: dq var2Addr,3951,var3Addr,22 to: Code: var2Addr 3951 var3Addr 22 and have them mean the same. I tried converting to fasmg and can assemble now. Trying to figure out how to edit it to use the above 2 requirements, not the binary or hex requirements for time being: Code: macro $ vals& iterate val, vals match a,val ;if a>$FFFFFFFFFFFFFFFFFFFF ; display "fasm supports 129bit",13,10 ; display "for internaly calcs,",13,10 ; display "but not for data definition",13,10 ; ddq a ;.err ; but ddq a same as .err ,no ddq in fasm1 ;else dq a end match end iterate end macro But getting assemble errors when using like this: Code: section '.data' data readable writeable align 16 someVals: $ \ 3 4 898 var2Addr 43 Code: flat assembler version g.izxz $ \ 3 4 898 var2Addr macro $ [9] dq [13] qword [1] (CALM) Error: invalid expression. So, I think the macro takes in the vals, then iterates them, then matches them (no longer matching binary or hex numbers), and on each token, defines it with dq. Or, in theory, think that's what I'm trying to get macro to do. Summarizing informally speaking: I have a lot of dq definitions that contain addresses like var2Addr and literal number values, separated by commas. Trying to just remove the need to keep typing the commas and precede block by dq since I have so many of these definitions and it's making it cluttered. I can live with it, but just curious if can be optimized. I'll stick with base 10 numbers for now, understand how to remove the b binary suffix and hex from prior examples. Is this possible? Can I remove dq and the commas, when some tokens are address labels, or does this only work with literal values? Also, how does the macro stop executing when it's multiline with \? When there's a blank line? Is this controllable, like is there set amount of whitespace that can end a block so whitespace can be used to organize the data visually? Lot of questions! Interesting how was looking through docs and was able to get macro to assemble with fasmg, the docs are really holding up, macros just not my forte yet, focusing on using core x86 currently with a Vulkan project. Take care..! |
|||
![]() |
|
Tomasz Grysztar 27 Dec 2021, 19:30
With fasmg this is easier than with fasm 1, because you can use interceptor macros to parse complete lines:
Code: macro $ macro ?! line& match , line ; upon seeing empty line purge ? ; stop intercepting else local buffer define buffer line while 1 match item= tail, buffer dq item define buffer tail else dq buffer ; just one item left break end match end while end match end macro end macro someVals: $ 3 4 898 var2Addr 43 var2Addr = 400000h Another example, this time using CALM for the line processing, and a special syntax to stop intercepting: Code: struc dqs label . : qword calminstruction ?! line& match /=dqs, line jyes purge loop: local item match item line?, line jno done arrange item, =dq item assemble item jump loop purge: arrange line, =purge =? assemble line done: end calminstruction end struc someVals dqs 3 4 898 43 /dqs |
|||
![]() |
|
Overclick 27 Dec 2021, 20:56
It is too easy for fasm_1.
Tomasz, why do you still pushing fasm_g for that trivial? )) Code: irps bin, \ 10111000 10111000 10111000 10111000 { db bin#b } |
|||
![]() |
|
donn 27 Dec 2021, 21:06
So awesome. I commented some lines to enhance my understanding, required 3 lines to terminate the macro processing, and ran a test to verify the first couple values. Test includes printing the address of one token as well as its value:
Code: macro $ blankLinesReached = 0 macro ?! line& ; ? and ! are special characters, similar example to multiline comment example in doc match , line ; upon seeing empty line if blankLinesReached < 2 blankLinesReached = blankLinesReached + 1 else blankLinesReached = 0 purge ? ; stop intercepting end if else blankLinesReached = 0 local buffer define buffer line ; Start buffer as incoming line while 1 match item= tail, buffer ; "item= tail" matches an item and everything after it which goes in the buffer. buffer is updated each iteration. = matches tokens literally, like "," separators dq item define buffer tail else dq buffer ; just one item left break end match end while end match end macro end macro Code: someVals: $ 3 4 898 vkPipelineShaderStageCreateInfoRef.sType 43 49 331 213 Some output from test: Code: 898 ; someVals + 16 140701382084288 ; someVals + 24 18 ; Value from address at someVals + 24 43 ; someVals + 32 49 ; someVals + 40 Very very useful. calm version and more to learn next.. |
|||
![]() |
|
Overclick 27 Dec 2021, 21:11
You can adopt my "Multisection" superior macro to do all things you need after named directive like ".binary"
|
|||
![]() |
|
Overclick 27 Dec 2021, 21:13
Ok, I'm out of this fasmG secta ))
|
|||
![]() |
|
Tomasz Grysztar 27 Dec 2021, 21:50
donn wrote: Very very useful. calm version and more to learn next.. Code: struc dqs label . : qword calminstruction ? line& match /=dqs, line jyes purge loop: local item match item= line, line jno last arrange item, =dq item assemble item jump loop last: arrange item, =dq line assemble item exit purge: arrange line, =purge =? assemble line end calminstruction end struc someVals dqs 3 4 898 43 /dqs Code: someVals dqs 3 4 if some_condition 898 end if 43 /dqs |
|||
![]() |
|
donn 28 Dec 2021, 04:45
I was mapping out how this calminstruction could handle X amount of blanklines to stop processing:
Code: struc dqs label . : qword calminstruction ? line& ; blankLinesCount = 0 match /=dqs, line jyes blanklineReached loop: local item match item= line, line jno last arrange item, =dq item assemble item jump loop last: arrange item, =dq line assemble item exit blanklineReached: ; if blankLinesCount < 2 ; blankLinesCount = blankLinesCount + 1 ; exit ; end if ; fallthrough to purge otherwise purge: ; blankLinesCount = 0 ; reset count for next time we run the calminstruction on a block from scratch arrange line, =purge =? assemble line end calminstruction end struc but then just realized you can end the processing with /dqs so that's already done. Again, interesting..! Still some terms to understand, but this or the macro version really reduces clutter. Yeah, advanced macros not always needed, but they allow fine-tuning that save tons of space over time, and change the game. Saving too much space is a problem too though, if you've ever worked with Matlab or GLSL, you may see that it's hard to understand how efficient the computations are. Then at a lower-level, with things like SPIR-V, there are all of these repetitive tokens. Sometimes, there's a middle ground. Good stuff, opens doors. |
|||
![]() |
|
Tomasz Grysztar 28 Dec 2021, 21:49
If you're still interested in modifying the CALM variant to allow terminating the definition with just empty lines, I finished your attempt:
Code: struc dq$ label . : qword local blankLinesCount blankLinesCount = 0 calminstruction ?! line& match , line jyes blanklineReached compute blankLinesCount, 0 loop: local item match item= line, line, () jno last arrange item, =dq item assemble item jump loop last: arrange item, =dq line assemble item exit blanklineReached: check blankLinesCount < 2 jno purge compute blankLinesCount, blankLinesCount + 1 exit purge: arrange line, =purge ? assemble line end calminstruction end struc someVals dq$ 3 4 898 (1 shl 40) 43 |
|||
![]() |
|
donn 20 Jan 2022, 06:02
I'll definitely follow-up on the calm version, but it will take me some time. I'm deep in using the pre-calm version and experimenting with some other techniques heavily. equ is my new secret weapon. It can replace definitions and offsets in a more shorthand version
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.