flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
Jin X 12 Feb 2021, 17:41
Or vice versa make -1.5e-2 must do the same (replace minus by underscore when defining label).
|
|||
![]() |
|
revolution 13 Feb 2021, 00:25
The usual method for naming constants is to describe their meaning, not their value.
Code: pi = 3.1415927 ; good v3.1415927 = 3.1415927 ; useless and redundant exchange_rate = 2.84510 ; good v2.84510 = 2.84510 ; useless, no idea what it means 1) Labels can only be constructed at the preprocessor stage. 2) Strings can only be scanned at the assembler stage. 3) Preprocessor runs before the assembler. So you can't scan a string using the assembler, and then later use the preprocessor to crate the label. |
|||
![]() |
|
revolution 13 Feb 2021, 07:17
Seeing as the minus is one of the "special" characters, and if you limit your replacement to only special characters, then you can use the preprocessor to construct a new label name.
Something like this:: Code: macro def_scan { macro scan out, in \{ local has_minus has_minus equ n match o =, =- b, out, in \\{ out equ o\\#_ def_scan scan out, b has_minus equ y \\} match o =, a =- b =, =n, out, in, has_minus \\{ out equ o\\#a\\#_ def_scan scan out, b has_minus equ y \\} match o =, =n, out, has_minus \\{ out equ o\\#in \\} \} }def_scan macro build_value [number] { forward local build_label build_label equ v ; labels can't start with a digit scan build_label, number match lbl, build_label \{ lbl equ number \} } build_value 100e-2, 10e-1, -1.0, -10e-1, 0.1e1, -0.1e1, 1.0 dd v100e_2, v10e_1, v_1.0, v_10e_1, v0.1e1, v_0.1e1, v1.0 |
|||
![]() |
|
DimonSoft 13 Feb 2021, 07:43
It might make. Sometimes having an FP constant instead of constructing it (simple things like 1.0, 2.0, 0.5, etc. are obviously constructible) makes machine code smaller and source code more readable. But this has the disadvantage of having to define lots of labelled memory operands. And if you have two or three of them having the same value, merging them into a single memory location is a good thing to do.
You’re right that having meaningless value-based names in the source is a bad thing, but for such cases it might be a way to go. And wrapping the generation of such stuff into macros is a good way to make it valid from code quality point of view: noone really cares about names in automatically generated code. After all, in HLL you would just have floating-point literals in such places which are basically magic numbers but are quite valid for some formulas. |
|||
![]() |
|
Jin X 13 Feb 2021, 09:47
I need to define labels that will be used primarily by another macro.
Like this: Code: calc 4 3 / pi * r dup dup * * * ; ... def r, ? def 4 def 3 def pi, 3.14159265359 So there's no need to assign special names in many cases. Is there a need to give special name for 3 or 4 ? I think, no. If the 2nd argument for def is absent then it assumed equal to the 1st. So def 4 creates smth like fp_4 dd 4; def r, ? creates fp_r dd ?. I thought about using underscore instead of minus because minus can't be a part of name. To use def _1.5e_2 to shorten def _1.5e_2, -1.5e-2. But now I understand that it's not so good idea because realization is too bulky and underscore looks not so cool... |
|||
![]() |
|
Jin X 13 Feb 2021, 14:00
But I could use dash instead of hyphen, e.g. def –1.5e–2 (visually almost the same as hyphen)
![]() Is there no way to replace dash by hyphen (minus)? |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.