flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Programming Language Design > Data directive with custom size

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6307
Location: Kraków, Poland
Data directive with custom size
Since the design phase I planned fasmg to have a special data directive in addition to fasm-compatible DB/DW/etc. that would allow specify a size of data unit. Let's call it DBX for now. It would be used like:

Code:
dbx 11,2,3 ; same as db 1,2,3
dbx 44,5,6 ; same as dd 4,5,6

The code is ready, adding such directive is a matter of a few minutes. The only reason why I did not enable it is because I could not decide how to name it. Though, now that I think about it, I could just use a semi-random name like above and then just add a synonym if we decide some other name is better (after all, there are already directives with synonyms, like REPT/REPEAT and IRP/ITERATE).

The other name I came up with is DLE, as "define little-endian". It is nicely describing what it does, I'd only be afraid that users would then expect DBE counterpart to be available, and that's outside of my plans. (I honestly don't know how such theoretical DBE should treat string arguments, for example. If you want it, write a macro.)

The obvious advantage of having such directive would be that it would allow to define data units with non-standard sizes. But the other reason for having it is to make overloading data directives easier.
For example, and architecture like ARM needs DH as an equivalent to fasm's DW, while DW should do the same as fasm's standard DD. If we simply defined DH and DW as macros forwarding the arguments to DW and DD, it would not work because DH would call DW macro, which would then pass it to DD. Thus a more complex variant set of macro is needed, based on a scheme like:

Code:
DATA_SIZES_ARM = 1

struc dw? data&
        if DATA_SIZES_ARM
                dd data
        else
                dw data
        end if
end struc

struc dh? data&
        DATA_SIZES_ARM =: 0
        dw data
        restore DATA_SIZES_ARM
end struc

With directive like DBX/DLE redefining standard size would be as simple as:

Code:
struc dw? data&
        dbx 4,data
end struc

struc dh? data&
        dbx 2,data
end struc

As I said, the directive has been ready to fly since the earliest releases of fasmg, all we need is a name. What do you think about the ones I used here? Or do you have a better one?
Post 19 Sep 2016, 12:33
View user's profile Send private message Visit poster's website Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 468
Location: Belarus
what about naturally aligned data types?

dbx sounds good. but what about RB? to reserve data? do you plan to add it? rbx woudn't work then
Post 19 Sep 2016, 15:00
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6307
Location: Kraków, Poland

zhak wrote:
what about naturally aligned data types?

Any more high-level concepts are to be implemented through macros. This directive is an example of a low-level tool that macros can access to provide higher level functions.


zhak wrote:
dbx sounds good. but what about RB? to reserve data? do you plan to add it? rbx woudn't work then

I don't think we need the reserving counterpart, since all that it would need to do can be summarized by this simple macro:

Code:
struc rbx? unit*,count*
        label . : unit
        rb (unit) * (count)
end struc

And even if you needed to redefine RB for some purpose, you could still access the same functionality with "DB unit*count dup ?" (or "DBX unit, count dup ?").
Post 19 Sep 2016, 15:17
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6307
Location: Kraków, Poland
I uploaded the fasmg package that has it implemented under the name DBX. I can still change the name (or add a synonym) later.
Post 19 Sep 2016, 15:29
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: 14673
Location: Origae-6
DV - Define Variable sized value(s)
Post 19 Sep 2016, 15:43
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6307
Location: Kraków, Poland

revolution wrote:
DV - Define Variable sized value(s)

Wouldn't this one be more fitting for the variant having a size declared independently for each argument?
Post 19 Sep 2016, 15:45
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: 14673
Location: Origae-6

Tomasz Grysztar wrote:

revolution wrote:
DV - Define Variable sized value(s)

Wouldn't this one be more fitting for the variant having a size declared independently for each argument?

Perhaps yes.

DX - Define random sized value(s)
Post 19 Sep 2016, 15:47
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: 14673
Location: Origae-6
DS - Define Specified size value(s)
Post 19 Sep 2016, 15:48
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: 14673
Location: Origae-6
DA - Define arbitrary size value(s)
Post 19 Sep 2016, 19: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: 14673
Location: Origae-6
Actually if/when this is implemented then perhaps all other data directives should be eliminated. Since this would be the core definition that others can be derived from.
Post 19 Sep 2016, 19:18
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: 14673
Location: Origae-6
D - Data

DATA - Data
Post 19 Sep 2016, 19:25
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: 14673
Location: Origae-6
Some more suggestions from one of my colleagues:

EMIT
OUTPUT
OUT
PUT

I'll try to stop spamming this topic now, sorry.
Post 19 Sep 2016, 20:01
View user's profile Send private message Visit poster's website Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62
Re: Data directive with custom size

Tomasz Grysztar wrote:
.... that would allow specify a size of data unit.
Let's call it DBX for now. It would be used like:
... all we need is a name. What do you think about the ones I used here? Or do you have a better one?



My main aversion to dbx would be that intel code is already a sea of x's...
I also dislike too-terse mnemonics, so 2 letters are out...

Perhaps
dbvw ? - Data Byte Variable Width
dbfw ? - Data Byte Field/Fixed Width

What else can this do ?
Currently db 1,23,"hello",00 is allowed

so, what about a variant syntax using : like

dbfw 1: 1,2,3 ; 00 01 02

dbfw 2: 1,2,3 ; 0000 0001 0002

The colon now also allows this
dbfw 3: 1,2,3, 2:0x55 ; 000000 000001 000002 0055

and even this...

dbfw 9: "StrA","StringB","22" ; right justified strings, " " packed ?
dbfw -9: "StrA","StringB","22" ; left justified strings, " " packed ?
Post 19 Sep 2016, 20:11
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6307
Location: Kraków, Poland

revolution wrote:
Actually if/when this is implemented then perhaps all other data directives should be eliminated. Since this would be the core definition that others can be derived from.

I had a similar thought, but at the same time fasmg contains predefined values like "word" and "dword" too, even though defining them is even easier. The main point here is that everything can be redefined, and some symbols are there by default just to make the environment a bit more friendly to a fasm user coming to fasmg.


jmg wrote:
My main aversion to dbx would be that intel code is already a sea of x's...
I also dislike too-terse mnemonics, so 2 letters are out...

Perhaps
dbvw ? - Data Byte Variable Width
dbfw ? - Data Byte Field/Fixed Width

What about something mentioning the endianess? DLTTLE? Wink


jmg wrote:
The colon now also allows this
dbfw 3: 1,2,3, 2:0x55 ; 000000 000001 000002 0055

In fasmg macros are your [obligatory] friend:

Code:
macro dbfw? args&
        local unit
        unit = 1
        iterate arg,args
                match size:valuearg
                        unit = size
                        dbx unit,value
                else
                        dbx unit,arg
                end match
        end iterate
end macro

dbfw 31,2,32:0x55

It is part of that "complex solutions with simple features" philosophy I declared for fasm (I even said once that I see fasmg as the ultimate embodiment of that idea).


jmg wrote:
dbfw 9: "StrA","StringB","22" ; right justified strings, " " packed ?
dbfw -9: "StrA","StringB","22" ; left justified strings, " " packed ?

I'm going to leave writing such macro as an excercise to the readers. Wink It is getting late where I'm sitting.
Post 19 Sep 2016, 20:27
View user's profile Send private message Visit poster's website Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62

Tomasz Grysztar wrote:
The main point here is that everything can be redefined, and some symbols are there by default just to make the environment a bit more friendly to a fasm user coming to fasmg.



I think it is a good idea to have "expected defaults" - ie that any ASM user would anticipate, but being able to overlay/redefine, covers all the bases...
Post 19 Sep 2016, 20:39
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2627
Location: dank orb
https://en.wikipedia.org/wiki/Word_(computer_architecture)

DWLD = data word length data, or just WLD (wild, lol) Very Happy

(I was thinking FASMG was a little too x86-centric when I was reading the manual. Even though this was the intent, it still feels odd.)
Post 19 Sep 2016, 20:41
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6307
Location: Kraków, Poland

bitRAKE wrote:
(I was thinking FASMG was a little too x86-centric when I was reading the manual. Even though this was the intent, it still feels odd.)

Yes, and this is mostly because I wanted to preserve as much of fasm as possible. When designing fasmg I also still considered that it could become a base engine for fasm 2. But now I have more fun writing macros than even thinking about fasm 2.
Post 19 Sep 2016, 20:53
View user's profile Send private message Visit poster's website Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62

Tomasz Grysztar wrote:


jmg wrote:
The colon now also allows this
dbfw 3: 1,2,3, 2:0x55 ; 000000 000001 000002 0055

In fasmg macros are your [obligatory] friend:

Code:
macro dbfw? args&
        local unit
        unit = 1
        iterate arg,args
                match size:valuearg
                        unit = size
                        dbx unit,value
                else
                        dbx unit,arg
                end match
        end iterate
end macro

dbfw 31,2,32:0x55

It is part of that "complex solutions with simple features" philosophy I declared for fasm (I even said once that I see fasmg as the ultimate embodiment of that idea).



Yes, I am new to fasmg, but what can be done with macros is frankly amazing.


I just tried the above (of course forgot I do not yet have dbx..)

No surprise it gives this

invert.asm [99] macro ? [1] macro dbfw [6]
Error: illegal instruction.

I'm guessing
[99] is source line#,
[1] is ? macro level ?,
[6] is line# inside macro dbfw,

but the following

Error: illegal instruction.

is rather terse, and could be clearer, & much easier to find if it also indicated the offending word ? - here, dbx


Last edited by jmg on 19 Sep 2016, 20:56; edited 1 time in total
Post 19 Sep 2016, 20:54
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3415
Location: Bulgaria
The name is not very important here. More important is that the suggested syntax does not distinguish between the data and the data size. In order to stay readable enough, it must separate the data size from the data values.

My suggestion is to use only "D" combined with the size of the data:

Code:
d1 1,2,3 ; same as db 1,2,3
d4 4,5,6 ; same as dd 4,5,6


Or if the single "d" is not enough, it can be "dv" from "define variable":

Code:
dv1 1,2,3 ; same as db 1,2,3
dv4 4,5,6 ; same as dd 4,5,6


Another approach is to use another separator for the size, like ":"

Code:
dbx 11,2,3 ; same as db 1,2,3
dbx 44,5,6 ; same as dd 4,5,6

Post 19 Sep 2016, 20:55
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
jmg



Joined: 18 Sep 2016
Posts: 62

JohnFound wrote:

My suggestion is to use only "D" combined with the size of the data:

Code:
d1 1,2,3 ; same as db 1,2,3
d4 4,5,6 ; same as dd 4,5,6






I thought of that, but that does not allow an equate to set the field width, which could be useful.


JohnFound wrote:

Another approach is to use another separator for the size, like ":"

Code:
dbx 11,2,3 ; same as db 1,2,3
dbx 44,5,6 ; same as dd 4,5,6




I agree that is better, (now can be equate set) and as the macro example above hints, this Size: can also now be redefined along the line too.
Post 19 Sep 2016, 20:59
View user's profile Send private message 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.