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 > On my new assembler

Goto page Previous  1, 2, 3, 4, 5, 6, 7, 8  Next
Author
Thread Post new topic Reply to topic
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6179
Location: Kraków, Poland
I have made the fasm g available to download from the fasm's official page. I have not decided on my further plans for this project, but still think that even in this basic form it can be useful for some applications so I decided make it more visible this way.


shutdownall wrote:
As I did implement the Z80 instructions and I think revolution (?) for the ARM processor and you for the main x86 target, wouldn't it be helpful to have an (more or less) easy to use assembly engine which can be adapted to nearly any new processor or microcontroller with minimal work ? So only some basic definitions - if there are instructions to complex they can be generated with the all purpose macro language as well.

This is a good idea and it is very compatible with some of my intentions behind fasm g engine - I had thought about creating some kind of "assembler construction kit" that would allow to easily create a dedicated assembler for specific instruction set based on fasmg. I think I learned from the problems that fasm 1 with its unfinished "guide to internals" had in this area and I hope with fasm g it would go better. Perhaps I should make this part my priority.
Post 13 Jun 2015, 18:28
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: 14469
Location: ?                               Posts: 6699
Just for an exercise in testing the arbitrary precision of fasmg we can test Mersenne numbers for primality.

Code:
;test Mersenne numbers for primality.

macro display_decimal value
        local digitdivisornumber
        number = value
        if number < 0
                number = -number
                display '-'
        end if
        divisor = 10
        while divisor < number
                divisor = divisor * 10
        end while
        divisor = divisor / 10
        while divisor > 0
                digit = number / divisor
                display digit + '0'
                number = number - digit * divisor
                divisor = divisor / 10
        end while
end macro

macro is_small_prime result,value
        result = 1
        j = 3
        while result & j * j <= (value)
                result = (valuemod j
                j = j + 2
        end while
end macro

;Lucas-Lehmer test for exponents from 3 to 1279

p = 3
while p <= 1279
        is_small_prime r,p
        if r
                s = 4
                M = 1 shl p - 1
                repeat p - 2
                        s = (s * s - 2mod M
                end repeat
                display '2^'
                if s = 0
                        display_decimal p
                        display '-1 is prime',13,10
                        display 'M = '
                        display_decimal M
                        display 13,10
                else
                        display_decimal p
                        display '-1 is not prime',13,10
                end if
        end if
        p = p + 2
end while

The output looks like this:

Code:
2^3-1 is prime
M = 7
2^5-1 is prime
M = 31
2^7-1 is prime
M = 127
2^11-1 is not prime
2^13-1 is prime
M = 8191
2^17-1 is prime
M = 131071
2^19-1 is prime
M = 524287
2^23-1 is not prime
2^29-1 is not prime
2^31-1 is prime
M = 2147483647
2^37-1 is not prime
2^41-1 is not prime
2^43-1 is not prime
2^47-1 is not prime
2^53-1 is not prime
2^59-1 is not prime
2^61-1 is prime
M = 2305843009213693951
2^67-1 is not prime
2^71-1 is not prime
2^73-1 is not prime
2^79-1 is not prime
2^83-1 is not prime
2^89-1 is prime
M = 618970019642690137449562111
2^97-1 is not prime
2^101-1 is not prime
2^103-1 is not prime
2^107-1 is prime
M = 162259276829213363391578010288127
2^109-1 is not prime
2^113-1 is not prime
2^127-1 is prime
M = 170141183460469231731687303715884105727
2^131-1 is not prime
2^137-1 is not prime
2^139-1 is not prime
2^149-1 is not prime
2^151-1 is not prime
2^157-1 is not prime
2^163-1 is not prime
2^167-1 is not prime
2^173-1 is not prime
2^179-1 is not prime
2^181-1 is not prime
2^191-1 is not prime
2^193-1 is not prime
2^197-1 is not prime
2^199-1 is not prime
2^211-1 is not prime
2^223-1 is not prime
2^227-1 is not prime
2^229-1 is not prime
2^233-1 is not prime
2^239-1 is not prime
2^241-1 is not prime
2^251-1 is not prime
2^257-1 is not prime
2^263-1 is not prime
2^269-1 is not prime
2^271-1 is not prime
2^277-1 is not prime
2^281-1 is not prime
2^283-1 is not prime
2^293-1 is not prime
2^307-1 is not prime
2^311-1 is not prime
2^313-1 is not prime
2^317-1 is not prime
2^331-1 is not prime
2^337-1 is not prime
2^347-1 is not prime
2^349-1 is not prime
2^353-1 is not prime
2^359-1 is not prime
2^367-1 is not prime
2^373-1 is not prime
2^379-1 is not prime
2^383-1 is not prime
2^389-1 is not prime
2^397-1 is not prime
2^401-1 is not prime
2^409-1 is not prime
2^419-1 is not prime
2^421-1 is not prime
2^431-1 is not prime
2^433-1 is not prime
2^439-1 is not prime
2^443-1 is not prime
2^449-1 is not prime
2^457-1 is not prime
2^461-1 is not prime
2^463-1 is not prime
2^467-1 is not prime
2^479-1 is not prime
2^487-1 is not prime
2^491-1 is not prime
2^499-1 is not prime
2^503-1 is not prime
2^509-1 is not prime
2^521-1 is prime
M = 686479766013060971498190079908139321726943530014330540939446345918554318339765605212255964066145
4554977296311391480858037121987999716643812574028291115057151
2^523-1 is not prime
2^541-1 is not prime
2^547-1 is not prime
2^557-1 is not prime
2^563-1 is not prime
2^569-1 is not prime
2^571-1 is not prime
2^577-1 is not prime
2^587-1 is not prime
2^593-1 is not prime
2^599-1 is not prime
2^601-1 is not prime
2^607-1 is prime
M = 531137992816767098689588206552468627329593117727031923199444138200403559860852242739162502265229
285668889329486246501015346579337652707239409519978766587351943831270835393219031728127
2^613-1 is not prime
2^617-1 is not prime
2^619-1 is not prime
2^631-1 is not prime
2^641-1 is not prime
2^643-1 is not prime
2^647-1 is not prime
2^653-1 is not prime
2^659-1 is not prime
2^661-1 is not prime
2^673-1 is not prime
2^677-1 is not prime
2^683-1 is not prime
2^691-1 is not prime
2^701-1 is not prime
2^709-1 is not prime
2^719-1 is not prime
2^727-1 is not prime
2^733-1 is not prime
2^739-1 is not prime
2^743-1 is not prime
2^751-1 is not prime
2^757-1 is not prime
2^761-1 is not prime
2^769-1 is not prime
2^773-1 is not prime
2^787-1 is not prime
2^797-1 is not prime
2^809-1 is not prime
2^811-1 is not prime
2^821-1 is not prime
2^823-1 is not prime
2^827-1 is not prime
2^829-1 is not prime
2^839-1 is not prime
2^853-1 is not prime
2^857-1 is not prime
2^859-1 is not prime
2^863-1 is not prime
2^877-1 is not prime
2^881-1 is not prime
2^883-1 is not prime
2^887-1 is not prime
2^907-1 is not prime
2^911-1 is not prime
2^919-1 is not prime
2^929-1 is not prime
2^937-1 is not prime
2^941-1 is not prime
2^947-1 is not prime
2^953-1 is not prime
2^967-1 is not prime
2^971-1 is not prime
2^977-1 is not prime
2^983-1 is not prime
2^991-1 is not prime
2^997-1 is not prime
2^1009-1 is not prime
2^1013-1 is not prime
2^1019-1 is not prime
2^1021-1 is not prime
2^1031-1 is not prime
2^1033-1 is not prime
2^1039-1 is not prime
2^1049-1 is not prime
2^1051-1 is not prime
2^1061-1 is not prime
2^1063-1 is not prime
2^1069-1 is not prime
2^1087-1 is not prime
2^1091-1 is not prime
2^1093-1 is not prime
2^1097-1 is not prime
2^1103-1 is not prime
2^1109-1 is not prime
2^1117-1 is not prime
2^1123-1 is not prime
2^1129-1 is not prime
2^1151-1 is not prime
2^1153-1 is not prime
2^1163-1 is not prime
2^1171-1 is not prime
2^1181-1 is not prime
2^1187-1 is not prime
2^1193-1 is not prime
2^1201-1 is not prime
2^1213-1 is not prime
2^1217-1 is not prime
2^1223-1 is not prime
2^1229-1 is not prime
2^1231-1 is not prime
2^1237-1 is not prime
2^1249-1 is not prime
2^1259-1 is not prime
2^1277-1 is not prime
2^1279-1 is prime
M = 104079321946643990819252403273640855386152622472667048053191123504036080596733602980122394417323
2418484242161395428100779138356624832346490813990660567732076292412950938922034577318334966158355047
2959420547689811211693677147548478866962501384438260291732348885311160828538416585028255604666224831
890918801847068222203140521026698435488732958028878050869736186900714720710555703168729087

Post 18 Jun 2015, 03:32
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


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

JohnFound wrote:
That is why I asked. Wink It is great, because if there is an existing repository, regardless of your decision in this very moment, there is always a hope it will be published later. Smile

I have also uploaded a copy of my repository to this website, so if you want to take a look at it, you can download it from here.


Last edited by Tomasz Grysztar on 06 Mar 2017, 19:02; edited 1 time in total
Post 27 Jun 2015, 13: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: 14469
Location: ?                               Posts: 6699

Tomasz Grysztar wrote:
I have also uploaded a copy of my repository to this website, so if you want to take a look at it, you can download it from here.

Make sure to select "Save link as ..." or equivalent in one's browser.

Tomasz: Do you intend to keep this up-to-date each time there is a new version?
Post 27 Jun 2015, 14:05
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


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

revolution wrote:
Tomasz: Do you intend to keep this up-to-date each time there is a new version?

I think I'm going to update it every time I upload the new fasmg.zip package (I'm doing it now). Not after every single commit, though. Even though the new commits are really very rare now.

Nevertheless, I also started working on AVR macros and I am progressing nicely, they may become another interesting example for the basic package.
Post 04 Jul 2015, 16:24
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6179
Location: Kraków, Poland
I updated the files today, with the AVR example added. This time I really felt that implementing (at least initially) the instruction set through macros has some advantages - I could easily experiment with various syntax options before deciding which one I prefer and I like the flexibility I had this way.
Post 08 Jul 2015, 17:41
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1558
Location: Ukraine
some CPU have address space 64kB - is there a way to check if code or data do not go beyond top memory limit? some MCU may have ROM size even smaller than possible address space - it would be nice to set custom limit of memory top also. i'm not sure if it is better to do with macro or with another way, which could be more efficient

+++++++++++++++++++++++++++++++++++++++

after posting i've guessed by myself Smile
a macro placed at the end of program may check if memory limit is not violated:

Code:
macro ENDM? top
    if $>top
        err "out of memory limit"
    end if
end macro


_________________
UNICODE forever!
Post 14 Jul 2015, 21:31
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 510
Location: Munich

shoorick wrote:
some CPU have address space 64kB - is there a way to check if code or data do not go beyond top memory limit? some MCU may have ROM size even smaller than possible address space - it would be nice to set custom limit of memory top also. i'm not sure if it is better to do with macro or with another way, which could be more efficient



I use extensively the statement ASSERT in my programs which can check several conditions. For example if some memory limit is respected:


Code:

assert ($-MEMST)<MEMAVL




or check some labels for program areas which have to be fixed like interrupt routines:


Code:

rst_30:
        db      0
        align   8;

assert rst_38 = $38           // assure begin of int routine at $38

rst_38:
        DEC     C               // scanline counter
        JP      NZ,.next
        POP     HL              // next row
        DEC     B
        RET     Z               // return when last row
        SET     3,C             // next row8 scanlines again




or the length of some drivers with critical size


Code:

assert ZXM_chdisplay.end-ZXM_chdisplay = DRVALIGN




Asserts are quite useful for several purposes and a good addition to alignments which may jump/move to wrong locations when codesize increases.
Post 15 Jul 2015, 16:43
View user's profile Send private message Send e-mail Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1558
Location: Ukraine
thanks for the clue, i missed this nice statement!
Post 15 Jul 2015, 16:53
View user's profile Send private message Visit poster's website Reply with quote
dunkaist



Joined: 31 Jul 2015
Posts: 11
There is a bug in current fasmg (0.90.1436376581):
(not 0) results in 0.

I use (-x-1) so far.
Post 31 Jul 2015, 20:34
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6179
Location: Kraków, Poland
Thank you for reporting it, I'm uploading the fixed version. I've been thinking that getting no bug reports means that there is very little interest in this project, so it is nice to hear that there is someone trying it out.
Post 31 Jul 2015, 21:54
View user's profile Send private message Visit poster's website Reply with quote
dunkaist



Joined: 31 Jul 2015
Posts: 11
Thank you, Tomasz, it does work.

Actually, I am not implementing any instruction set right now. That is really hard work and requires deep architecture knowledge. Imho, that is the reason you do not get much response.

I have been using fasm for some years, but never knew its preprocessor language. So I decided to read fasmg manual and implement sha3 hash as a macro.
It outputs computed hash to screen via 'display' and to file via 'store'.


Code:
$ tail -n 4 sha3.asm 
sha3 'hello, fasmg!'224
sha3 'hello, fasmg!'256
sha3 'hello, fasmg!'384
sha3 'hello, fasmg!'512

$ fasmg sha3.asm sha
flat assembler g  version 0.90.1438379288
sha3-22420d0318c56fe180570fb3f712941a02d007bd4fef264fcf1bcee4900
sha3-256847188b6f8015c04d351e9b9d9a0fab472113ca71e465754879bdbb6459ce55f
sha3-3840556986e638a2fec5d40723469bb48b9259f84f0f6462249fdc74b733c296f1173a00e09eb8263ad728bbd37ec8a5755
sha3-5127d5516543ef57aecfa88aeb74d22e43c2f6964d5850c5e05ae4f10ca1ae403b97d5e36d2f627af76d192a670b312b22c2e89b6befa5484c801d827b372601a8c

2 passes0.2 seconds172 bytes.

$ for bit_len in 224 256 384 512; do echo -n "sha3-$bit_len: "; echo -n 'hello, fasmg!' | rhash --simple --sha3-$bit_len -; done
sha3-22420d0318c56fe180570fb3f712941a02d007bd4fef264fcf1bcee4900  (stdin)
sha3-256847188b6f8015c04d351e9b9d9a0fab472113ca71e465754879bdbb6459ce55f  (stdin)
sha3-3840556986e638a2fec5d40723469bb48b9259f84f0f6462249fdc74b733c296f1173a00e09eb8263ad728bbd37ec8a5755  (stdin)
sha3-5127d5516543ef57aecfa88aeb74d22e43c2f6964d5850c5e05ae4f10ca1ae403b97d5e36d2f627af76d192a670b312b22c2e89b6befa5484c801d827b372601a8c  (stdin)

$ hexdump sha -C
00000000  20 d0 31 8c 56 fe 18 05  70 fb 3f 71 29 41 a0 2d  | .1.V...p.?q)A.-|
00000010  00 7b d4 fe f2 64 fc f1  bc ee 49 00 84 71 88 b6  |.{...d....I..q..|
00000020  f8 01 5c 04 d3 51 e9 b9  d9 a0 fa b4 72 11 3c a7  |..\..Q......r.<.|
00000030  1e 46 57 54 87 9b db b6  45 9c e5 5f 05 56 98 6e  |.FWT....E.._.V.n|
00000040  63 8a 2f ec 5d 40 72 34  69 bb 48 b9 25 9f 84 f0  |c./.]@r4i.H.%...|
00000050  f6 46 22 49 fd c7 4b 73  3c 29 6f 11 73 a0 0e 09  |.F"I..Ks<)o.s...|
00000060  eb 82 63 ad 72 8b bd 37  ec 8a 57 55 7d 55 16 54  |..c.r..7..WU}U.T|
00000070  3e f5 7a ec fa 88 ae b7  4d 22 e4 3c 2f 69 64 d5  |>.z.....M".</id.|
00000080  85 0c 5e 05 ae 4f 10 ca  1a e4 03 b9 7d 5e 36 d2  |..^..O......}^6.|
00000090  f6 27 af 76 d1 92 a6 70  b3 12 b2 2c 2e 89 b6 be  |.'.v...p...,....|
000000a0  fa 54 84 c8 01 d8 27 b3  72 60 1a 8c              |.T....'.r`..|
000000ac




Questions are all the same: is this behavior intentional and, if so, how can I rewrite my code shorter?
1.

Code:
irp x3,1,2
    s#x = 0
end irp

This doesn't work (as I expected) and assigns to sx. I have to write as follows.

Code:
irp x3,1,2
    rereat 1i:x
        s#i = 0
    end repeat
end irp



2.

Code:
repeat 7
    s#(% mod 5) = 0
end repeat

Such arithmetic doesn't work without 'repeat 1, i:%' either.

3.
Also, is there any way to declare arrays without declaring data?


Description:
Download
Filename: sha3.asm
Filesize: 5.33 KB
Downloaded: 17 Time(s)

Post 01 Aug 2015, 16:23
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


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

dunkaist wrote:
1.

Code:
irp x3,1,2
    s#x = 0
end irp

This doesn't work (as I expected) and assigns to sx.

It should not assign to sx. The following source demonstrates that it does in fact assign to s1, s2 and s3:

Code:
irp x3,1,2
    s#x = `x
end irp

display 's1 is ',s1,'.',13,10
display 's2 is ',s2,'.',13,10
display 's3 is ',s3,'.',13,10

Please show more of the context, perhaps the problem is caused by some specific usage.


dunkaist wrote:
2.

Code:
repeat 7
    s#(% mod 5) = 0
end repeat

Such arithmetic doesn't work without 'repeat 1, i:%' either.

The # operator is interpreted when recognizing identifiers, so before any expression evaluation happens. Only the replacement of parameters happens before #. The "repeat 1" trick is in fact inherited from fasm 1 (where it was preprocessor's "rept 1").


dunkaist wrote:
3.
Also, is there any way to declare arrays without declaring data?

You can use data reservation directives like "rb" in the labeled "virtual" block, and then access the array with "load" and "store". All the "virtual", "rb", "load", "store", etc. features work very much like in fasm 1.
Post 01 Aug 2015, 19:05
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6179
Location: Kraków, Poland
For an example of assembly-time arrays you can look at the assembly-time LZW compression sample I made once for fasm 1. You need to change curly braces to "end macro" syntax and then it works the same with fasm g.

PS When testing that source I noticed a bug that caused crash when file included with FILE directive was not found. I have uploaded the correction.
Post 01 Aug 2015, 19:14
View user's profile Send private message Visit poster's website Reply with quote
dunkaist



Joined: 31 Jul 2015
Posts: 11

Quote:
It should not assign to sx. The following source demonstrates that it does in fact assign to s1, s2 and s3:

Hm, you are right. I didn't save that old code to show now, so perhaps it was my fault.


Quote:
You can use data reservation directives like "rb" in the labeled "virtual" block, and then access the array with "load" and "store". All the "virtual", "rb", "load", "store", etc. features work very much like in fasm 1.

I meant an array of preprocessor variables. Now I write this way.

Code:
repeat 25i:0
    local A#i
    A#i = 0
end repeat

The code does what I need except these are 25 separate variables. I understand that fasmg doesn't intend to fight general purpose programming languages, but may be I missed something and it is possible to define all the variables like A[25].

UPD

Quote:
assembly-time LZW compression sample I made once for fasm 1

Seems like just what I need, thank you!
Post 01 Aug 2015, 19:40
View user's profile Send private message Reply with quote
dunkaist



Joined: 31 Jul 2015
Posts: 11
If you are interested in segmentation faults, I have two for you:

Code:
$ fasmg / x
flat assembler g  version 0.90.1438456944
Errorerror reading file.
Segmentation fault (core dumped)

$ fasmg /dev/stdin x
flat assembler g  version 0.90.1438456944
Errorerror reading file.
Segmentation fault (core dumped)



UPD:

Code:
file '/dev/stdin'

Post 01 Aug 2015, 19:54
View user's profile Send private message Reply with quote
gens



Joined: 18 Feb 2013
Posts: 159

dunkaist wrote:
If you are interested in segmentation faults, I have two for you:

Code:
$ fasmg / x
flat assembler g  version 0.90.1438456944
Errorerror reading file.
Segmentation fault (core dumped)

$ fasmg /dev/stdin x
flat assembler g  version 0.90.1438456944
Errorerror reading file.
Segmentation fault (core dumped)



UPD:

Code:
file '/dev/stdin'




/dev/stdin is a character device
/ is a directory
Post 01 Aug 2015, 21:00
View user's profile Send private message Reply with quote
dunkaist



Joined: 31 Jul 2015
Posts: 11

gens wrote:
/dev/stdin is a character device
/ is a directory

So what? I don't insist these are valid files to include, however segfault is not proper error handling. Consider my previous post as pointers to further improve fasmg.
Post 01 Aug 2015, 21:28
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1558
Location: Ukraine
is there any plan to process INCLUDE environment variable?
Post 19 Aug 2015, 08:22
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


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

shoorick wrote:
is there any plan to process INCLUDE environment variable?

Yes, I planned to implement it. I should be able to add it quickly.
Post 23 Aug 2015, 11:39
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 Previous  1, 2, 3, 4, 5, 6, 7, 8  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.