flat assembler
Message board for the users of flat assembler.
Index
> Main > [fasmg] Issues when creating new CALM instruction |
Author |
|
Tomasz Grysztar 24 Aug 2022, 21:34
The testing logic doesn't seem to be in the right place - by defining "isreg" this way you get it executed at the time when "testing" instruction is defined.
When you produce a line from inside such instruction, this line becomes part of the body of a compiled instruction (in this case, of the body of "testing"). You produce a line "arrange @TMP, somarg", and this line is then compiled as a part of "testing" instruction body, followed by "check 0" or "check 1". But all the other logic, including MATCH, is executed during the compilation of "testing", and therefore only once. It might have looked like it worked, but you only check the value of a global @TMP once - at the time when "testing" is defined and "isreg" is called. Every time the "testing" is used, it re-defines @TMP by executing the "arrange" command in its compiled body, but this no longer has any effect on the result of the check (because the "check 0" or "check 1" is also already compiled). I assume your intention was to execute the logic of "isreg" every time "testing" is executed - to do that, you should use CALL: Code: @TMP = 0 calminstruction @isreg arg* local tmp, i match a?[b], arg jno _checkregs ; Memory location jump _exit _checkregs: compute i, 0 _regloop: compute i, i + 1 check i > elementsof arg jyes _exit compute tmp, i metadataof arg check tmp relativeto x86.r64 | tmp relativeto x86.r32 | tmp relativeto x86.r16 | tmp relativeto x86.r8 jno _regloop compute @TMP, 1 exit jump _regloop _exit: compute @TMP, 0 end calminstruction calminstruction testing? somearg* call @isreg, somearg check @TMP jyes _yep asmcmd =display "No", 13 exit _yep: asmcmd =display "Yes", 13 end calminstruction Code: macro calminstruction?.isreg? var* call @isreg, var check @TMP end macro calminstruction testing? somearg* isreg somearg jyes _yep asmcmd =display "No", 13 exit _yep: asmcmd =display "Yes", 13 end calminstruction |
|||
24 Aug 2022, 21:34 |
|
Calanor 24 Aug 2022, 21:59
Yes, when I played around with the code a bit after posting this, I realised that I get different results depending on from where in the code I'm calling "testing".
It seems like there are some gaps in my understanding of how fasmg is handling things like this, so I am really grateful for your explanations. I'm not sure what you mean by "encapsulated symbol" though? A local of some sort? |
|||
24 Aug 2022, 21:59 |
|
bitRAKE 24 Aug 2022, 23:12
This is the technique I've used in the past, there might be a better way.
(As I'm still trying to get comfortable with the semantics.) Code: include 'cpu\x64.inc' include 'xcalm.inc' calminstruction @isreg arg*,@TMP* local tmp, i match a?[b], arg jno _checkregs ; Memory location jump _exit _checkregs: compute i, 0 _regloop: compute i, i + 1 check i > elementsof arg jyes _exit compute tmp, i metadataof arg check tmp relativeto x86.r64 | tmp relativeto x86.r32 | tmp relativeto x86.r16 | tmp relativeto x86.r8 jno _regloop compute tmp, 1 publish @TMP, tmp exit _exit: compute tmp, 0 publish @TMP, tmp end calminstruction macro calminstruction?.isreg? var* local TMP0,TMP1 initsym TMP1,TMP0 call @isreg, var, TMP1 check TMP0 end macro calminstruction testing? somearg* isreg somearg jyes _yep asm display 10,9,"No" exit _yep: asm display 10,9,"Yes" end calminstruction _Label: testing rax testing dword [rax] testing _Label _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
24 Aug 2022, 23:12 |
|
Tomasz Grysztar 25 Aug 2022, 08:21
You can make it access the hidden variable directly, to avoid having to evaluate symbolic link at run-time:
Code: define @TMP calminstruction @isreg arg* local tmp, i, result initsym @TMP, result match a?[b], arg jno _checkregs ; Memory location jump _exit _checkregs: compute i, 0 _regloop: compute i, i + 1 check i > elementsof arg jyes _exit compute tmp, i metadataof arg check tmp relativeto x86.r64 | tmp relativeto x86.r32 | tmp relativeto x86.r16 | tmp relativeto x86.r8 jno _regloop compute result, 1 exit jump _regloop _exit: compute result, 0 end calminstruction match result, @TMP macro calminstruction?.isreg? var* call @isreg, var check result end macro end match |
|||
25 Aug 2022, 08:21 |
|
Calanor 25 Aug 2022, 19:01
Thanks for the suggestions, guys!
|
|||
25 Aug 2022, 19:01 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.