flat assembler
Message board for the users of flat assembler.
Index
> Windows > Create your own data type |
Author |
|
Furs 13 Feb 2018, 13:27
No there's no way to create a "data type". However, with a macro, you could probably generate the string and check it for "invalid characters", that's not a data type though.
|
|||
13 Feb 2018, 13:27 |
|
ProMiNick 13 Feb 2018, 13:39
If thou need only data definition:
Code: macro ucaseA [val] { common match ,val \{ error \} match any,val \{ virtual at 0 db val repeat $ load a byte from $-% if a>90 error end if if a<65 error end if end virtual db val } struc ucaseA [val] { common match ,val \{ error \} match any,val \{ . db val repeat $ load a byte from .+% if a>90 error end if if a<65 error end if } Thou should override each instruction with macro that thou want affect thour type: Code: macro mov dest, src { match type val,src \{ match =ucaseA,type \\{ virtual at 0 db val repeat $ load a byte from $-% if a>90 error end if if a<65 error end if end virtual mov dest,val ?s equ \\} \} match =?s,?s \{ mov dest, src \} } I not guarantee that above code work - it is only ideas. However, in fasm natively supported only untyped sizing of operands. All the rest throw the macros. |
|||
13 Feb 2018, 13:39 |
|
Mino 15 Feb 2018, 14:41
Thank you for the answer:)
But I confess that I don't quite understand how to use these macros. If that's not too much to ask, could you give me an example? _________________ The best way to predict the future is to invent it. |
|||
15 Feb 2018, 14:41 |
|
ProMiNick 17 Feb 2018, 23:33
All types are illusion that helps stupid programmer to correctly interpret data, (next line makes this stupid things in fasm ON)
Code: ;typesON equ 1 ;but w/o that line code stayed usable for rest of community Code: macro enumns name,size,[values] { common local n,lst,?s n=0 name#.list equ forward match a==b,values \{ name#.list equ name#.list,a n=b a=b ?s equ \} match =?s, ?s \{ name#.list equ name#.list,values values=n \} n=n+1 restore ?s common match =typesON,typesON \{ name equ size ?s equ \} match =?s, ?s \{ macro name [defs] \\{ ;\\forward match a,<name#.list \\\{ if ~defs in a> error end if \\\} \\common size defs \\} struc name [defs] \\{ \\common match =db,size \\\{ label .:byte \\\} match =dw,size \\\{ label .:word \\\} match =dd,size \\\{ label .:dword \\\} match =dq,size \\\{ label .:dqword \\\} name defs \\} \} } macro enum name,[values] { common local ?s match n:s,name \{enumns n,s,values ?s equ \} match =?s, ?s \{ enumns name,dd,values ?s equ \} } ; use all above - define our type enum weekday:db,monday, tuesday, wednesday, thursday, friday, saturday, sunday ;define data of our type Myday weekday monday Myday2 weekday 1 ; if typesON will be defined here compilation will stop (monday & 1 binary identical, but 1 is out of type weekday) that way you can protect data defenitions for unsigned only or signed only values, for only integer, only float, or only string values (or even with chars in lowercase or uppercase only). But all of this will be only illusion that not make affect on output code. |
|||
17 Feb 2018, 23:33 |
|
ProMiNick 17 Feb 2018, 23:52
Code: typesON equ 1 macro ucaseA [val] { common local ?s match =typesON,typesON \{ ?s equ \} match =?s, ?s \{ match ,val \\{ error \\} match any,val \\{ virtual at 0 db val repeat $ load a byte from $-% if a>90 error end if if a<65 error end if end repeat end virtual \\} \} db val } struc ucaseA [val] { common label .:byte ucaseA val } A db "hello world!!!!" ; use macros as usual data definitions your type in place of data definition directive B ucaseA "HERE ALL UCASE" C ucaseA "But here is not" |
|||
17 Feb 2018, 23:52 |
|
DimonSoft 18 Feb 2018, 09:05
Let me ask the topicstarter what his real problem is. The right solution to it might be in the opposite direction, and then there’s not much point in putting hundreds of lines of task-specific macros into the code.
Are you trying to implement something like Pascal/Delphi subrange types? |
|||
18 Feb 2018, 09:05 |
|
Mino 18 Feb 2018, 09:28
Thank you for your answers
Yes, if we want, I would like to try to implement custom types from the axioms. But I never programmed in Delphi or Pascal, so maybe I misunderstood. _________________ The best way to predict the future is to invent it. |
|||
18 Feb 2018, 09:28 |
|
DimonSoft 18 Feb 2018, 11:00
Mino wrote: I would like to try to implement custom types from the axioms. But I never programmed in Delphi or Pascal, so maybe I misunderstood. Pascal/Delphi have subrange types which are defined as follows: Code: type TLatinLetter = 'A'..'Z'; THeadCount = 1..160; // Or even better TMonth = (mnJan, mnFeb, mnMar, ..., mnDec); TSummerMonth = mnJun..mnAug; Implementing such stuff in assembly might be ineffective. In HLL compiler would do all the checks necessary. What you can do in assembly is just create a few macros to ensure you define valid data (you already have to check it yourself, so don’t gain much here). How would you prevent something like this? Code: mov eax, 'Ў' mov [YourTypeVariable], eax Except, maybe, redefining every instruction as a macro. And injecting more and more checks into such a macro for every custom type you define. |
|||
18 Feb 2018, 11:00 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.