flat assembler
Message board for the users of flat assembler.
Index
> Programming Language Design > On my new assembler Goto page Previous 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Next |
Author |
|
revolution 18 Jun 2015, 03:32
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 digit, divisor, number 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 = (value) mod 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 - 2) mod 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 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 |
|||
18 Jun 2015, 03:32 |
|
Tomasz Grysztar 27 Jun 2015, 13:59
JohnFound wrote: That is why I asked. 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. Last edited by Tomasz Grysztar on 06 Mar 2017, 19:02; edited 1 time in total |
|||
27 Jun 2015, 13:59 |
|
revolution 27 Jun 2015, 14:05
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. Tomasz: Do you intend to keep this up-to-date each time there is a new version? |
|||
27 Jun 2015, 14:05 |
|
Tomasz Grysztar 04 Jul 2015, 16:24
revolution wrote: Tomasz: Do you intend to keep this up-to-date each time there is a new version? Nevertheless, I also started working on AVR macros and I am progressing nicely, they may become another interesting example for the basic package. |
|||
04 Jul 2015, 16:24 |
|
Tomasz Grysztar 08 Jul 2015, 17:41
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.
|
|||
08 Jul 2015, 17:41 |
|
shoorick 14 Jul 2015, 21:31
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 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! |
|||
14 Jul 2015, 21:31 |
|
shutdownall 15 Jul 2015, 16:43
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 row, 8 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. |
|||
15 Jul 2015, 16:43 |
|
shoorick 15 Jul 2015, 16:53
thanks for the clue, i missed this nice statement!
|
|||
15 Jul 2015, 16:53 |
|
dunkaist 31 Jul 2015, 20:34
There is a bug in current fasmg (0.90.1436376581):
(not 0) results in 0. I use (-x-1) so far. |
|||
31 Jul 2015, 20:34 |
|
Tomasz Grysztar 31 Jul 2015, 21:54
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.
|
|||
31 Jul 2015, 21:54 |
|
dunkaist 01 Aug 2015, 16:23
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-224: 20d0318c56fe180570fb3f712941a02d007bd4fef264fcf1bcee4900 sha3-256: 847188b6f8015c04d351e9b9d9a0fab472113ca71e465754879bdbb6459ce55f sha3-384: 0556986e638a2fec5d40723469bb48b9259f84f0f6462249fdc74b733c296f1173a00e09eb8263ad728bbd37ec8a5755 sha3-512: 7d5516543ef57aecfa88aeb74d22e43c2f6964d5850c5e05ae4f10ca1ae403b97d5e36d2f627af76d192a670b312b22c2e89b6befa5484c801d827b372601a8c 2 passes, 0.2 seconds, 172 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-224: 20d0318c56fe180570fb3f712941a02d007bd4fef264fcf1bcee4900 (stdin) sha3-256: 847188b6f8015c04d351e9b9d9a0fab472113ca71e465754879bdbb6459ce55f (stdin) sha3-384: 0556986e638a2fec5d40723469bb48b9259f84f0f6462249fdc74b733c296f1173a00e09eb8263ad728bbd37ec8a5755 (stdin) sha3-512: 7d5516543ef57aecfa88aeb74d22e43c2f6964d5850c5e05ae4f10ca1ae403b97d5e36d2f627af76d192a670b312b22c2e89b6befa5484c801d827b372601a8c (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 x, 3,1,2 s#x = 0 end irp Code: irp x, 3,1,2 rereat 1, i:x s#i = 0 end repeat end irp 2. Code: repeat 7 s#(% mod 5) = 0 end repeat 3. Also, is there any way to declare arrays without declaring data?
|
|||||||||||
01 Aug 2015, 16:23 |
|
Tomasz Grysztar 01 Aug 2015, 19:05
dunkaist wrote: 1. Code: irp x, 3,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 dunkaist wrote: 2. dunkaist wrote: 3. |
|||
01 Aug 2015, 19:05 |
|
Tomasz Grysztar 01 Aug 2015, 19:14
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. |
|||
01 Aug 2015, 19:14 |
|
dunkaist 01 Aug 2015, 19:40
Quote: It should not assign to sx. The following source demonstrates that it does in fact assign to s1, s2 and s3: 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. Code: repeat 25, i:0 local A#i A#i = 0 end repeat UPD Quote: assembly-time LZW compression sample I made once for fasm 1 |
|||
01 Aug 2015, 19:40 |
|
dunkaist 01 Aug 2015, 19:54
If you are interested in segmentation faults, I have two for you:
Code: $ fasmg / x flat assembler g version 0.90.1438456944 Error: error reading file. Segmentation fault (core dumped) $ fasmg /dev/stdin x flat assembler g version 0.90.1438456944 Error: error reading file. Segmentation fault (core dumped) UPD: Code: file '/dev/stdin' |
|||
01 Aug 2015, 19:54 |
|
gens 01 Aug 2015, 21:00
dunkaist wrote: If you are interested in segmentation faults, I have two for you: /dev/stdin is a character device / is a directory |
|||
01 Aug 2015, 21:00 |
|
dunkaist 01 Aug 2015, 21:28
gens wrote: /dev/stdin is a character device |
|||
01 Aug 2015, 21:28 |
|
shoorick 19 Aug 2015, 08:22
is there any plan to process INCLUDE environment variable?
|
|||
19 Aug 2015, 08:22 |
|
Tomasz Grysztar 23 Aug 2015, 11:39
shoorick wrote: is there any plan to process INCLUDE environment variable? |
|||
23 Aug 2015, 11:39 |
|
Goto page Previous 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.