flat assembler
Message board for the users of flat assembler.
flat assembler
> Programming Language Design > On my new assembler Goto page Previous 1, 2, 3, 4 ... 9, 10, 11 Next 
Author 

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
;LucasLehmer 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^31 is prime
M = 7
2^51 is prime
M = 31
2^71 is prime
M = 127
2^111 is not prime
2^131 is prime
M = 8191
2^171 is prime
M = 131071
2^191 is prime
M = 524287
2^231 is not prime
2^291 is not prime
2^311 is prime
M = 2147483647
2^371 is not prime
2^411 is not prime
2^431 is not prime
2^471 is not prime
2^531 is not prime
2^591 is not prime
2^611 is prime
M = 2305843009213693951
2^671 is not prime
2^711 is not prime
2^731 is not prime
2^791 is not prime
2^831 is not prime
2^891 is prime
M = 618970019642690137449562111
2^971 is not prime
2^1011 is not prime
2^1031 is not prime
2^1071 is prime
M = 162259276829213363391578010288127
2^1091 is not prime
2^1131 is not prime
2^1271 is prime
M = 170141183460469231731687303715884105727
2^1311 is not prime
2^1371 is not prime
2^1391 is not prime
2^1491 is not prime
2^1511 is not prime
2^1571 is not prime
2^1631 is not prime
2^1671 is not prime
2^1731 is not prime
2^1791 is not prime
2^1811 is not prime
2^1911 is not prime
2^1931 is not prime
2^1971 is not prime
2^1991 is not prime
2^2111 is not prime
2^2231 is not prime
2^2271 is not prime
2^2291 is not prime
2^2331 is not prime
2^2391 is not prime
2^2411 is not prime
2^2511 is not prime
2^2571 is not prime
2^2631 is not prime
2^2691 is not prime
2^2711 is not prime
2^2771 is not prime
2^2811 is not prime
2^2831 is not prime
2^2931 is not prime
2^3071 is not prime
2^3111 is not prime
2^3131 is not prime
2^3171 is not prime
2^3311 is not prime
2^3371 is not prime
2^3471 is not prime
2^3491 is not prime
2^3531 is not prime
2^3591 is not prime
2^3671 is not prime
2^3731 is not prime
2^3791 is not prime
2^3831 is not prime
2^3891 is not prime
2^3971 is not prime
2^4011 is not prime
2^4091 is not prime
2^4191 is not prime
2^4211 is not prime
2^4311 is not prime
2^4331 is not prime
2^4391 is not prime
2^4431 is not prime
2^4491 is not prime
2^4571 is not prime
2^4611 is not prime
2^4631 is not prime
2^4671 is not prime
2^4791 is not prime
2^4871 is not prime
2^4911 is not prime
2^4991 is not prime
2^5031 is not prime
2^5091 is not prime
2^5211 is prime
M = 686479766013060971498190079908139321726943530014330540939446345918554318339765605212255964066145
4554977296311391480858037121987999716643812574028291115057151
2^5231 is not prime
2^5411 is not prime
2^5471 is not prime
2^5571 is not prime
2^5631 is not prime
2^5691 is not prime
2^5711 is not prime
2^5771 is not prime
2^5871 is not prime
2^5931 is not prime
2^5991 is not prime
2^6011 is not prime
2^6071 is prime
M = 531137992816767098689588206552468627329593117727031923199444138200403559860852242739162502265229
285668889329486246501015346579337652707239409519978766587351943831270835393219031728127
2^6131 is not prime
2^6171 is not prime
2^6191 is not prime
2^6311 is not prime
2^6411 is not prime
2^6431 is not prime
2^6471 is not prime
2^6531 is not prime
2^6591 is not prime
2^6611 is not prime
2^6731 is not prime
2^6771 is not prime
2^6831 is not prime
2^6911 is not prime
2^7011 is not prime
2^7091 is not prime
2^7191 is not prime
2^7271 is not prime
2^7331 is not prime
2^7391 is not prime
2^7431 is not prime
2^7511 is not prime
2^7571 is not prime
2^7611 is not prime
2^7691 is not prime
2^7731 is not prime
2^7871 is not prime
2^7971 is not prime
2^8091 is not prime
2^8111 is not prime
2^8211 is not prime
2^8231 is not prime
2^8271 is not prime
2^8291 is not prime
2^8391 is not prime
2^8531 is not prime
2^8571 is not prime
2^8591 is not prime
2^8631 is not prime
2^8771 is not prime
2^8811 is not prime
2^8831 is not prime
2^8871 is not prime
2^9071 is not prime
2^9111 is not prime
2^9191 is not prime
2^9291 is not prime
2^9371 is not prime
2^9411 is not prime
2^9471 is not prime
2^9531 is not prime
2^9671 is not prime
2^9711 is not prime
2^9771 is not prime
2^9831 is not prime
2^9911 is not prime
2^9971 is not prime
2^10091 is not prime
2^10131 is not prime
2^10191 is not prime
2^10211 is not prime
2^10311 is not prime
2^10331 is not prime
2^10391 is not prime
2^10491 is not prime
2^10511 is not prime
2^10611 is not prime
2^10631 is not prime
2^10691 is not prime
2^10871 is not prime
2^10911 is not prime
2^10931 is not prime
2^10971 is not prime
2^11031 is not prime
2^11091 is not prime
2^11171 is not prime
2^11231 is not prime
2^11291 is not prime
2^11511 is not prime
2^11531 is not prime
2^11631 is not prime
2^11711 is not prime
2^11811 is not prime
2^11871 is not prime
2^11931 is not prime
2^12011 is not prime
2^12131 is not prime
2^12171 is not prime
2^12231 is not prime
2^12291 is not prime
2^12311 is not prime
2^12371 is not prime
2^12491 is not prime
2^12591 is not prime
2^12771 is not prime
2^12791 is prime
M = 104079321946643990819252403273640855386152622472667048053191123504036080596733602980122394417323
2418484242161395428100779138356624832346490813990660567732076292412950938922034577318334966158355047
2959420547689811211693677147548478866962501384438260291732348885311160828538416585028255604666224831
890918801847068222203140521026698435488732958028878050869736186900714720710555703168729087 

18 Jun 2015, 03:32 

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 

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 uptodate each time there is a new version? 

27 Jun 2015, 14:05 

revolution wrote: Tomasz: Do you intend to keep this uptodate 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 

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 

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 

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.endZXM_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 

thanks for the clue, i missed this nice statement!


15 Jul 2015, 16:53 

There is a bug in current fasmg (0.90.1436376581):
(not 0) results in 0. I use (x1) so far. 

31 Jul 2015, 20:34 

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 

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
sha3224: 20d0318c56fe180570fb3f712941a02d007bd4fef264fcf1bcee4900
sha3256: 847188b6f8015c04d351e9b9d9a0fab472113ca71e465754879bdbb6459ce55f
sha3384: 0556986e638a2fec5d40723469bb48b9259f84f0f6462249fdc74b733c296f1173a00e09eb8263ad728bbd37ec8a5755
sha3512: 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
sha3224: 20d0318c56fe180570fb3f712941a02d007bd4fef264fcf1bcee4900 (stdin)
sha3256: 847188b6f8015c04d351e9b9d9a0fab472113ca71e465754879bdbb6459ce55f (stdin)
sha3384: 0556986e638a2fec5d40723469bb48b9259f84f0f6462249fdc74b733c296f1173a00e09eb8263ad728bbd37ec8a5755 (stdin)
sha3512: 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 

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 

For an example of assemblytime arrays you can look at the assemblytime 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 

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: assemblytime LZW compression sample I made once for fasm 1 

01 Aug 2015, 19:40 

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 

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 

gens wrote: /dev/stdin is a character device 

01 Aug 2015, 21:28 

is there any plan to process INCLUDE environment variable?


19 Aug 2015, 08:22 

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

23 Aug 2015, 11:39 

Goto page Previous 1, 2, 3, 4 ... 9, 10, 11 Next < Last Thread  Next Thread > 
Forum Rules:

Copyright © 20042018, Tomasz Grysztar.
Powered by rwasa.