flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [sug] Underscores within numbers to improve readability

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
First an example:

Currently I am coding some register settings for hardware registers. These are simple bit-mapped registers.
Code:
...
    dq      1000100100111000100011100011001000001100100001000101011010001011b       ;register 0
 dq      0111011001101000110101101101100111010010010011011111011011000000b       ;register 1
...    


Now it is nicer to read and understand if we do this:
Code:
...
       dq      10001001_00111000_10001110_00110010_00001100_10000100_01010110_10001011b        ;register 0
 dq      01110110_01101000_11010110_11011001_11010010_01001101_11110110_11000000b        ;register 1
...    


But it can equally apply to any number radix:
Code:
...
       dq      0x8938_8E32_0C84_568B   ;register 0
 dq      0x7668_D6D9_D24D_F6C0   ;register 1
...    


And it can equally apply to any arbitrary position:
Code:
...
 dq      0x89_388E3_20C8_4568B   ;register 0
 dq      0x76_68D6D_9D24DF6_C0   ;register 1
...    


Essentially the underscore is just ignored if it appears within a number allowing the programmer to use it to enhance readability and also to show some sort of logical separation to improve comprehension.

There are a few IDEs/compilers for non-x86 systems that already allow this type of format for numbers. And in many circumstance is is nice to be able to separate long numbers into more readable sections without having to break it up. I think it would be good to introduce it onto the x86 world, especially now that the 64bit numbers are becoming more common.

I haven't looked into it yet, but I think a small change to the parser is all that would be needed. I wanted to throw this out there to let you all think about it and make some criticisms.
Post 02 Apr 2008, 02:29
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4241
Location: 2018
edfed
it is really a good idea.
but i'll prefer with the space.
Code:
dd 00 23 43 34h,32432h,233,label1
    

for ease of use.
only one space admitted, and of course the possibility to write numbers normally without bugs.


$ 1 000 000 baby!
or
$ 1_000_000 baby

note that on french keyboard, the _ char is not practical (8 lowcase) and the space bar is good because it's a reflex. note that numbers shall be shifted on the azerty keyboard too. then, it's not a reference.. Sad

edit: it is a very_very_very_good_idea.
but i really prefer with space chars. maybe the twice possibilities. wiull increase readability.
Code:
dq 3223_4344 4322_4334h
    

and can be at any positions too.
only one separator allowed between chars. ' ' or _


Last edited by edfed on 02 Apr 2008, 02:57; edited 1 time in total
Post 02 Apr 2008, 02:49
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: 17658
Location: In your JS exploiting you and your system
revolution
edfed wrote:
but i'll prefer with the space.
Ambiguous. Example:
Code:
push 123 456 ;<--- one push or two???    
Post 02 Apr 2008, 02:57
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4241
Location: 2018
edfed
ok, but, i never push immediates. the stack for me is only for temp saves of context. like task switch.

then, as you want. with _ i'm ok but it will be boring on french keyboard.

about multiples push and pops, i frequentlly have the reflex to make this
Code:
push eax,ebx,ecx
    

and when i compile, i meet errors.

in my own ( not the best) logic, the comma would be better to separate push and pop arguments.


Last edited by edfed on 02 Apr 2008, 03:02; edited 1 time in total
Post 02 Apr 2008, 02:59
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: 17658
Location: In your JS exploiting you and your system
revolution
edfed wrote:
... but it will be boring on french keyboard.
How many keypresses do you need on the French KB?
Post 02 Apr 2008, 03:01
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4241
Location: 2018
edfed
if i enter a number, then, i shall press the shift key.
and for each _ chars, i'll release the shift.

it's a loss of comfort. that's all.
Post 02 Apr 2008, 03:04
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: 17658
Location: In your JS exploiting you and your system
revolution
For the English KB it is the opposite. Numbers are unshifted and the underscore is shifted minus (-).
Post 02 Apr 2008, 03:07
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4241
Location: 2018
edfed
so, then, it will be the same comfort problem for everybody...
[offtopic] maybe we need to change radically the keyboard layouts???
Post 02 Apr 2008, 03:09
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3032
Location: vpcmipstrm
bitRAKE
RotAsm has this feature.

_________________
¯\(°_o)/¯ unlicense.org
Post 02 Apr 2008, 04:09
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: 17658
Location: In your JS exploiting you and your system
revolution
edfed wrote:
only one separator allowed between chars.
I originally thought this was best also, but now I think it is not necessary.

Example:
Code:
 dq 01110110_01101000__11010110_11011001___11010010_01001101__11110110_11000000b    
looks kinda nice.
Post 02 Apr 2008, 12:20
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
This is an awesome idea I had several years ago and rejected it for some reason I don't remember right now.

Tomasz, are your development tools all restored by now? do you think you can manage to add this feature to fasm expression parser?

btw. do you actually still have the overview of your own code when you change something in fasm? Rolling Eyes hopefully, you merged all expression calculations into a single file a while ago, or else you would have to change the code in even more places.

revolution wrote:

Example:
Code:
 dq 01110110_01101000__11010110_11011001___11010010_01001101__11110110_11000000b    

looks kinda nice.

to me, this looks like an inch subdivision.

_________________
MCD - the inevitable return of the Mad Computer Doggy

-||__/
.|+-~
.|| ||
Post 02 Apr 2008, 12:42
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
edfed: idea with space is *bad*, it makes it impossible for FASM's tokenizer to tell two number from one.

I think HLA also has this, and |)rHyde uses it a lot Wink
Post 02 Apr 2008, 13:13
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4241
Location: 2018
edfed
yes, i'm sorry.

me too in my command line i have space to separate numbers.

but it was just to debate. and fix some ideas.
for the multiple separators, yeah. it makes a great sense and give to numbers an interresting syntax.
Post 02 Apr 2008, 13:45
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
.

revolution wrote:

Code:
dq      1000100100111000100011100011001000001100100001000101011010001011b      
    


I prefer apostrophes:

Code:
dq      1000'1001'0011'1000'1000'1110'0011'0010'0000'1100'1000'0100'0101'0110'1000'1011b      
    


edfed wrote:

Quote:

if i enter a number, then, i shall press the shift key.
and for each _ chars, i'll release the shift.
it's a loss of comfort. that's all.


NO. The main problem is that your KBD is messed up. It's incredible how someone can type if you must press SHIFT for numbers, or even worse use the ALT-blah hack for brackets, blackslash etc. Sad
Post 03 Apr 2008, 00:28
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4241
Location: 2018
edfed
i totally agree. i seek an explanation to azerty. and finally, i don't find any as well as for qwerty..
keyboard would be much simpler with abcde. but in the old ages of type machines, this great and wonderfull industrial revolution, some theoricians emit the layout, probably they argue with some freud theory... but as a result, informatics seems to be an obscure science to when you see the keyboard for the first time.

i tryed to change it's layout to abcde, and i didn't find it harder to type.

the letters are in places where your hand don't need to travel a lot.

if only my endglish wasn't so poor, i could explain more preciselly what i have in mind...

OK for 0000'0000'0000'0000h
but one extra can be added then, " and '
this will be good.

but i think " and ' will be usefull later for an other purpose, like time and angles definitions.
Post 03 Apr 2008, 00:53
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: 17658
Location: In your JS exploiting you and your system
revolution
edfed wrote:
but i think " and ' will be usefull later for an other purpose, like time and angles definitions.
... and strings.
Post 03 Apr 2008, 02:08
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4241
Location: 2018
edfed
no, for strings, these symbols are only at the start and the end.
then, you seems to be tired revolution... i'm not used to see this kind of posts from you, look:
Code:
db 'string'
dq 9543'3232'FFFF'098Ah
    

then, you see it don't have concequences on the parsing.

exactlly as the &, < and > chars can be defined alone without the need of special definition in a good html parser.

then, for time and angle definitions:

Code:
dd 12"56'21s ; s like time in seconds
; and maybe
dd 32"12'4r   ; r like andle in radians???
    
Post 03 Apr 2008, 02:15
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: 17658
Location: In your JS exploiting you and your system
revolution
We need to leave the quotes as quotes only, for error checking. In a macro we might use # the try to join a string to a number by mistake.
Post 03 Apr 2008, 02:44
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4241
Location: 2018
edfed
ok. then, if i want this feature, i just have to emancipate and write my own assembler. but i cannot now, i'm not so good.

then, as you're more aware of the totality of the fasm core, you are more able to decide what will be the correct form, then, _ i'm still ok.

but one detail: quoted strings can be indifferentlly enclosed by " or '. then, it can be
Code:
"'" or '"'    
depending on what is the content of the string. it don't create problems anymore.
Post 03 Apr 2008, 03:08
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
edfed wrote:
depending on what is the content of the string. it don't create problems anymore.


But you can also do this (borrowed from TASM):

Code:
msg db 'Hello, ain''t life grand?$'
    


P.S. Octasm and Ada (EDIT: and NASM!) allow underscores, IIRC.


Last edited by rugxulo on 14 Apr 2008, 23:26; edited 1 time in total
Post 03 Apr 2008, 20:27
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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 © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.