flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > load/store type auto-detection

Author
Thread Post new topic Reply to topic
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld
I've just got a feature in my mind which is nice to have (for me at least, and would simplify the code a bit), but I'm not sure if it's possible to implement it now to not break existing projects and whether it's needed at all by anyone else.
What I'm thinking about is to allow 'load' and 'store' directives to guess type of value being loaded/stored from the given location. So, for example, having a declaration of 'x dd ?' one'd be able to write 'store 0x12345678 at x' instead of 'store dword 0x12345678 at x'. Old rules would still apply if it's not possible to determine the type, and one would still be able to specify the type even if it's possible to determine it.
Alternatively, it could be acceptable to implement it so that no backward compatibility is affected by using a bit different syntax of 'store 0x12345678 at [x]' (same as one used in instructions, huh). This way, type casting would [also] be acceptable as part of location specification, such as 'store 0x12345678 at dword[x]'.
This should increase type safety while still allowing non-safe operations to be done. On the other hand, this changes default behavoir of defaulting to 'byte' type.
Post 31 Dec 2011, 09:03
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
This can be achieved using macros:
Code:
struc dw val
{
        . dw val
        .typeof equ word
}

struc dd val
{
        . dd val
        .typeof equ dword
}

macro store val,id
{
        store id#.typeof val at id
}


x dd 0

store 0x12345678,x

;y dw 0
;
;store 0x10000,y    
Obviously this means overriding all data constructs and the load/store and I'm not sure how this affects other macros such as proc and struct but hopefully this doesn't affect anything.
Post 31 Dec 2011, 11:34
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1398
Location: Toronto, Canada
AsmGuru62
If something declared as DD -- it is already a DWORD, so no need for the override, the following works with no macros:
Code:
x dd ?
...
mov [x], 0x12345678
    

What am I missing?
Post 31 Dec 2011, 12:32
View user's profile Send private message Send e-mail Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
store is a compile time operation (and may be performed inside a virtual) but mov is a runtime operation.
Post 31 Dec 2011, 12:41
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 © 1999-2019, Tomasz Grysztar.

Powered by rwasa.