flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Displaying constant values |
Author |
|
bitRAKE 18 Sep 2021, 15:02
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
18 Sep 2021, 15:02 |
|
rCX 18 Sep 2021, 23:18
That would work if I only want to display a value. What about the following situation? Is there a way to reliably use the ` operator to convert a processor value to a string? For example when using the following code...
Code: macro dbNum num { db `num,0 } ; Case 1 dbNum 123 ; Case 2 y = 123 dbNum y ; Case 3 z equ 123 dbNum z Case 1 assembles into to what I want but cases 2 and 3 do not Code: db "123",0 ; Case 1 db "y",0 ; Case 2 db "z",0 ; Case 2 |
|||
18 Sep 2021, 23:18 |
|
macomics 19 Sep 2021, 00:24
Code: ; Case 2 y = 123 dbNum y ; Case 3 z equ 123 dbNum z So this is how it works. In these cases, the preprocessor does not operate with constants, but with label names. So everything is correct. https://flatassembler.net/docs.php?article=manual#2.3.3 wrote: Also conversion of name(not value!) into a quoted string is possible, with the ` operator, which likewise can be used inside the macroinstruction. It converts the name that follows it into a quoted string - but note, that when it is followed by a macro argument which is being replaced with value containing more than one symbol, only the first of them will be converted, as the ` operator converts only one symbol that immediately follows it. Try it like this Code: macro dbNum directive, [Val] { if Val <> 0 Acc=Val Divider=1000000000000000000 Highest0=0 if Acc < 0 directive "-" end if repeat 19 Digit= Acc/Divider Acc= Acc mod Divider Divider= Divider/10 if Digit <> 0 Highest0= 1 end if if Highest0 = 1 directive Digit+"0" end if end repeat else directive "0" end if if directive in <db, du> directive 0 else directive 0xa end if } y=123 z equ 123 dbNum db, 123, y, z |
|||
19 Sep 2021, 00:24 |
|
Tomasz Grysztar 19 Sep 2021, 07:34
rCX wrote: Case 1 assembles into to what I want but cases 2 and 3 do not For case 3 (which uses a preprocessor-stage symbol) it is possible to extract the numeric value from variable with help of REPT: Code: z equ 123 rept 1 c:z { db `c } Code: macro dbNum num { rept 1 c:num \{ db \`c \} } But in case 2 it is not possible, because "=" definitions are evaluated at assembly stage, when the final code is being resolved, and all the preprocessing is already finished by then. (It is possible in fasmg, which combines preprocessing and assembly into a unified process - there you can use the same REPT trick for both EQU and "=" definitions.) For such cases you need assembly-times loop for number conversion, as shown by others in this thread. |
|||
19 Sep 2021, 07:34 |
|
rCX 22 Sep 2021, 02:05
OK makes sense. Thanks everyone
|
|||
22 Sep 2021, 02:05 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.