flat assembler
Message board for the users of flat assembler.

flat assembler > Macroinstructions > [fasmg] Lucas Prime Test

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 2792
Location: dank orb
Code:
; is F a factor of 2^N-1
macro MFactorQ N*,F*
        local B,T,D
        D = 1 + bsr F
        B = 1
        T = 1
        while B < N & T
                if B+D <= N
                        T = T+1 shl D-1
                        B = B + D
                        T = T mod F
                else
                        T = T + T + 1
                        B = B + 1
                        if T >= F
                                T = T mod F
                        end if
                end if
        end while
        repeat 1,tT,bB,fF
                if T = 0
                        display `f,' divides 2^',`b,'-1.',13,10
                else
                        display '2^',`b,'-1 mod ',`f,' = ',`t,13,10
                end if
        end repeat
end macro

MFactorQ 1001664179, 1878753956886303627167 ; 2 min
MFactorQ 3930621659, 6134708376727152865752497 ; 10 min    

_________________
¯\(°_o)/¯ unlicense.org
Post 17 Feb 2019, 17:57
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2792
Location: dank orb
Is there an a way to terminate the assembly process without producing an error? I don't want an output file, but presently am using "err 'No Output File'".
Code:
test-file.fasmg 66
        err 'No Output File'
Custom error No Output File.
The terminal process terminated with exit code 1    
I need to prune zero length files from the directory or parse around "no file errors" to find actual errors. Another solution would be to output to NUL, but this too splits the build process. It would be nice to have a solution within the source itself.

Maybe "format null" could not produce a file?

_________________
¯\(°_o)/¯ unlicense.org
Post 27 Feb 2019, 01:27
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2792
Location: dank orb
bitRAKE wrote:
Next I try to verify some data: There is list of cube sums at https://arxiv.org/abs/1604.07746v1
The answer is 42 !

https://www.youtube.com/watch?v=ASoz_NuIvP0

_________________
¯\(°_o)/¯ unlicense.org
Post 13 Mar 2019, 02:00
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2792
Location: dank orb
Tried to encapsulate commandline option testing to something like:
Code:
OPTION "s","silent"
        bts Options.FLAGS,FLAG_SILENT
END OPTION

OPTION "h","help"
        mov rax,.pArgv
        push qword rax
        lea rdx,HelpMessage
        call STD_OUTPUT_HANDLE__wsprintfA
        pop rax
END OPTION    
... which resulted in the following try ...
Code:
Options.count = 0

macro OPTION text&
        local skip
        macro END.OPTION!
                        label skip.0
                esc end macro
                end repeat
                purge END.OPTION
        end macro

        Options.count = Options.count + 1
        repeat 1,iOptions.count
        esc macro Options.i
                iterate txt,text
                        virtual at 1
                                ; rely on DU to convert UTF8 to widechar
                                du txt
                                load temp $-1 from $$
                        end virtual
                        if % = %%
                                skip.temp = 1
                        end if
                        repeat bsr temp shr 4 + 2
Display "0"+%% ; 1?
                                if % = %%
                                        if % and 1
                                                cmp word rsi+2*%+1,temp
                                        else
                                                cmp dword rsi+2*%+1,temp
                                        end if
                                        if skip.temp
                                                ; fall through to process, if txt is last alternative
                                                jnz skip.0
                                        else
                                                ; jump over alternatives to process
                                                jz skip.dont
                                        end if
                                else if ~ % and 1
                                        cmp dword rsi+2*%+2,temp and $FFFFFFFF
                                        temp = temp shr 32
                                        if skip.temp
                                                ; if txt is last alternative skip process
                                                jnz skip.0
                                        else
                                                ; try next alternative
                                                jnz skip.%
                                        end if
                                end if
                        end repeat
                        label skip.%
                end iterate
                label skip.dont
end macro

macro __OPTIONS
        postpone ?
        repeat Options.count
                Options.%
        end repeat
        end postpone
end macro    
Can't seem to get this to work as expected. Completely baffled how REPEAT ?+2 could result in %%=1.

_________________
¯\(°_o)/¯ unlicense.org
Post 14 Jul 2019, 11:45
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7310
Location: Kraków, Poland
bitRAKE wrote:
Can't seem to get this to work as expected. Completely baffled how REPEAT ?+2 could result in %%=1.
When you define a macro inside a REPEAT block, the "%%" in the text of the inner macro is replaced with a number. So the body of your macro contains a hard-coded number in place of every occurrence of "%%" (and the same goes for "%").

To make matters worse, "%" and "%%" are global parameters (not limited by a scope, as long as you are inside some repeated block, they have a value), so even encapsulating the macro definition would not save you here.
Post 14 Jul 2019, 11:52
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7310
Location: Kraków, Poland
A reduced sample that demonstrates the problem:
Code:
repeat 1,i1
        macro Options.i
                iterate txt, 'a','b','c'
                        display '0'+%%
                end iterate
        end macro
end repeat

Options.1    
And a kind of a messy solution:
Code:
macro preserve_counters? %%, %%%%
        macro end?.preserve_counters?
                end match
        end macro
        outscope match %%%, %%%
end macro


repeat 1,i1
        preserve_counters
                macro Options.i
                        iterate txt, 'a','b','c'
                                display '0'+%%
                        end iterate
                end macro
        end preserve_counters
end repeat

Options.1    
But in this case I think it would be better to just get rid of the outer REPEAT, for example by using MATCH to extract the name of macro to define from a symbolic variable (you could even maintain Options.count as a symbolic variable).
Post 14 Jul 2019, 12:14
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2792
Location: dank orb
Since I didn't need the count, I went with something similar to:
Code:
postpone ?
OPTIONS
end postpone

macro OPTIONS
end macro

macro OPTION text&
        macro END.OPTION!
                esc end macro
                purge END.OPTION
        end macro

        esc macro OPTIONS
                OPTIONS
                iterate txt, text
                        display "0"+%,txt
                end iterate
                display 13,10
end macro


OPTION 'a','b','c'

END OPTION

OPTION 'x','y','z'

END OPTION    
This is less efficient perhaps?

_________________
¯\(°_o)/¯ unlicense.org
Post 30 Jul 2019, 14:27
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

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