flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > How in macro convert text to int or float number ? Goto page 1, 2 Next |
Author |
|
Roman 16 Apr 2023, 14:38
Fasmw 1.73
Code: macro fltDat {} fltDat "5.55" ;convert text to dd 5.55 flt1 equ '4.5430' fltDat flt1 ;convert text to dd 4.5430 |
|||
16 Apr 2023, 14:38 |
|
revolution 16 Apr 2023, 15:37
Third step not needed.
Fourth step (now the new third step): Code: include 'temp.fasm' |
|||
16 Apr 2023, 15:37 |
|
revolution 16 Apr 2023, 15:39
macomics wrote: Forth Sometimes I wonder if Roman is writing a fully-fledged HLL compiler with fasm macros. |
|||
16 Apr 2023, 15:39 |
|
Roman 16 Apr 2023, 15:58
Quote:
This variant I do and using now. But I want do simple convert in fasm macro. Sometime its handful. |
|||
16 Apr 2023, 15:58 |
|
macomics 16 Apr 2023, 16:07
revolution wrote: Third step not needed. |
|||
16 Apr 2023, 16:07 |
|
Roman 16 Apr 2023, 16:30
Idea little trick.
macro fltDat search text in Tabflts. Code: Virtual at 0 Tabflts:: Txt db "5.55" dd 5.55 db "4.5430" dd 4.5430 end virtual ;or this Virtual at 0 Tabflts:: Txt db "5.55" db "4.5430" end virtual Virtual at 0 Flts:: dd 5.55 dd 4.5430 end virtual |
|||
16 Apr 2023, 16:30 |
|
Tomasz Grysztar 16 Apr 2023, 17:13
Well, if you are that desperate, you could try something like this:
Code: macro fltDat str* { local buffer, next define buffer f rept 8 i:1 \{ rept 1 c: str shr ((8-i)*8) and 0FFh - 48 \\{ match f, buffer \\\{ define next 0 match -=48, c \\\\{ define next 1 \\\\} match -=2, c \\\\{ define buffer .\\\#f define next 1 \\\\} match =0, next \\\\{ define buffer c\\\#f \\\\} \\\} \\} \} dd buffer } fltDat "5.55" flt1 equ '4.5430' fltDat flt1 |
|||
16 Apr 2023, 17:13 |
|
Roman 16 Apr 2023, 17:23
Thanks.
Cool macro. |
|||
16 Apr 2023, 17:23 |
|
macomics 16 Apr 2023, 17:29
Tomasz Grysztar wrote: Well, if you are that desperate, you could try something like this: Code: macro fltDat str* { local buffer, next define buffer f rept 8 i:1 \{ rept 1 c: str shr ((8-i)*8) and 0FFh - 48 \\{ match f, buffer \\\{ define next 0 match -=48, c \\\\{ define next 1 \\\\} match -=2, c \\\\{ define buffer .\\\#f define next 1 \\\\} match =0, next \\\\{ define buffer c\\\#f \\\\} \\\} \\} \} dd buffer } fltDat "5.50000500000" flt1 equ '4.54300000000000001' fltDat flt1 Code: fasm -m 1024 ./temp.asm ./temp.fasm flat assembler version 1.73.30 (1024 kilobytes memory) ./temp.asm [16]: fltDat "5.50000500000" ./temp.asm [5] fltDat [4]: rept 1 c: str shr ((8-i)*8) and 0FFh - 48 \\{ ./temp.asm [5] rept [1]: rept 1 c: str shr ((8-i)*8) and 0FFh - 48 \\{ error: value out of range. |
|||
16 Apr 2023, 17:29 |
|
Tomasz Grysztar 16 Apr 2023, 17:34
The limitations of fasm's engine are obvious, but this doesn't matter anyway, because this macro is useless for any practical purpose. It can only handle literals that available at preprocessing time.
|
|||
16 Apr 2023, 17:34 |
|
revolution 16 Apr 2023, 17:37
Next we need a triple precision module to handle strings up to 24 characters.
Code: fltDat "3.141592635389793238e-245" ; 25 characters! It won't fit into triple precision. |
|||
16 Apr 2023, 17:37 |
|
Roman 16 Apr 2023, 17:58
For me normal 3.1415926 accuracy 7 digits
"-1.0" wrong value macro fltDat Last edited by Roman on 16 Apr 2023, 18:06; edited 2 times in total |
|||
16 Apr 2023, 17:58 |
|
revolution 16 Apr 2023, 18:05
Roman wrote: For me normal 3.1415926 accuracy 7 digits |
|||
16 Apr 2023, 18:05 |
|
Roman 16 Apr 2023, 18:07
Ok 3.141592 for me
|
|||
16 Apr 2023, 18:07 |
|
Tomasz Grysztar 16 Apr 2023, 18:15
Roman wrote: "-1.0" wrong value macro fltDat Code: match -=3, c \\\\{ define buffer -f define next 1 \\\\} |
|||
16 Apr 2023, 18:15 |
|
revolution 16 Apr 2023, 18:17
Code: 1e6 And Code: 1E6 Code: 1.2f Code: 1.61F |
|||
16 Apr 2023, 18:17 |
|
Tomasz Grysztar 16 Apr 2023, 18:21
I'm waiting for something else.
|
|||
16 Apr 2023, 18:21 |
|
revolution 16 Apr 2023, 18:23
We need arithmetic also.
Code: 3.2*1.8-2.1/7.8**-0.1+sqrt(7.02) |
|||
16 Apr 2023, 18:23 |
|
Tomasz Grysztar 16 Apr 2023, 18:24
The macro does exactly what was asked for. But I'm pretty sure that's mostly useless.
|
|||
16 Apr 2023, 18:24 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.