flat assembler
Message board for the users of flat assembler.

flat assembler > Programming Language Design > fasm(g) tolerate of underscore in numbers ?

Author
Thread Post new topic Reply to topic
jmg



Joined: 18 Sep 2016
Posts: 62
In various tools, it is now more common for parsers to tolerate underscore within numbers.
This makes source more readable by spacing the fields to match the contents.

eg

MOV A,#0000_1111b
MOV A,#00_11_1111b

MOV DPTR,#1_23_4H

Can that tolerate underscore within numbers feature be added to Fasm(g) ?

I see it is already smart enough to allow all 3 common HEX formats

DEC 0x55r
DEC 55H
DEC $55
Post 19 Sep 2016, 09:02
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6876
Location: Kraków, Poland
In fasm traditionally ' character was used for this purpose:
Code:
db 0000'1111b

But supporting _ as an alternative should not cause any problems, so I may as well add it.

In the meantime, just for fun I'm going to demonstrate how to preprocess source text to convert such numbers with a macro:
Code:
macro convert_token out,token& local t,a t db `token load a:byte from t if a >= '0' & a <='9' repeat $-t load a:byte from t+%-1 if a = "_" store "'":byte at t+%-1 end if end repeat end if end macro macro ? line& local buffer,command virtual at 0 define out define buffer line while 1 match car cdr, buffer convert_token out,car match car_= cdr_, buffer match =car,car_ db ' ' end match end match define buffer cdr else match car, buffer convert_token out,car break else break end match end while load command:$ from 0 end virtual eval command end macro db 0000_1111b
I originally wrote a variant of this macro for shoorick to convert octal numbers ending with "Q" to ones ending with "O", but then I added support for "Q" numbers into fasmg anyway.


Last edited by Tomasz Grysztar on 19 Sep 2016, 10:36; edited 2 times in total
Post 19 Sep 2016, 10:00
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15874
Location: 162173 Ryugu
fasm uses the single quote character (') for number separation.

fasmarm uses the more common underscore character (_) for number separation.
Post 19 Sep 2016, 10:04
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6876
Location: Kraków, Poland
revolution wrote:
fasm uses the single quote character (') for number separation.

fasmarm uses the more common underscore character (_) for number separation.
Well, I might add it into fasm, too.

Already added to fasmg.
Post 19 Sep 2016, 10:58
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15874
Location: 162173 Ryugu
Tomasz Grysztar wrote:
Well, I might add [_] into fasm, too.
Yay.
Post 19 Sep 2016, 11:01
View user's profile Send private message Visit poster's website Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62
Tomasz Grysztar wrote:

Already added to fasmg.


Great Smile

Tested this, and it also fixed an issue of not allowing > 8bit binary strings.
Now, only if the number overflows the field, does an error result = Good.

flat assembler g version 0.98.1474353977
Code:
dd (100000_0010b shl 22) dd (1111_1010_0101_0111_0110_0101_0100_0011b) ; dd (1_1111_1010_0101_0111_0110_0101_0100_0011b) ; flags, as is > 32b dq (1110_1111_1010_0101_0111_0110_0101_0100_0011_0010_0001b)
Post 19 Sep 2016, 19:57
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6876
Location: Kraków, Poland
To sum things up:l fasmg now supports three ways of separating groups of digits: with single quote, with underscore, or with hash - because "#" operator works with numbers as well as with symbol identifiers (and, unlike fasm 1, fasmg allows it anywhere, not only in lines generated by macros).

jmg wrote:
Tested this, and it also fixed an issue of not allowing > 8bit binary strings.
Now, only if the number overflows the field, does an error result = Good.
I think the problem must have been coming from elsewhere, since range checking in fasmg has not been changed recently or at any other time.
Post 21 Sep 2016, 17:21
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1904
I've been using $FFFF'FFFF for years with FASM Smile
Post 23 Sep 2016, 19:31
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 2004-2018, Tomasz Grysztar.

Powered by rwasa.